npm.io
1.0.0-Beta • Published 3 years ago

ts-copilot

Licence
MIT
Version
1.0.0-Beta
Deps
0
Size
255 kB
Vulns
0
Weekly
0

ts-copilot

A toolkit for ts

Usage

npm i ts-copilot

ts-copilot - v1.0.0-Beta

ts-copilot - v1.0.0-Beta

Table of contents

References

Functions

References

includes

Renames and re-exports contains

Functions

add

add(a, b): number

Adds two numbers with fixed precision.

Since

1.0.0

Example

add(0.1, 0.2) // returns 0.3
Parameters
Name Type Description
a number The first number to add.
b number The second number to add.
Returns

number

The result of adding the two numbers.

Defined in

packages/eskit/src/add.ts:14


clamp

clamp(num, min, max): number

Limits a number to be within a certain range.

Since

1.0.0

Example

// returns -5
clamp(-10, -5, 5);

Example

// returns 5
clamp(10, -5, 5);
Parameters
Name Type Description
num number The number to clamp.
min number The lower boundary of the range.
max number The upper boundary of the range.
Returns

number

The clamped number.

Defined in

packages/eskit/src/clamp.ts:22


clone

clone<T>(obj): T

Create a clone of the given object.

Example

const obj = { a: 1, b: { c: 2 } };
const cloneObj = clone(obj);
console.log(cloneObj); // { a: 1, b: { c: 2 } }

Since

1.0.0

Type parameters
Name
T
Parameters
Name Type Description
obj T The object to clone.
Returns

T

The cloned object.

Defined in

packages/eskit/src/clone.ts:14


compose

compose<T>(...funcs): (arg: T) => T

Composes an array of functions into a single function from right to left.

Since

1.0.0

Example

const add = (a: number) => (b: number) => a + b;
const multiplyByTwo = (a: number) => a * 2;
const addAndMultiply = compose(multiplyByTwo, add(1), add(2));
const result = addAndMultiply(3); // (3 + 2 + 1) * 2 = 12
Type parameters
Name Description
T The type of the input and output value.
Parameters
Name Type Description
...funcs (arg: T) => T[] An array of functions to compose.
Returns

fn

A new function that will execute the input functions in reverse order.

▸ (arg): T

Parameters
Name Type
arg T
Returns

T

Defined in

packages/eskit/src/compose.ts:17


constantize

constantize<T>(obj): void

Freezes an object and recursively freezes its enumerable properties (but not their children).

Since

1.0.0

Type parameters
Name Type
T extends Record<string, any>
Parameters
Name Type Description
obj T The object to be frozen.
Returns

void

Defined in

packages/eskit/src/constantize.ts:7


contains

contains(arr, value, position?): boolean

Determines whether an array or string contains a specified value.

Example

const arr = [1, 2, 3, 4];
contains(arr, 3); // Returns true
contains('hello', 'w', 3); // Returns false
Parameters
Name Type Default value Description
arr string | any[] undefined The array or string to search through.
value any undefined The value to search for.
position number -1 Optional. The index to start searching from. Default is -1.
Returns

boolean

A boolean indicating whether the value was found.

Defined in

packages/eskit/src/contains.ts:19


copyProperties

copyProperties<T, U>(target, source): void

Copies all properties of source to target, including non-enumerable ones.

Since

1.0.0

Example

const source = { a: 1, b: 2 };
const target = { c: 3 };

copyProperties(target, source);

console.log(target); // {a: 1, b: 2, c: 3}
Type parameters
Name Type
T T
U extends Record<string, unknown>
Parameters
Name Type Description
target T The target object.
source U The source object to copy from.
Returns

void

Defined in

packages/eskit/src/copy-properties.ts:17


curry

curry(fn): (...args: any[]) => (...args: any[]) => any

Curry a function with given arguments.

Example

const add = (a: number, b: number) => a + b;
const curriedAdd = curry(add);

const add5 = curriedAdd(5);
console.log(add5(3)); // Output: 8

const add2 = curriedAdd(2);
console.log(add2(4)); // Output: 6
Parameters
Name Type Description
fn (...args: any[]) => any The function to be curried.
Returns

fn

A curried function.

▸ (...args): (...args: any[]) => any

Parameters
Name Type
...args any[]
Returns

fn

▸ (...args): any

Parameters
Name Type
...args any[]
Returns

any

Defined in

packages/eskit/src/curry.ts:17


debounced

debounced<Args>(fn, delay, immediate?): DebouncedFn

Creates a debounced function that waits for the specified delay after the last call before executing.

Type parameters
Name Type
Args extends any[]
Parameters
Name Type Description
fn (...args: Args) => void The function to wrap.
delay number The delay time (in milliseconds) before the function is executed.
immediate? boolean Whether to execute the function immediately on the first call.
Returns

DebouncedFn

The wrapped debounced function.

Defined in

packages/eskit/src/debounced.ts:14


deepClone

deepClone<T>(obj): T

Type parameters
Name
T
Parameters
Name Type
obj T
Returns

T

Defined in

packages/eskit/src/deep-clone.ts:7


difference

difference<T>(arr, values?): T[]

Returns an array of values in arr that are not in the values array.

Typeparam

T The type of the array elements.

Example

const arr = [1, 2, 3, 4, 5]
const values = [3, 4, 5, 6, 7]

difference(arr, values) // Returns: [1, 2]
Type parameters
Name
T
Parameters
Name Type Default value Description
arr T[] undefined The array to inspect.
values T[] [] The values to exclude from the result.
Returns

T[]

An array of values in arr that are not in the values array.

Defined in

packages/eskit/src/difference.ts:20


divide

divide(a, b): number

Divides two numbers and returns the quotient.

Example

// Returns 2
divide(4, 2);

Example

// Returns 2.5
divide(5, 2);
Parameters
Name Type Description
a number The dividend.
b number The divisor.
Returns

number

The quotient.

Defined in

packages/eskit/src/divide.ts:16


each

each<T>(collection, func): void

Iterates over elements of collection and invokes func for each element.

Example

each([1, 2, 3], (value, index, collection) => console.log(value, index));
each({ a: 1, b: 2, c: 3 }, (value, key, collection) => console.log(value, key));
Type parameters
Name
T
Parameters
Name Type Description
collection Record<string, T> | T[] The collection to iterate over.
func (value: T, key?: string | number, collection?: Record<string, T> | T[]) => any The function invoked per iteration.
Returns

void

Defined in

packages/eskit/src/each.ts:13


extendDeep

extendDeep(parent, child?): ObjectType<any>

Recursively extends an object or array.

Typeparam

T The type of the parent object.

Example

const parent = { a: { b: 1 } };
const child = { a: { c: 2 } };

extendDeep(parent, child); // { a: { b: 1, c: 2 } }
Parameters
Name Type Description
parent ObjectType<any> The parent object to extend.
child ObjectType<any> The child object to merge into the parent object.
Returns

ObjectType<any>

The extended object.

Defined in

packages/eskit/src/extend-deep.ts:19


filter

filter<T>(collection, callback): T

Filters the elements of an array or object based on a callback function.

Example

// Define an array of numbers
const numbers = [1, 2, 3, 4, 5];

// Define a callback function to filter even numbers
const isEven = (num: number) => num % 2 === 0;

// Filter the array using the callback function
const evenNumbers = filter(numbers, isEven);

// The new array contains only even numbers
console.log(evenNumbers); // [2, 4]

// Define an object of key-value pairs
const obj = { a: 1, b: 2, c: 3, d: 4, e: 5 };

// Define a callback function to filter even values
const isEvenValue = (val: number) => val % 2 === 0;

// Filter the object using the callback function
const evenValuesObj = filter(obj, (_, value) => isEvenValue(value));

// The new object contains only key-value pairs where the value is even
console.log(evenValuesObj); // { b: 2, d: 4 }
Type parameters
Name Type
T extends Record<string, unknown> | unknown[]
Parameters
Name Type Description
collection T The array or object to filter.
callback (value: T extends U[] ? U : T[keyof T], indexOrKey: T extends unknown[] ? number : keyof T, collection: T) => boolean The function to call for each element. Should return true to keep the element, false to remove it.
Returns

