Reference Source Test Repository

Function

Static Public Summary
public

Clear all data stored in local storage

public

convertHexToRgb(color: string): string

Coverts any HEX color code to RGB

public

convertPixelRangeToArray(str: string): array

Convert pixel range to list of pixels

public

deduplicateArray(arr: array): array

Deduplicates any array

public

getKey(key: string): string

Get the data stored in specific key of local storage

public

isValidFontSize(str: string): boolean

Validate if user input is a valid font size

public

isValidPositiveInteger(str: string): boolean

Validate if user input is a positive integer

public

removeExtraSpacesAndCommas(str: string): string

Remove multiple consecutive spaces, trialing space and comma

public

removeKey(key: string)

Remove the data stored in specific key of local storage

public

roundToNearest(value: number, precision: number): number

Coverts any HEX color code to RGB

public

setKey(key: string, data: *)

Store data to local storage when key is provided

public

sortArrayAscending(arr: array): array

Sort array in ascending order

public

useDebounce(value: *, delay: number): *

A hook which used for debounce states for a certain amount of time(ms)

Static Public

public clearAll() source

Clear all data stored in local storage

public convertHexToRgb(color: string): string source

import convertHexToRgb from 'px2em-converter/src/utils/color.utils.js'

Coverts any HEX color code to RGB

Params:

NameTypeAttributeDescription
color string

HEX color

Return:

string

RGB value

public convertPixelRangeToArray(str: string): array source

import {convertPixelRangeToArray} from 'px2em-converter/src/utils/format.utils.js'

Convert pixel range to list of pixels

Params:

NameTypeAttributeDescription
str string

Pixel range, e.g. "12 - 20, 50, 100"

Return:

array

List of pixels, e.g. [12, 13, 14, 15, 16, 17, 18, 19, 20, 50, 100]`

public deduplicateArray(arr: array): array source

import {deduplicateArray} from 'px2em-converter/src/utils/format.utils.js'

Deduplicates any array

Params:

NameTypeAttributeDescription
arr array

Array to be deduplicated

Return:

array

Deduplicated array If arr provided is not an array, returns an empty array

public getKey(key: string): string source

Get the data stored in specific key of local storage

Params:

NameTypeAttributeDescription
key string

Local storage key which specifies where the data to be stored

Return:

string

Data stored in key of local storage

Return Properties:

NameTypeAttributeDescription
localStorageUtils function()

Helpers for interacting with local storage

public isValidFontSize(str: string): boolean source

import {isValidFontSize} from 'px2em-converter/src/utils/validate.utils.js'

Validate if user input is a valid font size

Params:

NameTypeAttributeDescription
str string

User input

Return:

boolean

true for decimal and integer values, false for other inputs

public isValidPositiveInteger(str: string): boolean source

import {isValidPositiveInteger} from 'px2em-converter/src/utils/validate.utils.js'

Validate if user input is a positive integer

Params:

NameTypeAttributeDescription
str string

User input

Return:

boolean

true for positive integers, false for negative integers and other inputs

public removeExtraSpacesAndCommas(str: string): string source

import {removeExtraSpacesAndCommas} from 'px2em-converter/src/utils/format.utils.js'

Remove multiple consecutive spaces, trialing space and comma

Params:

NameTypeAttributeDescription
str string

String to process

Return:

string

String which its multiple consecutive spaces, trialing space and comma are removed

public removeKey(key: string) source

Remove the data stored in specific key of local storage

Params:

NameTypeAttributeDescription
key string

Local storage key which specifies where the data to be stored

public roundToNearest(value: number, precision: number): number source

import {roundToNearest} from 'px2em-converter/src/utils/format.utils.js'

Coverts any HEX color code to RGB

Params:

NameTypeAttributeDescription
value number

Interger / floating point value that needs to be rounded

precision number

Number of decimal places

Return:

number

Rounded floating point value

public setKey(key: string, data: *) source

Store data to local storage when key is provided

Params:

NameTypeAttributeDescription
key string

Local storage key which specifies where the data to be stored

data *

Data to store to local storage

public sortArrayAscending(arr: array): array source

Sort array in ascending order

Params:

NameTypeAttributeDescription
arr array

Array to sort

Return:

array

Array sorted in ascending order

public useDebounce(value: *, delay: number): * source

A hook which used for debounce states for a certain amount of time(ms)

Params:

NameTypeAttributeDescription
value *

state value

delay number

debounce in milliseconds

Return:

*

latest value of state