Variable default

default: {
    noop: (() => void);
    and<Args>(...fns): ((...args) => boolean);
    asError(value): Error;
    camelCase(str): string;
    capitalize(str): string;
    chunk<T>(arr, size): T[][];
    compact<T>(arr): T[];
    concat<T>(...arrs): T[];
    detectCase(str): "camel" | "kebab" | "screaming-kebab" | "snake" | "screaming-snake" | "pascal" | "lower" | "upper" | "mixed" | "none";
    difference<T>(arr, values): T[];
    ensure<T, Args>(checkFn, errorMsg?): ((value, ...args) => T);
    ensure<T, Args>(checkFn, errorMsg?): ((value, ...args) => T);
    entries<T>(obj): [keyof T, T[keyof T]][];
    fillKeys<T, V>(keys, value): Record<T, V>;
    filter<T>(arr, fn): T[];
    first<T>(arr): T;
    hasOwn(obj, key, param2?): key is any;
    intersection<T>(...arrs): T[];
    isArr(value): value is any[];
    isEmpty(value): boolean;
    isFn(value): value is Function;
    isKeyOf<T>(value, obj): value is keyof T;
    isNullish(value): value is undefined | null;
    isNum(value): value is number;
    isObj(value): value is object;
    isPromise(value): value is Promise<unknown>;
    isStr(value): value is string;
    kebabCase(str, options?): string;
    keys<T>(obj): (keyof T)[];
    last<T>(arr): T;
    lowerCase(str): string;
    map<T, U>(arr, fn): U[];
    not<Args>(fn): ((...args) => boolean);
    or<Args>(...fns): ((...args) => boolean);
    pascalCase(str): string;
    reduce<T, U>(arr, fn, initial): U;
    separateWords(str): string[];
    snakeCase(str, options?): string;
    split(str, separator, limit?): string[];
    take<T>(arr, n): T[];
    takeRight<T>(arr, size): T[];
    throwError(message?): never;
    toEnum<T, CapitalizeKeys, CapitalizeValues>(list, options?): EnumFromList<T, CapitalizeKeys, CapitalizeValues>;
    toObj<T, R>(arr, keyFn, valueFn?): Record<PropertyKey, R>;
    union<T>(...arrs): T[];
    uniq<T>(arr): T[];
    uniqBy<T>(arr, fn): T[];
    upperCase(str): string;
    values<T>(obj): T[keyof T][];
    xor<Args>(...fns): ((...args) => boolean);
}