T

A new array or object containing only the elements for which the callback function returned true.

Defined in

packages/eskit/src/filter.ts:31


flatten

flatten<T>(array): T[]

Flattens an array.

Typeparam

T The type of the array elements.

Example

const arr = [1, [2, [3, 4]], 5];

flatten(arr); // [1, 2, 3, 4, 5]
Type parameters
Name
T
Parameters
Name Type Description
array (T | T[])[] The array to flatten.
Returns

T[]

The flattened array.

Defined in

packages/eskit/src/flatten.ts:13


formatMoney

formatMoney(money, currencySymbol?): string

Formats a given number as a string with a currency symbol.

Example

formatMoney(10) // "$10.00"
formatMoney(1000000, "£") // "£1,000,000.00"

Since

1.0.0

Parameters
Name Type Default value Description
money number undefined The number to be formatted.
currencySymbol string ' The currency symbol to use. Defaults to '$'.
Returns

string

A string with the formatted currency symbol and number.

Defined in

packages/eskit/src/format-money.ts:16


formatNumber

formatNumber(val, separator, digitNum?): string

Formats a number with the specified decimal separator and digit number.

This function formats a number with the specified decimal separator and digit number. If the input value is not a valid number, this function returns the input value as a string without formatting.

Example

const formattedNumber = formatNumber(123456.789, ',', 2)
console.log(formattedNumber)
// Output: "123,456.79"
Parameters
Name Type Default value Description
val number undefined The input number to be formatted.
separator string undefined The decimal separator to use for formatting the number.
digitNum number 0 The number of digits to appear after the decimal point (defaults to 0).
Returns

string

The formatted number as a string.

Defined in

packages/eskit/src/format-number.ts:18


getGlobal

getGlobal(): unknown

Returns the global object for the current runtime environment.

This function returns the global object for the current runtime environment. It works in both browser and Node.js environments.

Throws

An error if the global object cannot be located.

Example

const globalObj = getGlobal()

if (typeof globalObj.process === 'object') {
  console.log('Running in Node.js')
} else {
  console.log('Running in browser')
}
Returns

unknown

The global object for the current runtime environment.

Defined in

packages/eskit/src/get-global.ts:21


getRandomInt

getRandomInt(min, max): number

Returns a random integer between the specified minimum and maximum values (inclusive).

This function returns a random integer between the specified minimum and maximum values (inclusive). The minimum and maximum values must be integers, and the minimum value must be less than or equal to the maximum value.

Example

const randomInt = getRandomInt(1, 10)
console.log(randomInt)
Parameters
Name Type Description
min number The minimum value (inclusive).
max number The maximum value (inclusive).
Returns

number

A random integer between the specified minimum and maximum values (inclusive).

Defined in

packages/eskit/src/get-random-int.ts:16


getType

getType(value): string

Get the type of a value

Example

getType(42) // "Number"
getType("hello") // "String"
getType([]) // "Array"
getType(null) // "Null"
getType(undefined) // "Undefined"
getType({}) // "Object"
Parameters
Name Type Description
value any The value to get the type of
Returns

string

The type of the value

Defined in

packages/eskit/src/get-type.ts:19


hasOwnProperty

hasOwnProperty(obj, key): boolean

A reference to the Object.prototype.hasOwnProperty() method.

This function allows you to check if an object has a property defined on itself (i.e., not inherited from its prototype chain).

Example

const obj = { foo: 42 }

hasOwnProperty(obj, 'foo') // true
hasOwnProperty(obj, 'toString') // false
Parameters
Name Type
obj unknown
key PropertyKey
Returns

boolean

true if the object has the property defined on itself, false otherwise.

Defined in

packages/eskit/src/hasOwnProperty.ts:18


isArguments

isArguments(value): boolean

Tests whether a value is an arguments object.

Example

// Returns true
function sampleFunc() {
  return isArguments(arguments)
}
sampleFunc();

Example

// Returns false
isArguments([1,2,3]);
Parameters
Name Type Description
value unknown The value to test.
Returns

boolean

true if the value is an arguments object, false otherwise.

Defined in

packages/eskit/src/is-arguments.ts:23


isArray

isArray(value): value is any[]

Checks if a value is an array.

Example

isArray('abc') // => false
isArray([]) // => true
isArray({ 0: 'a', 1: 'b', 2: 'c', length: 3 }) // => false
Parameters
Name Type Description
value any The value to check.
Returns

value is any[]

true if the value is an array, else false.

Defined in

packages/eskit/src/is-array.ts:15


isArrayBuffer

isArrayBuffer(value): value is unknown[]

Tests whether a value is an ArrayBuffer object.

Example

// Returns false
isArrayBuffer([1,2,3]);

Example

// Returns true
const buffer = new ArrayBuffer(16);
isArrayBuffer(buffer);
Parameters
Name Type Description
value unknown The value to test.
Returns

value is unknown[]

true if the value is an ArrayBuffer object, false otherwise.

Defined in

packages/eskit/src/is-array-buffer.ts:21


isArrayLike

isArrayLike(value): boolean

Checks if a value is array-like.

Example

isArrayLike('abc') // => true
isArrayLike([]) // => true
isArrayLike({ 0: 'a', 1: 'b', 2: 'c', length: 3 }) // => true
isArrayLike(Function) // => false
Parameters
Name Type Description
value any The value to check.
Returns

boolean

true if the value is array-like, else false.

Defined in

packages/eskit/src/is-array-like.ts:15


isArrayLikeObject

isArrayLikeObject(value): boolean

Checks if a value is array-like.

Example

isArrayLikeObject('abc') // => true
isArrayLikeObject([]) // => true
isArrayLikeObject(document.querySelectorAll('div')) // => true
isArrayLikeObject(Function) // => false
Parameters
Name Type Description
value unknown The value to check.
Returns

boolean

true if the value is array-like, else false.

Defined in

packages/eskit/src/is-array-like-object.ts:19


isBoolean

isBoolean(value): value is boolean

Checks if a value is a boolean.

Example

isBoolean(true) // => true
isBoolean(false) // => true
isBoolean(0) // => false
isBoolean('true') // => false
Parameters
Name Type Description
value unknown The value to check.
Returns

value is boolean

true if the value is a boolean, else false.

Defined in

packages/eskit/src/is-boolean.ts:16


isDate

isDate(value): value is Date

Checks if a value is a Date object.

Example

isDate(new Date()) // => true
isDate(Date.now()) // => false
isDate('2022-03-30') // => false
Parameters
Name Type Description
value unknown The value to check.
Returns

value is Date

true if the value is a Date object, else false.

Defined in

packages/eskit/src/is-date.ts:15


isDecimal

isDecimal(num): boolean

Checks if a number is a decimal.

Example

isDecimal(1.5) // => true
isDecimal(3) // => false
isDecimal('1.23') // => false
Parameters
Name Type Description
num unknown The number to check.
Returns

boolean

true if the number is a decimal, else false.

Defined in

packages/eskit/src/is-decimal.ts:15


isDefined

isDefined<T>(val): val is T

Checks if a value is defined (not undefined or null).

Example

isDefined(1) // => true
isDefined('hello') // => true
isDefined(null) // => false
isDefined(undefined) // => false
Type parameters
Name Description
T The type of the value to check.
Parameters
Name Type Description
val undefined | null | T The value to check.
Returns

val is T

true if the value is defined, else false.

Defined in

packages/eskit/src/is-defined.ts:16


isElement

isElement(o): boolean

Checks if a value is an Element or HTMLDocument object.

Example

isElement(document.body) // => true
isElement(document.querySelector('.my-class')) // => true
isElement(window) // => false
isElement('not an element') // => false
Parameters
Name Type Description
o unknown The value to check.
Returns

boolean

true if the value is an Element or HTMLDocument object, else false.

Defined in

packages/eskit/src/is-element.ts:15


isEmpty

isEmpty(value): boolean

Checks if a value is empty.

A value is considered empty if it is undefined, null, an empty array or string, an empty Map or Set object, or an object with no own properties.

Example

