AND operator for functions.
Rest
...fns: ((...args) => boolean)[]functions to combine
a function that returns true if all of the input functions return true
Rest
...args: Argsconst isEven = (n: number) => n % 2 === 0
const isPositive = (n: number) => n > 0
const isPositiveEven = and(isEven, isPositive)
isPositiveEven(2) // returns true
Capitalizes the first letter of a string
string to capitalize
the string with the first letter capitalized
capitalize('foo') // returns 'Foo'
capitalize('FOO') // returns 'FOO'
capitalize('123') // returns '123'
capitalize('') // returns ''
Detects the case of a string
string to detect the case of
the detected case of the string
detectCase('fooBar') // returns 'camel'
detectCase('foo-bar') // returns 'kebab'
detectCase('FOO-BAR') // returns 'screaming-kebab'
detectCase('foo_bar') // returns 'snake'
detectCase('FOO_BAR') // returns 'screaming-snake'
detectCase('FooBar') // returns 'pascal'
detectCase('FOO BAR') // returns 'upper'
detectCase('foo bar') // returns 'lower'
detectCase('fooBar-baz') // returns 'mixed
detectCase('foo BAR') // returns 'mixed
detectCase('') // returns 'none'
Determines if a value is a number.
a function that checks if a value matches the expected type
const ensureArr = ensure(isArr, 'Value is not an array')
const arr = ensureArr(123) // throws an error
const arr2 = ensureArr([1, 2, 3]) // returns [1, 2, 3]
Optional
errorMsg: stringDetermines if an object has a key.
object to check
key to check
options to customize the check
Optional
ignoretrue if the object has the key, false otherwise
Converts a string to kebab-case
string to convert
options for the conversion
the string in kebab-case
kebabCase('fooBar') // returns 'foo-bar'
kebabCase('foo_bar') // returns 'foo-bar'
kebabCase('foo-bar') // returns 'foo-bar'
kebabCase('FOO_BAR') // returns 'foo-bar'
kebabCase('foo') // returns 'foo'
kebabCase('') // returns ''
kebabCase('fooBar', { screaming: true }) // returns 'FOO-BAR'
kebabCase('foo_bar', { screaming: true }) // returns 'FOO-BAR'
kebabCase('foo-bar', { screaming: true }) // returns 'FOO-BAR'
kebabCase('FOO_BAR', { screaming: true }) // returns 'FOO-BAR'
kebabCase('foo', { screaming: true }) // returns 'FOO'
NOT operator for functions.
function to negate
Rest
...args: Argsa function that negates the result of the input function
Rest
...args: Argsconst isEven = (n: number) => n % 2 === 0
const isOdd = not(isEven)
isOdd(2) // returns false
OR operator for functions.
Rest
...fns: ((...args) => boolean)[]functions to combine
a function that returns true if any of the input functions return true
Rest
...args: Argsconst isEven = (n: number) => n % 2 === 0
const isPositive = (n: number) => n > 0
const isPositiveOrEven = or(isEven, isPositive)
isPositiveOrEven(2) // returns true
isPositiveOrEven(3) // returns true
Converts a string to PascalCase
string to convert
the string in PascalCase
pascalCase('fooBar') // returns 'FooBar'
pascalCase('foo-bar') // returns 'FooBar'
pascalCase('foo_bar') // returns 'FooBar'
pascalCase('FOO_BAR') // returns 'FooBar'
pascalCase('foo') // returns 'Foo'
pascalCase('') // returns ''
Separates words in a string based on the detected case.
The string to separate.
An array of separated words.
separateWords('fooBar') // returns ['foo', 'Bar']
separateWords('foo-bar') // returns ['foo', 'bar']
separateWords('FOO_BAR') // returns ['FOO', 'BAR']
separateWords('foo bar') // returns ['foo', 'bar']
separateWords('') // returns []
separateWords('fooBar-baz') // returns ['foo', 'Bar', 'baz']
Converts a string to snake_case
string to convert
options for the conversion
the string in snake_case
snakeCase('fooBar') // returns 'foo_bar'
snakeCase('foo-bar') // returns 'foo_bar'
snakeCase('foo_bar') // returns 'foo_bar'
snakeCase('FOO_BAR') // returns 'foo_bar'
snakeCase('foo') // returns 'foo'
snakeCase('') // returns ''
snakeCase('fooBar', { screaming: true }) // returns 'FOO_BAR'
snakeCase('foo-bar', { screaming: true }) // returns 'FOO_BAR'
snakeCase('foo_bar', { screaming: true }) // returns 'FOO_BAR'
snakeCase('FOO_BAR', { screaming: true }) // returns 'FOO_BAR'
snakeCase('foo', { screaming: true }) // returns 'FOO'
snakeCase('fooBar', { screaming: true }) // returns 'FOO_BAR'
snakeCase('foo-bar', { screaming: true }) // returns 'FOO_BAR'
Converts a list of strings to an enum.
list of strings to convert to an enum
options to customize the enum
Optional
capitalizeOptional
capitalizean enum from the list
Converts a string to upper case
string to convert
the string in upper case
upperCase('foo') // returns 'FOO'
upperCase('FOO') // returns 'FOO'
upperCase('123') // returns '123'
upperCase('') // returns ''
upperCase('foo-bar') // returns 'FOO-BAR'
XOR operator for functions.
Rest
...fns: ((...args) => boolean)[]functions to combine
a function that returns true if exactly one of the input functions returns true
Rest
...args: Argsconst isEven = (n: number) => n % 2 === 0
const isPositive = (n: number) => n > 0
const isPositiveXorEven = xor(isEven, isPositive)
isPositiveXorEven(2) // returns false
isPositiveXorEven(3) // returns true
isPositiveXorEven(4) // returns false
Generated using TypeDoc
Empty function.