@iol-inc/fe-utils
TypeScript icon, indicating that this package has built-in type declarations

1.4.0 • Public • Published

Constants

FILE_SIZE_100MB : number

Represents a file size of 100MB in bytes.

FILE_SIZE_5MB : number

Represents a file size of 5MB in bytes.

FILE_SIZE_3MB : number

Represents a file size of 3MB in bytes.

formatCurrencyPHP : Intl.NumberFormat

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

Functions

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

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

findIndexById(indexMap, id)number

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

IS_ARRAY_EQUAL(arr1, arr2)boolean

Checks if two arrays are equal by comparing their elements.

IS_VALID_ARRAY(array)boolean

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

IS_VALUE_ARRAY(array)boolean

Checks if a value is an array or not.

IS_FILE_LARGER_100MB(fileSize)boolean

Checks if file size is greater than 100MB

IS_FILE_LARGER_5MB(fileSize)boolean

Checks if file size is greater than 5MB

IS_FILE_LARGER_3MB(fileSize)boolean

Checks if file size is greater than 3MB

calcHeight1610(width)

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

roundUpTwoDecimals(value)number

Rounds up a number to two decimal places.

decode_id_token(params)Object

Decodes an ID token using the jwt-decode library and extracts detailed user information and roles.

hs_decodeIdToken(params)Object

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

convertToBase64(text)string

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

customCapitalize(params)string

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

limitWords(text, wordLimit)

Limits the given text to a specified number of words.

getWordLength([text])number

Calculates the number of words in a given text.

stringRemoveSpaceLowercase(string_param)string

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

FILE_SIZE_100MB : number

Represents a file size of 100MB in bytes.

Kind: global constant

FILE_SIZE_5MB : number

Represents a file size of 5MB in bytes.

Kind: global constant

FILE_SIZE_3MB : number

Represents a file size of 3MB in bytes.

Kind: global constant

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.

Param Type Description
array Array.<ArrayOfObjects> The array of objects to create the index map from.
idKey string The 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.

Param Type Description
indexMap Record.<any, any> The index map where the keys are object IDs and the values are their indices in the original array.
id string The 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.

Param Type Description
arr1 Array.<any> The first array to compare.
arr2 Array.<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

Param Type Description
array Array.<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

Param Type Description
array Array.<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.

Param Type Description
fileSize Array.<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.

Param Type Description
fileSize Array.<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.

Param Type Description
fileSize Array.<any> file size of the file for checking

calcHeight1610(width) ⇒

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

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

Param Description
width The width of the rectangle.

roundUpTwoDecimals(value) ⇒ number

Rounds up a number to two decimal places.

Kind: global function
Returns: number - The number rounded up to two decimal places.

Param Type Description
value number The number to be rounded up.

decode_id_token(params) ⇒ Object

Decodes an ID token using the jwt-decode library and extracts detailed user information and roles.

Kind: global function
Returns: Object - An object containing detailed user information including names, email, roles, and status flags indicating the user's specific roles.

Param Type Description
params Object The parameters for decoding.
params.IdToken string The JWT ID token to decode.
params.ROLE_ID Object An object containing role identifiers for comparison.

Properties

Name Type Description
tenantID string The tenant ID associated with the user.
branchID string The branch ID associated with the user.
suffix string A suffix associated with the user, if any.
name string The full name of the user.
fname string The user's first name.
lname string The user's last name.
email string The user's email address.
email_verified boolean Indicates whether the user's email address is verified.
phone_number string The user's phone number.
phone_number_verified boolean Indicates whether the user's phone number is verified.
username string The username associated with the user.
roles Array.<string> An array of roles assigned to the user.
isUserFreelancer boolean Indicates if the user is identified as a freelancer.
isUserHSAdmin boolean Indicates if the user is an HS (Health and Safety) admin.
isUserFacilitator boolean Indicates if the user is a facilitator.
isUserBusiness boolean Indicates if the user is a business admin.
isUserCashier boolean Indicates if the user is a cashier.
isUserOwner boolean Indicates if the user is an owner of the business.
isUserManager boolean Indicates if the user is a manager.

Example

const tokenDetails = decode_id_token({
  IdToken: 'yourTokenHere',
  ROLE_ID: {
    freelancer: 'freelancerRoleID',
    hs_admin: 'hsAdminRoleID',
    facilitator: 'facilitatorRoleID',
    business_admin: 'businessAdminRoleID',
    cashier: 'cashierRoleID',
    owner: 'ownerRoleID',
    manager: 'managerRoleID'
  }
});
console.log(tokenDetails);

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.

Param Type Description
params Object The parameters for decoding.
params.IdToken string The ID token to decode.
params.ROLE_ID Object An object containing role identifiers.

Properties

Name Type Description
name string The user's name.
fname string The user's first name.
lname string The user's last name.
email string The user's email address.
email_verified boolean Indicates whether the user's email is verified.
username string The user's username.
roles Array.<string> The roles assigned to the user.
isUserFreelancer boolean Indicates if the user is a freelancer.
isUserHSAdmin boolean Indicates if the user is an HS admin.
isUserFacilitator boolean Indicates if the user is a facilitator.
isUserBusiness boolean Indicates if the user is a business admin.
isUserCashier boolean Indicates if the user is a a cashier.
isUserOwner boolean Indicates if the user is a owner.
isUserManager boolean Indicates if the user is a manager.

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.

Param Type Description
text string The 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.

Param Type Description
params Object The parameters for capitalization.
params.string string The string to be capitalized.
params.character string The 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.

Param Description
text The original text.
wordLimit The 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.

Param Type Default Description
[text] string "&quot;&quot;" 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.

Param Type Description
string_param string The string from which spaces need to be removed and then converted to lowercase.

Example

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

Readme

Keywords

none

Package Sidebar

Install

npm i @iol-inc/fe-utils

Weekly Downloads

31

Version

1.4.0

License

MIT

Unpacked Size

63 kB

Total Files

5

Last publish

Collaborators

  • georg_ner
  • amiellion
  • iolinc