isEmpty(undefined) // => true
isEmpty(null) // => true
isEmpty('') // => true
isEmpty([]) // => true
isEmpty(new Map()) // => true
isEmpty(new Set()) // => true
isEmpty({}) // => true
isEmpty({ prop: 'value' }) // => false
isEmpty([1, 2, 3]) // => false
isEmpty('hello') // => false
isEmpty(new Map([['key', 'value']])) // => false
isEmpty(new Set([1, 2, 3])) // => false
Parameters
Name Type Description
value any The value to check.
Returns

boolean

true if the value is empty, else false.

Defined in

packages/eskit/src/is-empty.ts:32


isEqual

isEqual(value, other): boolean

Determines if two values are equal. Supports objects, arrays, and primitives.

Example

isEqual([1, 2, 3], [1, 2, 3]) // => true
isEqual({a: 1, b: {c: 2}}, {a: 1, b: {c: 2}}) // => true
isEqual('abc', 'abc') // => true
isEqual(1, 2) // => false
isEqual(null, undefined) // => false
Parameters
Name Type Description
value any The value to compare.
other any The other value to compare.
Returns

boolean

True if the values are equal, false otherwise.

Defined in

packages/eskit/src/is-equal.ts:19


isEqualWith

isEqualWith<T>(value, other, fn): boolean

Performs a deep comparison between two values to determine if they are equivalent.

Example

isEqualWith([1, 2, 3], [1, 2, 3], (v1, v2) => {
  if (Array.isArray(v1) && Array.isArray(v2)) {
    return v1.length === v2.length;
  }
  return undefined;
}); // => true
Type parameters
Name
T
Parameters
Name Type Description
value T The value to compare.
other T The other value to compare.
fn (v1: T, v2: T) => boolean The customizer function to use to compare values.
Returns

boolean

Returns true if the values are equivalent, else false.

Defined in

packages/eskit/src/is-equal-with.ts:19


isError

isError(value): value is Error

Determines whether the given value is an instance of Error.

Example

const err = new Error('Example error');
isError(err); // true

const obj = { error: new Error('Example error') };
isError(obj.error); // true

isError('Error'); // false
Parameters
Name Type Description
value unknown The value to check.
Returns

value is Error

Whether the given value is an instance of Error.

Defined in

packages/eskit/src/is-error.ts:17


isEven

isEven(num): boolean

Checks if a number is even.

Example

isEven(2); // true
isEven(3); // false
Parameters
Name Type Description
num number The number to check.
Returns

boolean

Whether the number is even or not.

Defined in

packages/eskit/src/is-even.ts:12


isFunction

isFunction(value): value is Function

Checks if a given value is a function

Example

isFunction(() => {}) // true
isFunction(function() {}) // true
isFunction(42) // false
Parameters
Name Type Description
value unknown The value to check
Returns

value is Function

True if the value is a function, false otherwise

Defined in

packages/eskit/src/is-function.ts:11


isInteger

isInteger(number): boolean

Checks if a value is an integer.

Example

isInteger(0); // true
isInteger(5); // true
isInteger(-10); // true
isInteger(2.5); // false
Parameters
Name Type
number unknown
Returns

boolean

Returns true if value is an integer, else false.

Defined in

node_modules/typescript/lib/lib.es2015.core.d.ts:233


isNil

isNil(value): value is undefined | null

Type guard to determine if a value is null or undefined.

Example

isNil(null); // true
isNil(undefined); // true
isNil(''); // false
isNil(0); // false
Parameters
Name Type Description
value unknown The value to test.
Returns

value is undefined | null

Whether or not the value is null or undefined.

Defined in

packages/eskit/src/is-nil.ts:17


isNumber

isNumber(value): value is number

Checks if a value is a number.

Example

isNumber(42); // true
isNumber('42'); // false
Parameters
Name Type Description
value unknown The value to check.
Returns

value is number

Returns true if the value is a number, else false.

Defined in

packages/eskit/src/is-number.ts:12


isObject

isObject(value): value is Record<string, unknown>

Check if a value is an object.

Example

isObject({}) // true
isObject([]) // true
isObject(null) // false
Parameters
Name Type Description
value unknown The value to check.
Returns

value is Record<string, unknown>

true if the value is an object, else false.

Defined in

packages/eskit/src/is-object.ts:13


isObjectLike

isObjectLike(value): boolean

Checks if a value is object-like, which means it's not null and its type is 'object'.

Example

isObjectLike({}); // true
isObjectLike([]); // true
isObjectLike(null); // false
isObjectLike(42); // false
Parameters
Name Type Description
value unknown The value to check.
Returns

boolean

True if the value is object-like, false otherwise.

Defined in

packages/eskit/src/is-object-like.ts:13


isPromiseLike

isPromiseLike(obj): boolean

Checks if a given object is promise-like (thenable).

Example

const myPromise = new Promise(resolve => setTimeout(() => resolve('done'), 100));
console.log(isPromiseLike(myPromise)); // true
console.log(isPromiseLike({ then: () => {} })); // true
console.log(isPromiseLike({})); // false
Parameters
Name Type Description
obj any The object to check.
Returns

boolean

Whether the object is promise-like.

Defined in

packages/eskit/src/is-promise-like.ts:11


isPrototype

isPrototype(value): boolean

Checks if value is likely a prototype object.

Example

function Foo() {}
isPrototype(Foo.prototype)
// => true

isPrototype({})
// => false
Parameters
Name Type Description
value unknown The value to check.
Returns

boolean

Whether value is a prototype object.

Defined in

packages/eskit/src/is-prototype.ts:16


isRegExp

isRegExp(value): value is RegExp

Determines whether the given value is a regular expression.

Example

isRegExp(/ab+c/i) // => true
isRegExp('hello') // => false
Parameters
Name Type Description
value unknown The value to check.
Returns

value is RegExp

true if the value is a regular expression, else false.

Defined in

packages/eskit/src/is-reg-exp.ts:12


isString

isString(value): value is string

Checks if a given value is a string.

Example

isString('hello') // => true
isString(123) // => false
Parameters
Name Type Description
value unknown The value to check.
Returns

value is string

Returns true if the given value is a string, else false.

Defined in

packages/eskit/src/is-string.ts:12


isType

isType(type, value): boolean

Checks if a value's type matches the specified type string.

Example

isType('String', 'hello'); // true
isType('Array', {}); // false
Parameters
Name Type Description
type string The type string to check against.
value unknown The value to check the type of.
Returns

boolean

True if the value's type matches the specified type string, false otherwise.

Defined in

packages/eskit/src/is-type.ts:10


listToTree

listToTree<T>(list, pid?): T[]

Converts a flat list of items to a tree structure.

Type parameters
Name Type Description
T extends IItem<T, T> The type of the items in the list.
Parameters
Name Type Description
list T[] The list of items to convert.
pid PidType The parent ID to start the conversion from. Defaults to null.
Returns

T[]

The resulting tree structure.

Defined in

packages/eskit/src/list-to-tree.ts:22


lowerFirst

lowerFirst(value): string

Converts the first character of value to lower case.

Example

lowerFirst('Apple'); // => 'apple'
Parameters
Name Type Description
value string The string to convert.
Returns

string

Returns the converted string.

Defined in

packages/eskit/src/lower-first.ts:11


max

max(arr): undefined | number

Returns the maximum value of a numeric array. If the input value is not an array or the array is empty, returns undefined.

Example

max([1, 2, 3, 4, 5]) // 5
max([]) // undefined
max(null) // undefined
max(undefined) // undefined
Parameters
Name Type Description
arr number[] The array of numbers to search for the maximum value.
Returns

undefined | number

The maximum value of the input array, or undefined if the input is not an array or the array is empty.

Defined in

packages/eskit/src/max.ts:15


memoize

memoize<T>(fn): T

Memoizes the result of a function for the same set of arguments.

Example

function expensiveOperation(arg1: string, arg2: number): number {
  // ...some expensive operation here...
}

const memoizedOperation = memoize(expensiveOperation);

const result1 = memoizedOperation('foo', 42); // Expensive operation is called.
const result2 = memoizedOperation('foo', 42); // Expensive operation is not called.
const result3 = memoizedOperation('bar', 42); // Expensive operation is called again.
Type parameters
Name Type
T extends MemoizeFn
Parameters
Name Type Description
fn T The function to be memoized.
Returns

