@pineapplelab/util
v1.9.0
Published
common functions
Downloads
693
Readme
isUndefined
(function)
Check if the values is undefined
code: value === undefined
Parameters:
- value (
any
)
returns: boolean
isNull
(function)
Check if the values is null
code: value === null
Parameters:
- value (
any
)
returns: boolean
isNullOrUndefined
(function)
Check if the values is null or undefined
code: value === undefined || value === null
Parameters:
- value (
any
)
returns: boolean
isValidString
(function)
This function return true
if the value is not null, not undefined and typeof is 'string', otherwise false
code: !isNullOrUndefined(value) && typeof value === 'string'
Parameters:
- value (
any
)
returns: boolean
isValidFunction
(function)
This function return true
if the value is not null, not undefined and typeof is 'function', otherwise false
code: !isNullOrUndefined(value) && typeof value === 'function'
Parameters:
- value (
any
)
returns: boolean
isNotEmptyString
(function)
This function return true
if the value is not null, not undefined, typeof is 'string' and different of '', otherwise false
code: isValidString(value) && value !== ''
Parameters:
- value (
string
)
returns: boolean
isDefinedString
(function)
This function return true
if the value is not null, not undefined, typeof is 'string' and different of '', otherwise false
code: isValidString(value) && value !== ''
Parameters:
- value (
string
)
returns: boolean
isProvidedString
(function)
This function return true
if the value is not null, not undefined, typeof is 'string' and different of '', otherwise false
code: isValidString(value) && value !== ''
Parameters:
- value (
string
)
returns: boolean
isFilledString
(function)
This function return true
if the value is not null, not undefined, typeof is 'string' and different of '', otherwise false
code: isValidString(value) && value !== ''
Parameters:
- value (
string
)
returns: boolean
isEmptyString
(function)
This function return true
if the value is not null, not undefined, and equal to '', otherwise false
code: isValidString(value) && value === ''
Parameters:
- value (
string
)
returns: boolean
isNumber
(function)
This function return true
if value's type is 'number', otherwise `false
code: typeof value === 'number'
Parameters:
- value (
any
)
returns: boolean
isNotNaNNumber
(function)
This function return true
if value is a number and is not a NaN
code: return isNumber(value) && !isNaN(value)
Parameters:
- value (
number
)
returns: boolean
isNaNNumber
(function)
Parameters:
- value (
number
)
returns: boolean
isValidNumber
(function)
Parameters:
- value (
any
)
returns: boolean
isFloat
(function)
!isNaN(parseFloat(value as string))
Parameters:
- value (
string | number
)
returns: boolean
isPositiveFloat
(function)
isFloat(value) && isFloatGreaterThan(value)
Parameters:
- value (
any
)
returns: boolean
isFloatGreaterThan
(function)
isFloat(value) && isFloat(valueToCompare) && parseFloat(value) > valueToCompare
Parameters:
- value (
string
) - valueToCompare (
number
)
returns: boolean
isFloatLessThan
(function)
isFloat(value) && isFloat(valueToCompare) && parseFloat(value) < valueToCompare
Parameters:
- value (
string
) - valueToCompare (
number
)
returns: boolean
isString
(function)
typeof value === 'string'
Parameters:
- value (
string
)
returns: boolean
isArray
(function)
!isNullOrUndefined(value) && Array.isArray(value)
Parameters:
- value (
any[]
)
returns: boolean
isNoEmptyArray
(function)
This function return true
if the value is not null, not undefined, is an array and length is greater than zero, otherwise false
code: isArray(value) && value.length > 0
Parameters:
- value (
any[]
)
returns: boolean
isFilledArray
(function)
This function return true
if the value is not null, not undefined, is an array and length is greater than zero, otherwise false
code: isArray(value) && value.length > 0
Parameters:
- value (
any[]
)
returns: boolean
isObject
(function)
!isNullOrUndefined(value) && typeof value === 'object'
Parameters:
- value (
any
)
returns: boolean
delay
(function)
Default: milliseconds = 1000
new Promise<void>((resolve) => setTimeout(() => resolve(), milliseconds))
Parameters:
- milliseconds (
number
)
returns: Promise
closetValue
(function)
!isNullOrUndefined(value) && typeof value === 'object'
Parameters:
- array (
number[]
) - goal (
number
)
returns: number
removeAllSubStr
(function)
(isString(value) && isString(toRemove)) ? value.split(toRemove).join('') : value
Parameters:
- value (
string
) - toRemove (
string
)
returns: string
isValidHttpUrl
(function)
!isNullOrUndefined(new URL(value))
Parameters:
- value (
string
)
returns: boolean
urlFromBlob
(function)
Parameters:
- blob (
Blob
)
returns: string
blobFromDataArray
(function)
Parameters:
- dataArray (
any[]
)
returns: Blob
blobFromBuffer
(function)
Parameters:
- buffer (
Buffer
)
returns: Blob
blobFromString
(function)
Parameters:
- stringBase64 (
string
)
returns: Promise
blobFromUrl
(function)
Parameters:
- url (
string
) - headers (
HeadersInit
)
returns: Promise
convertBlobToBase64
(function)
Parameters:
- blob (
Blob
)
returns: Promise
downloadBlobFile
(function)
Parameters:
- blob (
Blob
) - fileName (
string
)
returns: void
downloadByFileUrl
(function)
Parameters:
- url (
string
) - fileName (
string
)
returns: Promise
downloadByFileUrlAsHref
(function)
Parameters:
- url (
string
) - fileName (
string
)
returns: Promise
textToBlob
(function)
Parameters:
- text (
string
)
returns: Blob
camelToSnakeCase
(function)
str.replace(/[A-Z]/g, letter => `_${letter.toLowerCase()}`)
Parameters:
- str (
string
)
returns: string
snakeToCamelCase
(function)
str.replace(/(\_\w)/g, (m) => m[1].toUpperCase())
Parameters:
- str (
string
)
returns: string
sentenceToCamelCase
(function)
To camelCase
Parameters:
- str (
string
)
returns: string
replaceSpaces
(function)
Replace withe spaces with the second parameter, by default will just remove it.
Input: replaceSpaces('AAA ee BB H h j')
Output: 'AAAeeBBHhj'
Input: replaceSpaces('AAA ee BB H h j', '_')
Output: 'AAA_ee_BB_H_h_j'
Parameters:
- str (
string
) - newValue (
string
)
returns: string
replaceCharacters
(function)
Replace any character, by default will just find space characters and remove it.
Input: replaceSpaces('AAA ee BB H h j')
Output: 'AAAeeBBHhj'
Input: replaceSpaces('AAA ee BB H h j', ' ', '+')
Output: 'AAA+ee+BB+H+h+j'
Parameters:
- str (
string
) - character (
string
) - newValue (
string
)
returns: string
sentenceToConstName
(function)
Input: 'AAA ee BB H h j' Output: 'AAAEe_BB_HHJ'
Parameters:
- str (
string
)
returns: string
sentenceToSnakeCase
(function)
Input: 'AAA ee BB H h j' Output: 'AAAEe_BB_HHJ'
Parameters:
- str (
string
)
returns: string
getFileNameExtension
(function)
Parameters:
- str (
string
)
returns: string
toSentenceCase
(function)
Parameters:
- str (
string
)
returns: string
emailIsValid
(function)
Check if the string is a email
Parameters:
- email (
string
)
returns: boolean
isAlpha
(function)
Check if the string is alphabetic.
You can allow any other character as second parameter, by default blank space is allowed.
By default don't allow empty
Parameters:
- str (
string
) - allow (
string
) - allowEmpty (
boolean
)
returns: boolean
isAlphaWithoutSpaces
(function)
Check if the string is alphabetic without blank spaces.
By default don't allow empty
Parameters:
- str (
string
) - allowEmpty (
boolean
)
returns: boolean
isAlphanumeric
(function)
Check if the string is alphanumeric.
You can allow any other character as second parameter.
By default don't allow empty
Parameters:
- str (
string
) - allow (
string
) - allowEmpty (
boolean
)
returns: boolean
isNumeric
(function)
Check if the string is numeric.
You can allow any other character as second parameter.
By default don't allow empty
Parameters:
- str (
string
) - allow (
string
) - allowEmpty (
boolean
)
returns: boolean
isAlphanumericSpaceAndDash
(function)
Check if the string is alphanumeric and can have spaces and dash.
By default don't allow empty
Parameters:
- str (
string
) - allowEmpty (
boolean
)
returns: boolean
isAlphanumericDotSpaceAndDash
(function)
Check if the string is alphanumeric and can have dot, spaces and dash.
Parameters:
- str (
string
)
returns: boolean
IsEmptyOrAlphanumericDotSpaceAndDash
(function)
Check if the string is alphanumeric and can have dot, spaces and dash or can be a empty string.
Parameters:
- str (
string
)
returns: boolean
hasANumber
(function)
Check if the string has a number.
Parameters:
- str (
string
)
returns: boolean
hasALowercaseLetter
(function)
Check if the string has a lowercase letter.
Parameters:
- str (
string
)
returns: boolean
hasAUppercaseLetter
(function)
Check if the string has a uppercase letter.
Parameters:
- str (
string
)
returns: boolean
hasASpecialCharacter
(function)
Check if the string has a special character like: -+_!@#$%^&*., ?
Parameters:
- str (
string
)
returns: boolean
isEven
(function)
isValidNumber( value ) && value % 2 === 0
Parameters:
- value (
any
)
returns: boolean
isOdd
(function)
isValidNumber(value) && !isEven(value)
Parameters:
- value (
any
)
returns: boolean