1.3.0-beta • Published 8 months ago

iol-front-end-utils v1.3.0-beta

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

Constants

Functions

calcHeight1610 ⇒

Calculates the height of a 16:10 rectangle from the width.

Kind: global constant
Returns: The height of the rectangle.

ParamDescription
widthThe width of the rectangle.

formatCurrencyPHP : Intl.NumberFormat

A utility for formatting numbers as currency in Philippine Peso (PHP) using the Filipino locale.

Kind: global constant
Note: This utility uses the "fil-PH" locale and is set to display numbers in decimal style with a minimum of 2 fraction digits.
Example

const amount = 1234.56;
console.log(formatCurrencyPHP.format(amount)); // "1,234.56"

createIndexMap(array, idKey) ⇒ Record.<any, any>

Creates an index map for an array of objects based on a specified key.

Kind: global function
Returns: Record.<any, any> - An index map where the keys are the values from the idKey of the objects and the values are their indices in the array.

ParamTypeDescription
arrayArray.<ArrayOfObjects>The array of objects to create the index map from.
idKeystringThe key in the objects to use for indexing.

Example

const arr = [{id: 1, name: 'Alice'}, {id: 2, name: 'Bob'}];
const indexMap = createIndexMap(arr, 'id');
console.log(indexMap); // {1: 0, 2: 1}

findIndexById(indexMap, id) ⇒ number

Retrieves the index of an object in an array using its ID from a pre-constructed index map.

Kind: global function
Returns: number - The index of the object in the original array. Returns undefined if the ID is not found in the index map.

ParamTypeDescription
indexMapRecord.<any, any>The index map where the keys are object IDs and the values are their indices in the original array.
idstringThe ID of the object whose index needs to be retrieved.

Example

const indexMap = {1: 0, 2: 1};
const index = findIndexById(indexMap, '1');
console.log(index); // 0

IS_ARRAY_EQUAL(arr1, arr2) ⇒ boolean

Checks if two arrays are equal by comparing their elements.

Kind: global function
Returns: boolean - Returns true if the arrays are equal, otherwise false.
Note: This function uses xorWith and isEqual for comparison and isEmpty to check the result. Ensure these utilities are imported and available in the scope.

ParamTypeDescription
arr1Array.<any>The first array to compare.
arr2Array.<any>The second array to compare.

Example

const array1 = [1, 2, 3];
const array2 = [1, 2, 3];
const areEqual = IS_ARRAY_EQUAL(array1, array2);
console.log(areEqual); // true

IS_VALID_ARRAY(array) ⇒ boolean

Checks if a value is a an array and if it contains an element.

Kind: global function
Returns: boolean - Returns true if the value provided is an array and if it contains an element

ParamTypeDescription
arrayArray.<any>value to check if array or not.

IS_VALUE_ARRAY(array) ⇒ boolean

Checks if a value is an array or not.

Kind: global function
Returns: boolean - Returns true if the value provided is an array

ParamTypeDescription
arrayArray.<any>value to check if array or not.

IS_FILE_LARGER_100MB(fileSize) ⇒ boolean

Checks if file size is greater than 100MB

Kind: global function
Returns: boolean - Returns true if the value is greater than 100MB.

ParamTypeDescription
fileSizeArray.<any>file size of the file for checking

IS_FILE_LARGER_5MB(fileSize) ⇒ boolean

Checks if file size is greater than 5MB

Kind: global function
Returns: boolean - Returns true if the value is greater than 5MB.

ParamTypeDescription
fileSizeArray.<any>file size of the file for checking

IS_FILE_LARGER_3MB(fileSize) ⇒ boolean

Checks if file size is greater than 3MB

Kind: global function
Returns: boolean - Returns true if the value is greater than 3MB.

ParamTypeDescription
fileSizeArray.<any>file size of the file for checking

hs_decodeIdToken(params) ⇒ Object

HEY SUCCESS Decodes an ID token and extracts user information and roles.

Kind: global function
Returns: Object - An object containing user details and roles.
Note: This function uses the jwt-decode library to decode the ID token.

ParamTypeDescription
paramsObjectThe parameters for decoding.
params.IdTokenstringThe ID token to decode.
params.ROLE_IDObjectAn object containing role identifiers.

Properties

NameTypeDescription
namestringThe user's name.
fnamestringThe user's first name.
lnamestringThe user's last name.
emailstringThe user's email address.
email_verifiedbooleanIndicates whether the user's email is verified.
usernamestringThe user's username.
rolesArray.<string>The roles assigned to the user.
isUserFreelancerbooleanIndicates if the user is a freelancer.
isUserHSAdminbooleanIndicates if the user is an HS admin.
isUserFacilitatorbooleanIndicates if the user is a facilitator.
isUserBusinessbooleanIndicates if the user is a business admin.

Example

const tokenDetails = hs_decodeIdToken({ IdToken: 'yourTokenHere', ROLE_ID: { freelancer: 'freelancerRoleID', hs_admin: 'hsAdminRoleID', facilitator: 'facilitatorRoleID', business_admin: 'businessAdminRoleID' } });
console.log(tokenDetails);

convertToBase64(text) ⇒ string

Converts a given text to a Base64 data URI for PNG/JPEG images.

Kind: global function
Returns: string - A Base64 data URI formatted for PNG/JPEG images.
Note: This function assumes the provided text is a valid Base64 encoded PNG or JPEG image.

ParamTypeDescription
textstringThe text to be converted to a Base64 data URI.

Example

const base64Data = convertToBase64('yourBase64EncodedImageHere');
console.log(base64Data); // "data:image/png/jpeg;base64, yourBase64EncodedImageHere"

customCapitalize(params) ⇒ string

Capitalizes the first letter of a string or each substring separated by a specified character.

Kind: global function
Returns: string - The capitalized string or capitalized substrings joined by the specified character.
Note: This function assumes the capitalize function is available in the scope to capitalize individual strings.

ParamTypeDescription
paramsObjectThe parameters for capitalization.
params.stringstringThe string to be capitalized.
params.characterstringThe character used to split the string.

Example

const capitalizedString = customCapitalize({ string: 'hello-world', character: '-' });
console.log(capitalizedString); // "Hello-World"

limitWords(text, wordLimit) ⇒

Limits the given text to a specified number of words.

Kind: global function
Returns: The limited text.

ParamDescription
textThe original text.
wordLimitThe maximum number of words.

getWordLength(text) ⇒ number

Calculates the number of words in a given text.

Kind: global function
Returns: number - The number of words in the text.
Note: This function splits the text based on whitespace to determine word count.

ParamTypeDefaultDescription
textstring"\"\""The text whose word count needs to be determined. Defaults to an empty string.

Example

const wordCount = getWordLength("Hello, how are you?");
console.log(wordCount); // 4

stringRemoveSpaceLowercase(string_param) ⇒ string

Removes all spaces from a string and converts it to lowercase.

Kind: global function
Returns: string - The modified string without spaces and in lowercase.
Note: This function uses regular expressions to remove spaces from the string.

ParamTypeDescription
string_paramstringThe string from which spaces need to be removed and then converted to lowercase.

Example

const modifiedString = stringRemoveSpaceLowercase("Hello World");
console.log(modifiedString); // "helloworld"
1.3.0-beta

8 months ago

1.2.5-beta

8 months ago

1.1.5-beta

8 months ago

1.1.4-beta

8 months ago

1.1.3-beta

8 months ago

1.1.2-beta

8 months ago

1.1.1-beta

8 months ago

1.1.0-beta

8 months ago

1.0.0-beta

8 months ago

1.1.0-alpha

8 months ago

1.0.0-alpha

8 months ago