T

The memoized function.

Defined in

packages/eskit/src/memoize.ts:17


min

min(arr): undefined | number

Returns the smallest number in an array of numbers. Returns undefined if the input array is not an array or is empty.

Example

min([3, 1, 4, 1, 5, 9]) // returns 1
min([]) // returns undefined
Parameters
Name Type Description
arr number[] An array of numbers
Returns

undefined | number

The smallest number in the array, or undefined if the input is not an array or is empty

Defined in

packages/eskit/src/min.ts:13


mixin

mixin(...mixins): any

Creates a new class by combining multiple classes.

Example

// Define some classes
class Foo {
  foo() {}
}

class Bar {
  bar() {}
}

// Create a new class by combining Foo and Bar
const Baz = mixin(Foo, Bar);

// Create an instance of Baz
const baz = new Baz();

// Call methods from both Foo and Bar
baz.foo();
baz.bar();
Parameters
Name Type Description
...mixins any[] The classes to combine.
Returns

any

Defined in

packages/eskit/src/mixin.ts:25


multiply

multiply(a, b): number

Multiply two numbers accurately.

Example

const result = multiply(2.3, 4.5);
console.log(result); // Output: 10.35
Parameters
Name Type Description
a number The first number to multiply.
b number The second number to multiply.
Returns

number

The result of the multiplication.

Defined in

packages/eskit/src/multiply.ts:10


noop

noop(): void

Returns

void

Defined in

packages/eskit/src/noop.ts:3


pick

pick<T, K>(obj, ...keys): Pick<T, K>

Creates an object composed of the picked obj properties.

Example

const object = { 'a': 1, 'b': '2', 'c': 3 };
pick(object, 'a', 'c');
// => { 'a': 1, 'c': 3 }
Type parameters
Name Type
T T
K extends string | number | symbol
Parameters
Name Type Description
obj T The source object.
...keys K[] The property keys to pick.
Returns

Pick<T, K>

The new object.

Defined in

packages/eskit/src/pick.ts:16


range

range(start, end?, step?): number[]

Creates an array of numbers progressing from start up to, but not including, end. A step of -1 is used if a negative start is specified without an end or step.

Example

range(4); => [0, 1, 2, 3]
range(-4); => [0, -1, -2, -3]
range(1, 5); => [1, 2, 3, 4]
range(0, 20, 5); => [0, 5, 10, 15]
Parameters
Name Type Description
start number The start of the range.
end? number The end of the range.
step? number The value to increment or decrement by.
Returns

number[]

Returns the range of numbers.

Defined in

packages/eskit/src/range.ts:15


shuffle

shuffle<T>(arr): void

Randomly shuffle an array in place.

Remarks

This function modifies the original array and does not return a new array.

Example

const arr = [1, 2, 3, 4, 5];
shuffle(arr);
console.log(arr); // Output: [3, 2, 5, 1, 4] (random order)
Type parameters
Name
T
Parameters
Name Type Description
arr T[] The array to shuffle.
Returns

void

Defined in

packages/eskit/src/shuffle.ts:16


sleep

sleep(ms): Promise<void>

Pauses the execution for the specified amount of time.

Example

console.log('Start')
await sleep(2000)
console.log('End')
Parameters
Name Type Description
ms number The number of milliseconds to sleep.
Returns

Promise<void>

A promise that resolves after the specified amount of time.

Defined in

packages/eskit/src/sleep.ts:16


subtract

subtract(a, b): number

Returns the result of subtracting the second number from the first number.

Example

subtract(3, 1); // 2
Parameters
Name Type Description
a number The first number to subtract.
b number The second number to subtract from the first number.
Returns

number

The result of subtracting the second number from the first number.

Defined in

packages/eskit/src/subtract.ts:11


throttle

throttle<TArgs>(fn, delay, options?): (...args: TArgs) => void

Creates a throttled function that only invokes the original function at most once per every delay milliseconds. The throttled function has optional leading or trailing invocation.

Example

const throttledFn = throttle((x, y) => {
  console.log(x + y);
}, 1000, { leading: true });

throttledFn(1, 2); // logs 3 immediately
throttledFn(3, 4); // not invoked
setTimeout(() => throttledFn(5, 6), 2000); // logs 11 after 2 seconds
Type parameters
Name Type
TArgs extends any[]
Parameters
Name Type Description
fn (...args: TArgs) => void The original function to be throttled.
delay number The number of milliseconds to throttle.
options? Object Optional configuration for leading and/or trailing invocation.
options.leading? boolean Specify invoking the original function on the leading edge of the throttle. Default is false.
options.trailing? boolean Specify invoking the original function on the trailing edge of the throttle. Default is true.
Returns

fn

  • Throttled function that delays invoking the original function at most once per every delay milliseconds.

▸ (...args): void

Parameters
Name Type
...args TArgs
Returns

void

Defined in

packages/eskit/src/throttle.ts:23


toString

toString(value): string

Converts a value to a string.

Example

toString(123); // '123'
toString('hello'); // 'hello'
toString(null); // ''
Parameters
Name Type Description
value any The value to convert.
Returns

string

The string representation of the value, or an empty string if the value is null or undefined.

Defined in

packages/eskit/src/to-string.ts:15


treeToList

treeToList<T>(tree): T[]

Flattens a tree structure represented by an array of items with child nodes into a flat array.

Example

interface TreeNode {
  id: number;
  name: string;
  children?: TreeNode[];
}

const tree: TreeNode[] = [
  {
    id: 1,
    name: "Node 1",
    children: [
      { id: 2, name: "Node 1.1" },
      { id: 3, name: "Node 1.2" }
    ]
  },
  {
    id: 4,
    name: "Node 2",
    children: [
      { id: 5, name: "Node 2.1" },
      { id: 6, name: "Node 2.2", children: [{ id: 7, name: "Node 2.2.1" }] }
    ]
  }
];

const result = treeToList(tree);
// [
//   { id: 2, name: "Node 1.1" },
//   { id: 3, name: "Node 1.2" },
//   { id: 1, name: "Node 1" },
//   { id: 5, name: "Node 2.1" },
//   { id: 7, name: "Node 2.2.1" },
//   { id: 6, name: "Node 2.2" },
//   { id: 4, name: "Node 2" }
// ]
Type parameters
Name Type Description
T extends IItem<T, T> Type of items in the tree.
Parameters
Name Type Description
tree T[] The tree structure represented by an array of items with child nodes.
Returns

T[]

A flat array of items.

Defined in

packages/eskit/src/tree-to-list.ts:51


upperFirst

upperFirst(value): string

Converts the first character of a string to uppercase.

Example

upperFirst('hello world') // Returns 'Hello world'
Parameters
Name Type Description
value string The string to modify.
Returns

string

The modified string.

Defined in

packages/eskit/src/upper-first.ts:11

The currency symbol to use. Defaults to '$'.
Returns

__INLINE_CODE_263__

A string with the formatted currency symbol and number.

Defined in

packages/eskit/src/format-money.ts:16


formatNumber

formatNumber(__INLINE_CODE_264__, __INLINE_CODE_265__, __INLINE_CODE_266__): __INLINE_CODE_267__

Formats a number with the specified decimal separator and digit number.

This function formats a number with the specified decimal separator and digit number. If the input value is not a valid number, this function returns the input value as a string without formatting.

__INLINE_CODE_268__

const formattedNumber = formatNumber(123456.789, ',', 2)
console.log(formattedNumber)
// Output: "123,456.79"
Parameters
Name Type Default value Description
__INLINE_CODE_269__ __INLINE_CODE_270__ __INLINE_CODE_271__ The input number to be formatted.
__INLINE_CODE_272__ __INLINE_CODE_273__ __INLINE_CODE_274__ The decimal separator to use for formatting the number.
__INLINE_CODE_275__ __INLINE_CODE_276__ __INLINE_CODE_277__ The number of digits to appear after the decimal point (defaults to 0).
Returns

__INLINE_CODE_278__

