npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@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