Skip to content

Latest commit

 

History

History

strings

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

SWR Audio Lab / Strings, Arrays, Objects

Common string, array, object encoding and getter helpers.

Install

Add the parent package to your dependencies:

yarn add @swrlab/utils

capitalize - get capitalized string

  • value (required) - String to capitalize

Import the library:

const { capitalize } = require('@swrlab/utils/packages/strings')

Then use the toolkit:

capitalize('apple')
// Apple

getObjectLength - get the length of an object

  • value (required) - Value to check

Import the library:

const { getObjectLength } = require('@swrlab/utils/packages/strings')

Then use the toolkit:

getObjectLength({ hello: 'world' })
// 1

getObjectLength({ hello: 'world', foo: 'bar' })
// 2

isArray - check if a value is a proper array

  • value (required) - Value to check

Import the library:

const { isArray } = require('@swrlab/utils/packages/strings')

Then use the toolkit:

isArray(['hello world'])
// true

isArray('hello world')
// false

isEmptyArray - check if a value is an empty array

  • value (required) - Value to check

Import the library:

const { isEmptyArray } = require('@swrlab/utils/packages/strings')

Then use the toolkit:

isEmptyArray([])
// true

isEmptyArray(['hello world'])
// false

isEmptyObject - check if a value is an empty object

  • value (required) - Value to check

Import the library:

const { isEmptyObject } = require('@swrlab/utils/packages/strings')

Then use the toolkit:

isEmptyObject({})
// true

isEmptyObject({ hello: 'world' })
// false

isEmptyString - check if a value is an empty string

  • value (required) - Value to check

Import the library:

const { isEmptyString } = require('@swrlab/utils/packages/strings')

Then use the toolkit:

isEmptyString('')
// true

isEmptyString('hello world')
// false

isIncluded - check if a value (haystack) includes another value (needle)

  • haystack (required) - Array or value to check
  • needle (required) - Array or value to check

Import the library:

const { isIncluded } = require('@swrlab/utils/packages/strings')

Then use the toolkit:

isIncluded('hello world', 'hello')
// true

isIncluded('hello world', 'earth')
// false

isNull - check if a value is null

  • value (required) - Value to check

Import the library:

const { isNull } = require('@swrlab/utils/packages/strings')

Then use the toolkit:

isNull(null)
// true

isNull(undefined)
// false

isObject - check if a value is a proper object

  • value (required) - Value to check

Import the library:

const { isObject } = require('@swrlab/utils/packages/strings')

Then use the toolkit:

isObject({ hello: 'world' })
// true

isObject('hello world')
// false

isUndefined - check if a value is undefined

  • value (required) - Value to check

Import the library:

const { isUndefined } = require('@swrlab/utils/packages/strings')

Then use the toolkit:

isUndefined(undefined)
// true

isUndefined(null)
// false

notEmptyArray - check if a value is not an empty array

  • value (required) - Value to check

Import the library:

const { notEmptyArray } = require('@swrlab/utils/packages/strings')

Then use the toolkit:

notEmptyArray(['hello world'])
// true

notEmptyArray([])
// false

notEmptyObject - check if a value is not an empty object

  • value (required) - Value to check

Import the library:

const { notEmptyObject } = require('@swrlab/utils/packages/strings')

Then use the toolkit:

notEmptyObject({ hello: 'world' })
// true

notEmptyObject({})
// false

notNullOrUndefined - check if a value is neither null nor undefined

  • value (required) - Value to check

Import the library:

const { notNullOrUndefined } = require('@swrlab/utils/packages/strings')

Then use the toolkit:

notNullOrUndefined('hello world')
// true

notNullOrUndefined(null)
// false

notNullOrUndefined(undefined)
// false

pluralize - get pluralized string

  • value (required) - String to pluralize

Import the library:

const { pluralize } = require('@swrlab/utils/packages/strings')

Then use the toolkit:

pluralize(1, 'Apple')
// 1 Apple

pluralize(1000, 'Apple')
// 1.000 Apples

pluralize(1, 'Child', 'Children')
// 1 Child

pluralize(1000, 'Child', 'Children')
// 1.000 Children

removeDoubleSpaces - take a string and remove its duplicate spaces

  • value (required) - String to convert

Import the library:

const { removeDoubleSpaces } = require('@swrlab/utils/packages/strings')

Then use the toolkit:

removeDoubleSpaces('hello  world')
// hello world

removeDoubleSpaces('hello  world  once  again')
// hello world once again

toHex - take a string convert it to a hex string

  • value (required) - String to convert

Import the library:

const { toHex } = require('@swrlab/utils/packages/strings')

Then use the toolkit:

toHex('hello world')
// 68656c6c6f20776f726c64