The formatted number as a string.

Defined in

packages/eskit/src/format-number.ts:18


getGlobal

getGlobal(): __INLINE_CODE_279__

Returns the global object for the current runtime environment.

This function returns the global object for the current runtime environment. It works in both browser and Node.js environments.

__INLINE_CODE_280__

An error if the global object cannot be located.

__INLINE_CODE_281__

const globalObj = getGlobal()

if (typeof globalObj.process === 'object') {
  console.log('Running in Node.js')
} else {
  console.log('Running in browser')
}
Returns

__INLINE_CODE_282__

The global object for the current runtime environment.

Defined in

packages/eskit/src/get-global.ts:21


getRandomInt

getRandomInt(__INLINE_CODE_283__, __INLINE_CODE_284__): __INLINE_CODE_285__

Returns a random integer between the specified minimum and maximum values (inclusive).

This function returns a random integer between the specified minimum and maximum values (inclusive). The minimum and maximum values must be integers, and the minimum value must be less than or equal to the maximum value.

__INLINE_CODE_286__

const randomInt = getRandomInt(1, 10)
console.log(randomInt)
Parameters
Name Type Description
__INLINE_CODE_287__ __INLINE_CODE_288__ The minimum value (inclusive).
__INLINE_CODE_289__ __INLINE_CODE_290__ The maximum value (inclusive).
Returns

__INLINE_CODE_291__

A random integer between the specified minimum and maximum values (inclusive).

Defined in

packages/eskit/src/get-random-int.ts:16


getType

getType(__INLINE_CODE_292__): __INLINE_CODE_293__

Get the type of a value

__INLINE_CODE_294__

getType(42) // "Number"
getType("hello") // "String"
getType([]) // "Array"
getType(null) // "Null"
getType(undefined) // "Undefined"
getType({}) // "Object"
Parameters
Name Type Description
__INLINE_CODE_295__ __INLINE_CODE_296__ The value to get the type of
Returns

__INLINE_CODE_297__

The type of the value

Defined in

packages/eskit/src/get-type.ts:19


hasOwnProperty

hasOwnProperty(__INLINE_CODE_298__, __INLINE_CODE_299__): __INLINE_CODE_300__

A reference to the Object.prototype.hasOwnProperty() method.

This function allows you to check if an object has a property defined on itself (i.e., not inherited from its prototype chain).

__INLINE_CODE_301__

const obj = { foo: 42 }

hasOwnProperty(obj, 'foo') // true
hasOwnProperty(obj, 'toString') // false
Parameters
Name Type
__INLINE_CODE_302__ __INLINE_CODE_303__
__INLINE_CODE_304__ __INLINE_CODE_305__
Returns

__INLINE_CODE_306__

__INLINE_CODE_307__ if the object has the property defined on itself, __INLINE_CODE_308__ otherwise.

Defined in

packages/eskit/src/hasOwnProperty.ts:18


isArguments

isArguments(__INLINE_CODE_309__): __INLINE_CODE_310__

Tests whether a value is an __INLINE_CODE_311__ object.

__INLINE_CODE_312__

// Returns true
function sampleFunc() {
  return isArguments(arguments)
}
sampleFunc();

__INLINE_CODE_313__

// Returns false
isArguments([1,2,3]);
Parameters
Name Type Description
__INLINE_CODE_314__ __INLINE_CODE_315__ The value to test.
Returns

__INLINE_CODE_316__

__INLINE_CODE_317__ if the value is an __INLINE_CODE_318__ object, __INLINE_CODE_319__ otherwise.

Defined in

packages/eskit/src/is-arguments.ts:23


isArray

isArray(__INLINE_CODE_320__): value is any[]

Checks if a value is an array.

__INLINE_CODE_321__

isArray('abc') // => false
isArray([]) // => true
isArray({ 0: 'a', 1: 'b', 2: 'c', length: 3 }) // => false
Parameters
Name Type Description
__INLINE_CODE_322__ __INLINE_CODE_323__ The value to check.
Returns

value is any[]

__INLINE_CODE_324__ if the value is an array, else __INLINE_CODE_325__.

Defined in

packages/eskit/src/is-array.ts:15


isArrayBuffer

isArrayBuffer(__INLINE_CODE_326__): value is unknown[]

Tests whether a value is an __INLINE_CODE_327__ object.

__INLINE_CODE_328__

// Returns false
isArrayBuffer([1,2,3]);

__INLINE_CODE_329__

// Returns true
const buffer = new ArrayBuffer(16);
isArrayBuffer(buffer);
Parameters
Name Type Description
__INLINE_CODE_330__ __INLINE_CODE_331__ The value to test.
Returns

value is unknown[]

__INLINE_CODE_332__ if the value is an __INLINE_CODE_333__ object, __INLINE_CODE_334__ otherwise.

Defined in

packages/eskit/src/is-array-buffer.ts:21


isArrayLike

isArrayLike(__INLINE_CODE_335__): __INLINE_CODE_336__

Checks if a value is array-like.

__INLINE_CODE_337__

isArrayLike('abc') // => true
isArrayLike([]) // => true
isArrayLike({ 0: 'a', 1: 'b', 2: 'c', length: 3 }) // => true
isArrayLike(Function) // => false
Parameters
Name Type Description
__INLINE_CODE_338__ __INLINE_CODE_339__ The value to check.
Returns

__INLINE_CODE_340__

__INLINE_CODE_341__ if the value is array-like, else __INLINE_CODE_342__.

Defined in

packages/eskit/src/is-array-like.ts:15


isArrayLikeObject

isArrayLikeObject(__INLINE_CODE_343__): __INLINE_CODE_344__

Checks if a value is array-like.

__INLINE_CODE_345__

isArrayLikeObject('abc') // => true
isArrayLikeObject([]) // => true
isArrayLikeObject(document.querySelectorAll('div')) // => true
isArrayLikeObject(Function) // => false
Parameters
Name Type Description
__INLINE_CODE_346__ __INLINE_CODE_347__ The value to check.
Returns

__INLINE_CODE_348__

__INLINE_CODE_349__ if the value is array-like, else __INLINE_CODE_350__.

Defined in

packages/eskit/src/is-array-like-object.ts:19


isBoolean

isBoolean(__INLINE_CODE_351__): value is boolean

Checks if a value is a boolean.

__INLINE_CODE_352__

isBoolean(true) // => true
isBoolean(false) // => true
isBoolean(0) // => false
isBoolean('true') // => false
Parameters
Name Type Description
__INLINE_CODE_353__ __INLINE_CODE_354__ The value to check.
Returns

value is boolean

__INLINE_CODE_355__ if the value is a boolean, else __INLINE_CODE_356__.

Defined in

packages/eskit/src/is-boolean.ts:16


isDate

isDate(__INLINE_CODE_357__): value is Date

Checks if a value is a Date object.

__INLINE_CODE_358__

isDate(new Date()) // => true
isDate(Date.now()) // => false
isDate('2022-03-30') // => false
Parameters
Name Type Description
__INLINE_CODE_359__ __INLINE_CODE_360__ The value to check.
Returns

value is Date

__INLINE_CODE_361__ if the value is a Date object, else __INLINE_CODE_362__.

Defined in

packages/eskit/src/is-date.ts:15


isDecimal

isDecimal(__INLINE_CODE_363__): __INLINE_CODE_364__

Checks if a number is a decimal.

__INLINE_CODE_365__

isDecimal(1.5) // => true
isDecimal(3) // => false
isDecimal('1.23') // => false
Parameters
Name Type Description
__INLINE_CODE_366__ __INLINE_CODE_367__ The number to check.
Returns

__INLINE_CODE_368__

__INLINE_CODE_369__ if the number is a decimal, else __INLINE_CODE_370__.

Defined in

packages/eskit/src/is-decimal.ts:15


isDefined

isDefined<__INLINE_CODE_371__>(__INLINE_CODE_372__): val is T

Checks if a value is defined (not __INLINE_CODE_373__ or __INLINE_CODE_374__).

__INLINE_CODE_375__