Type declaration

  • noop: (() => void)

    Empty function.

      • (): void
      • Returns void

  • and:function
    • AND operator for functions.

      Type Parameters

      • Args extends readonly unknown[]

      Parameters

      • Rest ...fns: ((...args) => boolean)[]

        functions to combine

      Returns ((...args) => boolean)

      a function that returns true if all of the input functions return true

        • (...args): boolean
        • Parameters

          Returns boolean

      Example

      const isEven = (n: number) => n % 2 === 0
      const isPositive = (n: number) => n > 0
      const isPositiveEven = and(isEven, isPositive)
      isPositiveEven(2) // returns true
  • asError:function
    • Converts a value to an error.

      Parameters

      • value: unknown

        value to convert

      Returns Error

      the value as an error

  • camelCase:function
    • Converts a string to camelCase

      Parameters

      • str: string

        string to convert

      Returns string

      the string in camelCase

      Example

      camelCase('foo-bar') // returns 'fooBar'
      camelCase('foo_bar') // returns 'fooBar'
      camelCase('FooBar') // returns 'fooBar'
      camelCase('FOO_BAR') // returns 'fooBar'
  • capitalize:function
    • Capitalizes the first letter of a string

      Parameters

      • str: string

        string to capitalize

      Returns string

      the string with the first letter capitalized

      Example

      capitalize('foo') // returns 'Foo'
      capitalize('FOO') // returns 'FOO'
      capitalize('123') // returns '123'
      capitalize('') // returns ''
  • chunk:function
    • Creates an array of elements split into groups the length of size. If array can't be split evenly, the final chunk will be the remaining elements.

      Type Parameters

      • T

      Parameters

      • arr: T[]
      • size: number

      Returns T[][]

  • compact:function
    • Compacts an array by removing null and undefined values.

      Type Parameters

      • T

      Parameters

      • arr: (undefined | null | false | 0 | T)[]

        array to compact

      Returns T[]

      the compacted array

  • concat:function
    • Concatenates arrays

      Type Parameters

      • T

      Parameters

      • Rest ...arrs: T[][]

        arrays to concatenate

      Returns T[]

      the concatenated array

  • detectCase:function
    • Detects the case of a string

      Parameters

      • str: string

        string to detect the case of

      Returns "camel" | "kebab" | "screaming-kebab" | "snake" | "screaming-snake" | "pascal" | "lower" | "upper" | "mixed" | "none"

      the detected case of the string

      Example

      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'
  • difference:function
    • Creates an array of unique values that are included in the first provided array, but not in the second.

      Type Parameters

      • T

      Parameters

      • arr: T[]

        array to difference from

      • values: T[]

        values to exclude

      Returns T[]

      the differenced array

  • ensure:function
    • Determines if a value is a number.

      Type Parameters

      • T
      • Args extends readonly unknown[] = []

      Parameters

      • checkFn: ((value, ...args) => value is T)

        function to check the value

          • (value, ...args): value is T
          • Parameters

            • value: any
            • Rest ...args: Args

            Returns value is T

      • Optional errorMsg: string

        error message to throw if the value does not match the expected type

      Returns ((value, ...args) => T)

      a function that checks if a value matches the expected type

        • (value, ...args): T
        • Parameters

          • value: unknown
          • Rest ...args: Args

          Returns T

      Example

      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]
    • Type Parameters

      • T
      • Args extends readonly unknown[] = []

      Parameters

      • checkFn: ((value, ...args) => boolean)
          • (value, ...args): boolean
          • Parameters

            • value: T
            • Rest ...args: Args

            Returns boolean

      • Optional errorMsg: string

      Returns ((value, ...args) => T)

        • (value, ...args): T
        • Parameters

          • value: T
          • Rest ...args: Args

          Returns T

  • entries:function
    • Gets the entries of an object.

      Type Parameters

      • T extends object

      Parameters

      • obj: T

        object to check

      Returns [keyof T, T[keyof T]][]

      true if the value is a number, false otherwise

  • fillKeys:function
    • Fills an array with a value.

      Type Parameters

      • T extends PropertyKey
      • V

      Parameters

      • keys: T[]

        keys to fill

      • value: V

        value to fill the keys with

      Returns Record<T, V>

      an object with the keys filled with the value

  • filter:function
    • Removes elements from an array for which the callback returns false.

      Type Parameters

      • T

      Parameters

      • arr: T[]

        array to filter

      • fn: ((value, index, array) => unknown)

        callback to filter the array

          • (value, index, array): unknown
          • Parameters

            • value: T
            • index: number
            • array: T[]

            Returns unknown

      Returns T[]

      the filtered array

  • first:function
    • Returns the first element of an array

      Type Parameters

      • T

      Parameters

      • arr: T[]

        array to get the first element from

      Returns T

      the first element of the array

  • hasOwn:function
    • Determines if an object has a key.

      Parameters

      • obj: Record<any, any>

        object to check

      • key: PropertyKey

        key to check

      • param2: {
            ignoreCase?: boolean;
        } = {}

        options to customize the check

        • Optional ignoreCase?: boolean

      Returns key is any

      true if the object has the key, false otherwise

  • intersection:function
    • Creates an array of unique values that are included in all given arrays using SameValueZero for equality comparisons.

      Type Parameters

      • T

      Parameters

      • Rest ...arrs: T[][]

        arrays to intersect

      Returns T[]

      the intersected array

  • isArr:function
    • Determines if a value is an array.

      Parameters

      • value: unknown

        value to check

      Returns value is any[]

      true if the value is an array, false otherwise

  • isEmpty:function
    • Determines if a value is empty.

      Parameters

      • value: any

      Returns boolean

  • isFn:function
    • Determines if a value is a function.

      Parameters

      • value: unknown

        value to check

      Returns value is Function

      true if the value is a function, false otherwise

  • isKeyOf:function
    • Determines if a value is a key of an object.

      Type Parameters

      • T extends object

      Parameters

      • value: unknown

        value to check

      • obj: T

        object to check if the value is a key of

      Returns value is keyof T

      true if the value is a key of the object, false otherwise

  • isNullish:function
    • Determines if a value is null or undefined.

      Parameters

      • value: unknown

        value to check

      Returns value is undefined | null

      true if the value is a number, false otherwise

  • isNum:function
    • Determines if a value is a number.

      Parameters

      • value: unknown

        value to check

      Returns value is number

      true if the value is a number, false otherwise

  • isObj:function
    • Determines if a value is an object.

      Parameters

      • value: unknown

        value to check

      Returns value is object

      true if the value is an object, false otherwise

  • isPromise:function
    • Determines if a value is a promise.

      Parameters

      • value: unknown

        value to check

      Returns value is Promise<unknown>

      true if the value is a promise, false otherwise

  • isStr:function
    • Determines if a value is a string.

      Parameters

      • value: unknown

        value to check

      Returns value is string

      true if the value is a string, false otherwise

  • kebabCase:function
    • Converts a string to kebab-case

      Parameters

      • str: string

        string to convert

      • options: {
            screaming: boolean;
        } = ...

        options for the conversion

        • screaming: boolean

      Returns string

      the string in kebab-case

      Example

      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'
  • keys:function
    • Gets the keys of an object.

      Type Parameters

      • T extends object

      Parameters

      • obj: T

        object to check

      Returns (keyof T)[]

      true if the value is a number, false otherwise

  • last:function
    • Returns the last element of an array

      Type Parameters

      • T

      Parameters

      • arr: T[]

        array to get the last element from

      Returns T

      the last element of the array

  • lowerCase:function
    • Converts a string to lower case

      Parameters

      • str: string

        string to convert

      Returns string

      the string in lower case

      Example

      lowerCase('FOO') // returns 'foo'
      lowerCase('foo') // returns 'foo'
      lowerCase('123') // returns '123'
      lowerCase('') // returns ''
  • map:function
    • Maps an array of values to an array of results of the callback.

      Type Parameters

      • T
      • U

      Parameters

      • arr: T[]

        array to map

      • fn: ((value, index, array) => U)

        callback to map the array

          • (value, index, array): U
          • Parameters

            • value: T
            • index: number
            • array: T[]

            Returns U

      Returns U[]

      the mapped array

  • not:function
    • NOT operator for functions.

      Type Parameters

      • Args extends readonly unknown[]

      Parameters

      • fn: ((...args) => boolean)

        function to negate

          • (...args): boolean
          • Parameters

            Returns boolean

      Returns ((...args) => boolean)

      a function that negates the result of the input function

        • (...args): boolean
        • Parameters

          Returns boolean

      Example

      const isEven = (n: number) => n % 2 === 0
      const isOdd = not(isEven)
      isOdd(2) // returns false
  • or:function
    • OR operator for functions.

      Type Parameters

      • Args extends readonly unknown[]

      Parameters

      • Rest ...fns: ((...args) => boolean)[]

        functions to combine

      Returns ((...args) => boolean)

      a function that returns true if any of the input functions return true

        • (...args): boolean
        • Parameters

          Returns boolean

      Example

      const 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
  • pascalCase:function
    • Converts a string to PascalCase

      Parameters

      • str: string

        string to convert

      Returns string

      the string in PascalCase

      Example

      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 ''
  • reduce:function
    • Reduces an array to a value which is the accumulated result of running each element in the array through the callback.

      Type Parameters

      • T
      • U

      Parameters

      • arr: T[]

        array to reduce

      • fn: ((acc, value, index, array) => U)

        callback to reduce the array

          • (acc, value, index, array): U
          • Parameters

            • acc: U
            • value: T
            • index: number
            • array: T[]

            Returns U

      • initial: U

        initial value

      Returns U

      the reduced value

  • separateWords:function
    • Separates words in a string based on the detected case.

      Parameters

      • str: string

        The string to separate.

      Returns string[]

      An array of separated words.

      Example

      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']
  • snakeCase:function
    • Converts a string to snake_case

      Parameters

      • str: string

        string to convert

      • options: {
            screaming: boolean;
        } = ...

        options for the conversion

        • screaming: boolean

      Returns string

      the string in snake_case

      Example

      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'
  • split:function
    • Splits a string into an array of substrings based on a separator

      Parameters

      • str: string

        string to split

      • separator: string | RegExp

        separator to split the string by

      • Optional limit: number

        maximum number of substrings to return

      Returns string[]

      an array of substrings

  • take:function
    • Returns the first n elements of an array

      Type Parameters

      • T

      Parameters

      • arr: T[]

        array to get the first n elements from

      • n: number

        number of elements to get

      Returns T[]

      the first n elements of the array

  • takeRight:function
    • Returns the last n elements of an array

      Type Parameters

      • T

      Parameters

      • arr: T[]
      • size: number

      Returns T[]

  • throwError:function
    • Throws an error with the given message.

      Parameters

      • message: string = ''

        error message

      Returns never

  • toEnum:function
  • toObj:function
    • Converts an array to an object.

      Type Parameters

      • T
      • R = T

      Parameters

      • arr: T[]

        array to fill

      • keyFn: ((item) => PropertyKey)

        function to get the key from the item

          • (item): PropertyKey
          • Parameters

            • item: T

            Returns PropertyKey

      • valueFn: ((item) => R) = ...

        function to get the value from the item

          • (item): R
          • Parameters

            • item: T

            Returns R

      Returns Record<PropertyKey, R>

      an object with the keys and values from the array

  • union:function
    • Creates an array of unique values, in order, from all given arrays using SameValueZero for equality comparisons.

      Type Parameters

      • T

      Parameters

      • Rest ...arrs: T[][]

        arrays to union

      Returns T[]

      the unioned array

  • uniq:function
    • Unique values from an array. Order is not guaranteed.

      Type Parameters

      • T

      Parameters

      • arr: T[]

        array to get unique values from

      Returns T[]

      the array with unique values

  • uniqBy:function
    • Unique values from an array, based on a comparator function.

      Type Parameters

      • T

      Parameters

      • arr: T[]

        array to get unique values from

      • fn: ((a) => unknown)

        comparator function

          • (a): unknown
          • Parameters

            Returns unknown

      Returns T[]

      the array with unique values

  • upperCase:function
    • Converts a string to upper case

      Parameters

      • str: string

        string to convert

      Returns string

      the string in upper case

      Example

      upperCase('foo') // returns 'FOO'
      upperCase('FOO') // returns 'FOO'
      upperCase('123') // returns '123'
      upperCase('') // returns ''
      upperCase('foo-bar') // returns 'FOO-BAR'
  • values:function
    • Gets the values of an object.

      Type Parameters

      • T extends object

      Parameters

      • obj: T

        object to check

      Returns T[keyof T][]

      true if the value is a number, false otherwise

  • xor:function
    • XOR operator for functions.

      Type Parameters

      • Args extends readonly unknown[]

      Parameters

      • Rest ...fns: ((...args) => boolean)[]

        functions to combine

      Returns ((...args) => boolean)

      a function that returns true if exactly one of the input functions returns true

        • (...args): boolean
        • Parameters

          Returns boolean

      Example

      const 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