Common string, array, object encoding and getter helpers.
- SWR Audio Lab / Strings, Arrays, Objects
- Install
capitalize
- get capitalized stringgetObjectLength
- get the length of an objectisArray
- check if a value is a proper arrayisEmptyArray
- check if a value is an empty arrayisEmptyObject
- check if a value is an empty objectisEmptyString
- check if a value is an empty stringisIncluded
- check if a value (haystack) includes another value (needle)isNull
- check if a value is nullisObject
- check if a value is a proper objectisUndefined
- check if a value is undefinednotEmptyArray
- check if a value is not an empty arraynotEmptyObject
- check if a value is not an empty objectnotNullOrUndefined
- check if a value is neither null nor undefinedpluralize
- get pluralized stringremoveDoubleSpaces
- take a string and remove its duplicate spacestoHex
- take a string convert it to a hex string
Add the parent package to your dependencies:
yarn add @swrlab/utils
value
(required) - String to capitalize
Import the library:
const { capitalize } = require('@swrlab/utils/packages/strings')
Then use the toolkit:
capitalize('apple')
// Apple
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
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
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
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
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
haystack
(required) - Array or value to checkneedle
(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
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
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
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
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
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
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
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
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
value
(required) - String to convert
Import the library:
const { toHex } = require('@swrlab/utils/packages/strings')
Then use the toolkit:
toHex('hello world')
// 68656c6c6f20776f726c64