isDefined(1) // => true
isDefined('hello') // => true
isDefined(null) // => false
isDefined(undefined) // => false
Type parameters
Name Description
__INLINE_CODE_376__ The type of the value to check.
Parameters
Name Type Description
__INLINE_CODE_377__ __INLINE_CODE_378__ | __INLINE_CODE_379__ | __INLINE_CODE_380__ The value to check.
Returns

val is T

__INLINE_CODE_381__ if the value is defined, else __INLINE_CODE_382__.

Defined in

packages/eskit/src/is-defined.ts:16


isElement

isElement(__INLINE_CODE_383__): __INLINE_CODE_384__

Checks if a value is an Element or HTMLDocument object.

__INLINE_CODE_385__

isElement(document.body) // => true
isElement(document.querySelector('.my-class')) // => true
isElement(window) // => false
isElement('not an element') // => false
Parameters
Name Type Description
__INLINE_CODE_386__ __INLINE_CODE_387__ The value to check.
Returns

__INLINE_CODE_388__

__INLINE_CODE_389__ if the value is an Element or HTMLDocument object, else __INLINE_CODE_390__.

Defined in

packages/eskit/src/is-element.ts:15


isEmpty

isEmpty(__INLINE_CODE_391__): __INLINE_CODE_392__

Checks if a value is empty.

A value is considered empty if it is __INLINE_CODE_393__, __INLINE_CODE_394__, an empty array or string, an empty Map or Set object, or an object with no own properties.

__INLINE_CODE_395__

isEmpty(undefined) // => true
isEmpty(null) // => true
isEmpty('') // => true
isEmpty([]) // => true
isEmpty(new Map()) // => true
isEmpty(new Set()) // => true
isEmpty({}) // => true
isEmpty({ prop: 'value' }) // => false
isEmpty([1, 2, 3]) // => false
isEmpty('hello') // => false
isEmpty(new Map([['key', 'value']])) // => false
isEmpty(new Set([1, 2, 3])) // => false
Parameters
Name Type Description
__INLINE_CODE_396__ __INLINE_CODE_397__ The value to check.
Returns

__INLINE_CODE_398__

__INLINE_CODE_399__ if the value is empty, else __INLINE_CODE_400__.

Defined in

packages/eskit/src/is-empty.ts:32


isEqual

isEqual(__INLINE_CODE_401__, __INLINE_CODE_402__): __INLINE_CODE_403__

Determines if two values are equal. Supports objects, arrays, and primitives.

__INLINE_CODE_404__

isEqual([1, 2, 3], [1, 2, 3]) // => true
isEqual({a: 1, b: {c: 2}}, {a: 1, b: {c: 2}}) // => true
isEqual('abc', 'abc') // => true
isEqual(1, 2) // => false
isEqual(null, undefined) // => false
Parameters
Name Type Description
__INLINE_CODE_405__ __INLINE_CODE_406__ The value to compare.
__INLINE_CODE_407__ __INLINE_CODE_408__ The other value to compare.
Returns

__INLINE_CODE_409__

True if the values are equal, false otherwise.

Defined in

packages/eskit/src/is-equal.ts:19


isEqualWith

isEqualWith<__INLINE_CODE_410__>(__INLINE_CODE_411__, __INLINE_CODE_412__, __INLINE_CODE_413__): __INLINE_CODE_414__

Performs a deep comparison between two values to determine if they are equivalent.

__INLINE_CODE_415__

isEqualWith([1, 2, 3], [1, 2, 3], (v1, v2) => {
  if (Array.isArray(v1) && Array.isArray(v2)) {
    return v1.length === v2.length;
  }
  return undefined;
}); // => true
Type parameters
Name
__INLINE_CODE_416__
Parameters
Name Type Description
__INLINE_CODE_417__ __INLINE_CODE_418__ The value to compare.
__INLINE_CODE_419__ __INLINE_CODE_420__ The other value to compare.
__INLINE_CODE_421__ (__INLINE_CODE_422__: __INLINE_CODE_423__, __INLINE_CODE_424__: __INLINE_CODE_425__) => __INLINE_CODE_426__ The customizer function to use to compare values.
Returns

__INLINE_CODE_427__

Returns __INLINE_CODE_428__ if the values are equivalent, else __INLINE_CODE_429__.

Defined in

packages/eskit/src/is-equal-with.ts:19


isError

isError(__INLINE_CODE_430__): value is Error

Determines whether the given value is an instance of __INLINE_CODE_431__.

__INLINE_CODE_432__

const err = new Error('Example error');
isError(err); // true

const obj = { error: new Error('Example error') };
isError(obj.error); // true

isError('Error'); // false
Parameters
Name Type Description
__INLINE_CODE_433__ __INLINE_CODE_434__ The value to check.
Returns

value is Error

Whether the given value is an instance of __INLINE_CODE_435__.

Defined in

packages/eskit/src/is-error.ts:17


isEven

isEven(__INLINE_CODE_436__): __INLINE_CODE_437__

Checks if a number is even.

__INLINE_CODE_438__

isEven(2); // true
isEven(3); // false
Parameters
Name Type Description
__INLINE_CODE_439__ __INLINE_CODE_440__ The number to check.
Returns

__INLINE_CODE_441__

Whether the number is even or not.

Defined in

packages/eskit/src/is-even.ts:12


isFunction

isFunction(__INLINE_CODE_442__): value is Function

Checks if a given value is a function

__INLINE_CODE_443__

isFunction(() => {}) // true
isFunction(function() {}) // true
isFunction(42) // false
Parameters
Name Type Description
__INLINE_CODE_444__ __INLINE_CODE_445__ The value to check
Returns

value is Function

True if the value is a function, false otherwise

Defined in

packages/eskit/src/is-function.ts:11


isInteger

isInteger(__INLINE_CODE_446__): __INLINE_CODE_447__

Checks if a value is an integer.

__INLINE_CODE_448__

isInteger(0); // true
isInteger(5); // true
isInteger(-10); // true
isInteger(2.5); // false
Parameters
Name Type
__INLINE_CODE_449__ __INLINE_CODE_450__
Returns

__INLINE_CODE_451__

Returns __INLINE_CODE_452__ if __INLINE_CODE_453__ is an integer, else __INLINE_CODE_454__.

Defined in

node_modules/typescript/lib/lib.es2015.core.d.ts:233


isNil

isNil(__INLINE_CODE_455__): value is undefined | null

Type guard to determine if a value is null or undefined.

__INLINE_CODE_456__

isNil(null); // true
isNil(undefined); // true
isNil(''); // false
isNil(0); // false
Parameters
Name Type Description
__INLINE_CODE_457__ __INLINE_CODE_458__ The value to test.
Returns

value is undefined | null

Whether or not the value is null or undefined.

Defined in

packages/eskit/src/is-nil.ts:17


isNumber

isNumber(__INLINE_CODE_459__): value is number

Checks if a value is a number.

__INLINE_CODE_460__

isNumber(42); // true
isNumber('42'); // false
Parameters
Name Type Description
__INLINE_CODE_461__ __INLINE_CODE_462__ The value to check.
Returns

value is number

Returns __INLINE_CODE_463__ if the value is a number, else __INLINE_CODE_464__.

Defined in

packages/eskit/src/is-number.ts:12


isObject

isObject(__INLINE_CODE_465__): value is Record<string, unknown>

Check if a value is an object.

__INLINE_CODE_466__

isObject({}) // true
isObject([]) // true
isObject(null) // false
Parameters
Name Type Description
__INLINE_CODE_467__ __INLINE_CODE_468__ The value to check.
Returns

value is Record<string, unknown>

__INLINE_CODE_469__ if the value is an object, else __INLINE_CODE_470__.

Defined in

packages/eskit/src/is-object.ts:13


isObjectLike

isObjectLike(__INLINE_CODE_471__): __INLINE_CODE_472__

Checks if a value is object-like, which means it's not null and its type is 'object'.

__INLINE_CODE_473__

isObjectLike({}); // true
isObjectLike([]); // true
isObjectLike(null); // false
isObjectLike(42); // false
Parameters
Name Type Description
__INLINE_CODE_474__ __INLINE_CODE_475__ The value to check.
Returns

__INLINE_CODE_476__

True if the value is object-like, false otherwise.

Defined in

packages/eskit/src/is-object-like.ts:13


isPromiseLike

isPromiseLike(__INLINE_CODE_477__): __INLINE_CODE_478__

Checks if a given object is promise-like (thenable).

__INLINE_CODE_479__

const myPromise = new Promise(resolve => setTimeout(() => resolve('done'), 100));
console.log(isPromiseLike(myPromise)); // true
console.log(isPromiseLike({ then: () => {} })); // true
console.log(isPromiseLike({})); // false
Parameters
Name Type Description
__INLINE_CODE_480__ __INLINE_CODE_481__ The object to check.
Returns

__INLINE_CODE_482__

Whether the object is promise-like.

Defined in

packages/eskit/src/is-promise-like.ts:11


isPrototype

isPrototype(__INLINE_CODE_483__): __INLINE_CODE_484__

Checks if __INLINE_CODE_485__ is likely a prototype object.

__INLINE_CODE_486__

function Foo() {}
isPrototype(Foo.prototype)
// => true

isPrototype({})
// => false
Parameters
Name Type Description
__INLINE_CODE_487__ __INLINE_CODE_488__ The value to check.
Returns

__INLINE_CODE_489__

Whether __INLINE_CODE_490__ is a prototype object.

Defined in

packages/eskit/src/is-prototype.ts:16


isRegExp

isRegExp(__INLINE_CODE_491__): value is RegExp

Determines whether the given value is a regular expression.

__INLINE_CODE_492__

isRegExp(/ab+c/i) // => true
isRegExp('hello') // => false
Parameters
Name Type Description
__INLINE_CODE_493__ __INLINE_CODE_494__ The value to check.
Returns

value is RegExp

__INLINE_CODE_495__ if the value is a regular expression, else __INLINE_CODE_496__.

Defined in

packages/eskit/src/is-reg-exp.ts:12


isString

isString(__INLINE_CODE_497__): value is string

Checks if a given value is a string.

__INLINE_CODE_498__

isString('hello') // => true
isString(123) // => false
Parameters
Name Type Description
__INLINE_CODE_499__ __INLINE_CODE_500__ The value to check.
Returns

value is string

Returns __INLINE_CODE_501__ if the given value is a string, else __INLINE_CODE_502__.

Defined in

packages/eskit/src/is-string.ts:12


isType

isType(__INLINE_CODE_503__, __INLINE_CODE_504__): __INLINE_CODE_505__

Checks if a value's type matches the specified type string.

__INLINE_CODE_506__

isType('String', 'hello'); // true
isType('Array', {}); // false
Parameters
Name Type Description
__INLINE_CODE_507__ __INLINE_CODE_508__ The type string to check against.
__INLINE_CODE_509__ __INLINE_CODE_510__ The value to check the type of.
Returns

__INLINE_CODE_511__

True if the value's type matches the specified type string, false otherwise.

Defined in

packages/eskit/src/is-type.ts:10


listToTree

listToTree<__INLINE_CODE_512__>(__INLINE_CODE_513__, __INLINE_CODE_514__): __INLINE_CODE_515__[]

Converts a flat list of items to a tree structure.

Type parameters
Name Type Description
__INLINE_CODE_516__ extends __INLINE_CODE_517__<__INLINE_CODE_518__, __INLINE_CODE_519__> The type of the items in the list.
Parameters
Name Type Description
__INLINE_CODE_520__ __INLINE_CODE_521__[] The list of items to convert.
__INLINE_CODE_522__ __INLINE_CODE_523__ The parent ID to start the conversion from. Defaults to null.
Returns

__INLINE_CODE_524__[]

The resulting tree structure.

Defined in

packages/eskit/src/list-to-tree.ts:22


lowerFirst

lowerFirst(__INLINE_CODE_525__): __INLINE_CODE_526__

Converts the first character of __INLINE_CODE_527__ to lower case.

__INLINE_CODE_528__

lowerFirst('Apple'); // => 'apple'
Parameters
Name Type Description
__INLINE_CODE_529__ __INLINE_CODE_530__ The string to convert.
Returns

__INLINE_CODE_531__

Returns the converted string.

Defined in

packages/eskit/src/lower-first.ts:11


max

max(__INLINE_CODE_532__): __INLINE_CODE_533__ | __INLINE_CODE_534__

Returns the maximum value of a numeric array. If the input value is not an array or the array is empty, returns __INLINE_CODE_535__.

__INLINE_CODE_536__

max([1, 2, 3, 4, 5]) // 5
max([]) // undefined
max(null) // undefined
max(undefined) // undefined
Parameters
Name Type Description
__INLINE_CODE_537__ __INLINE_CODE_538__[] The array of numbers to search for the maximum value.
Returns

__INLINE_CODE_539__ | __INLINE_CODE_540__

The maximum value of the input array, or __INLINE_CODE_541__ if the input is not an array or the array is empty.

Defined in

packages/eskit/src/max.ts:15


memoize

memoize<__INLINE_CODE_542__>(__INLINE_CODE_543__): __INLINE_CODE_544__

Memoizes the result of a function for the same set of arguments.

__INLINE_CODE_545__

function expensiveOperation(arg1: string, arg2: number): number {
  // ...some expensive operation here...
}

const memoizedOperation = memoize(expensiveOperation);

const result1 = memoizedOperation('foo', 42); // Expensive operation is called.
const result2 = memoizedOperation('foo', 42); // Expensive operation is not called.
const result3 = memoizedOperation('bar', 42); // Expensive operation is called again.
Type parameters
Name Type
__INLINE_CODE_546__ extends __INLINE_CODE_547__
Parameters
Name Type Description
__INLINE_CODE_548__ __INLINE_CODE_549__ The function to be memoized.
Returns

__INLINE_CODE_550__

The memoized function.

Defined in

packages/eskit/src/memoize.ts:17


min

min(__INLINE_CODE_551__): __INLINE_CODE_552__ | __INLINE_CODE_553__

Returns the smallest number in an array of numbers. Returns undefined if the input array is not an array or is empty.

__INLINE_CODE_554__

min([3, 1, 4, 1, 5, 9]) // returns 1
min([]) // returns undefined
Parameters
Name Type Description
__INLINE_CODE_555__ __INLINE_CODE_556__[] An array of numbers
Returns

__INLINE_CODE_557__ | __INLINE_CODE_558__

The smallest number in the array, or undefined if the input is not an array or is empty

Defined in

packages/eskit/src/min.ts:13


mixin

mixin(__INLINE_CODE_559__): __INLINE_CODE_560__

Creates a new class by combining multiple classes.

__INLINE_CODE_561__

// Define some classes
class Foo {
  foo() {}
}

class Bar {
  bar() {}
}

// Create a new class by combining Foo and Bar
const Baz = mixin(Foo, Bar);

// Create an instance of Baz
const baz = new Baz();

// Call methods from both Foo and Bar
baz.foo();
baz.bar();
Parameters
Name Type Description
__INLINE_CODE_562__ __INLINE_CODE_563__[] The classes to combine.
Returns

__INLINE_CODE_564__

Defined in

packages/eskit/src/mixin.ts:25


multiply

multiply(__INLINE_CODE_565__, __INLINE_CODE_566__): __INLINE_CODE_567__

Multiply two numbers accurately.

__INLINE_CODE_568__

const result = multiply(2.3, 4.5);
console.log(result); // Output: 10.35
Parameters
Name Type Description
__INLINE_CODE_569__ __INLINE_CODE_570__ The first number to multiply.
__INLINE_CODE_571__ __INLINE_CODE_572__ The second number to multiply.
Returns

__INLINE_CODE_573__

The result of the multiplication.

Defined in

packages/eskit/src/multiply.ts:10


noop

noop(): __INLINE_CODE_574__

Returns

__INLINE_CODE_575__

Defined in

packages/eskit/src/noop.ts:3


pick

pick<__INLINE_CODE_576__, __INLINE_CODE_577__>(__INLINE_CODE_578__, __INLINE_CODE_579__): __INLINE_CODE_580__<__INLINE_CODE_581__, __INLINE_CODE_582__>

Creates an object composed of the picked __INLINE_CODE_583__ properties.

__INLINE_CODE_584__

const object = { 'a': 1, 'b': '2', 'c': 3 };
pick(object, 'a', 'c');
// => { 'a': 1, 'c': 3 }
Type parameters
Name Type
__INLINE_CODE_585__ __INLINE_CODE_586__
__INLINE_CODE_587__ extends __INLINE_CODE_588__ | __INLINE_CODE_589__ | __INLINE_CODE_590__
Parameters
Name Type Description
__INLINE_CODE_591__ __INLINE_CODE_592__ The source object.
__INLINE_CODE_593__ __INLINE_CODE_594__[] The property keys to pick.
Returns

__INLINE_CODE_595__<__INLINE_CODE_596__, __INLINE_CODE_597__>

The new object.

Defined in

packages/eskit/src/pick.ts:16


range

range(__INLINE_CODE_598__, __INLINE_CODE_599__, __INLINE_CODE_600__): __INLINE_CODE_601__[]

Creates an array of numbers progressing from start up to, but not including, end. A step of -1 is used if a negative start is specified without an end or step.

__INLINE_CODE_602__

range(4); => [0, 1, 2, 3]
range(-4); => [0, -1, -2, -3]
range(1, 5); => [1, 2, 3, 4]
range(0, 20, 5); => [0, 5, 10, 15]
Parameters
Name Type Description
__INLINE_CODE_603__ __INLINE_CODE_604__ The start of the range.
__INLINE_CODE_605__ __INLINE_CODE_606__ The end of the range.
__INLINE_CODE_607__ __INLINE_CODE_608__ The value to increment or decrement by.
Returns

__INLINE_CODE_609__[]

Returns the range of numbers.

Defined in

packages/eskit/src/range.ts:15


shuffle

shuffle<__INLINE_CODE_610__>(__INLINE_CODE_611__): __INLINE_CODE_612__

Randomly shuffle an array in place.

__INLINE_CODE_613__

This function modifies the original array and does not return a new array.

__INLINE_CODE_614__

const arr = [1, 2, 3, 4, 5];
shuffle(arr);
console.log(arr); // Output: [3, 2, 5, 1, 4] (random order)
Type parameters
Name
__INLINE_CODE_615__
Parameters
Name Type Description
__INLINE_CODE_616__ __INLINE_CODE_617__[] The array to shuffle.
Returns

__INLINE_CODE_618__

Defined in

packages/eskit/src/shuffle.ts:16


sleep

sleep(__INLINE_CODE_619__): __INLINE_CODE_620__<__INLINE_CODE_621__>

Pauses the execution for the specified amount of time.

__INLINE_CODE_622__

console.log('Start')
await sleep(2000)
console.log('End')
Parameters
Name Type Description
__INLINE_CODE_623__ __INLINE_CODE_624__ The number of milliseconds to sleep.
Returns

__INLINE_CODE_625__<__INLINE_CODE_626__>

A promise that resolves after the specified amount of time.

Defined in

packages/eskit/src/sleep.ts:16


subtract

subtract(__INLINE_CODE_627__, __INLINE_CODE_628__): __INLINE_CODE_629__

Returns the result of subtracting the second number from the first number.

__INLINE_CODE_630__

subtract(3, 1); // 2
Parameters
Name Type Description
__INLINE_CODE_631__ __INLINE_CODE_632__ The first number to subtract.
__INLINE_CODE_633__ __INLINE_CODE_634__ The second number to subtract from the first number.
Returns

__INLINE_CODE_635__

The result of subtracting the second number from the first number.

Defined in

packages/eskit/src/subtract.ts:11


throttle

throttle<__INLINE_CODE_636__>(__INLINE_CODE_637__, __INLINE_CODE_638__, __INLINE_CODE_639__): (...__INLINE_CODE_640__: __INLINE_CODE_641__) => __INLINE_CODE_642__

Creates a throttled function that only invokes the original function at most once per every __INLINE_CODE_643__ milliseconds. The throttled function has optional leading or trailing invocation.

__INLINE_CODE_644__

const throttledFn = throttle((x, y) => {
  console.log(x + y);
}, 1000, { leading: true });

throttledFn(1, 2); // logs 3 immediately
throttledFn(3, 4); // not invoked
setTimeout(() => throttledFn(5, 6), 2000); // logs 11 after 2 seconds
Type parameters
Name Type
__INLINE_CODE_645__ extends __INLINE_CODE_646__[]
Parameters
Name Type Description
__INLINE_CODE_647__ (...__INLINE_CODE_648__: __INLINE_CODE_649__) => __INLINE_CODE_650__ The original function to be throttled.
__INLINE_CODE_651__ __INLINE_CODE_652__ The number of milliseconds to throttle.
__INLINE_CODE_653__ __INLINE_CODE_654__ Optional configuration for leading and/or trailing invocation.
__INLINE_CODE_655__ __INLINE_CODE_656__ Specify invoking the original function on the leading edge of the throttle. Default is __INLINE_CODE_657__.
__INLINE_CODE_658__ __INLINE_CODE_659__ Specify invoking the original function on the trailing edge of the throttle. Default is __INLINE_CODE_660__.
Returns

__INLINE_CODE_661__

  • Throttled function that delays invoking the original function at most once per every __INLINE_CODE_662__ milliseconds.

▸ (__INLINE_CODE_663__): __INLINE_CODE_664__

Parameters
Name Type
__INLINE_CODE_665__ __INLINE_CODE_666__
Returns

__INLINE_CODE_667__

Defined in

packages/eskit/src/throttle.ts:23


toString

toString(__INLINE_CODE_668__): __INLINE_CODE_669__

Converts a value to a string.

__INLINE_CODE_670__

toString(123); // '123'
toString('hello'); // 'hello'
toString(null); // ''
Parameters
Name Type Description
__INLINE_CODE_671__ __INLINE_CODE_672__ The value to convert.
Returns

__INLINE_CODE_673__

The string representation of the value, or an empty string if the value is null or undefined.

Defined in

packages/eskit/src/to-string.ts:15


treeToList

treeToList<__INLINE_CODE_674__>(__INLINE_CODE_675__): __INLINE_CODE_676__[]

Flattens a tree structure represented by an array of items with child nodes into a flat array.

__INLINE_CODE_677__

interface TreeNode {
  id: number;
  name: string;
  children?: TreeNode[];
}

const tree: TreeNode[] = [
  {
    id: 1,
    name: "Node 1",
    children: [
      { id: 2, name: "Node 1.1" },
      { id: 3, name: "Node 1.2" }
    ]
  },
  {
    id: 4,
    name: "Node 2",
    children: [
      { id: 5, name: "Node 2.1" },
      { id: 6, name: "Node 2.2", children: [{ id: 7, name: "Node 2.2.1" }] }
    ]
  }
];

const result = treeToList(tree);
// [
//   { id: 2, name: "Node 1.1" },
//   { id: 3, name: "Node 1.2" },
//   { id: 1, name: "Node 1" },
//   { id: 5, name: "Node 2.1" },
//   { id: 7, name: "Node 2.2.1" },
//   { id: 6, name: "Node 2.2" },
//   { id: 4, name: "Node 2" }
// ]
Type parameters
Name Type Description
__INLINE_CODE_678__ extends __INLINE_CODE_679__<__INLINE_CODE_680__, __INLINE_CODE_681__> Type of items in the tree.
Parameters
Name Type Description
__INLINE_CODE_682__ __INLINE_CODE_683__[] The tree structure represented by an array of items with child nodes.
Returns

__INLINE_CODE_684__[]

A flat array of items.

Defined in

packages/eskit/src/tree-to-list.ts:51


upperFirst

upperFirst(__INLINE_CODE_685__): __INLINE_CODE_686__

Converts the first character of a string to uppercase.

__INLINE_CODE_687__

upperFirst('hello world') // Returns 'Hello world'
Parameters
Name Type Description
__INLINE_CODE_688__ __INLINE_CODE_689__ The string to modify.
Returns

__INLINE_CODE_690__

The modified string.

Defined in

packages/eskit/src/upper-first.ts:11

Keywords