1.0.0-Beta • Published 1 year ago

ts-copilot v1.0.0-Beta

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

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

NameTypeDescription
anumberThe first number to add.
bnumberThe 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

NameTypeDescription
numnumberThe number to clamp.
minnumberThe lower boundary of the range.
maxnumberThe 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

NameTypeDescription
objTThe 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

NameDescription
TThe type of the input and output value.

Parameters

NameTypeDescription
...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
NameType
argT
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

NameType
Textends Record<string, any>

Parameters

NameTypeDescription
objTThe 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

NameTypeDefault valueDescription
arrstring | any[]undefinedThe array or string to search through.
valueanyundefinedThe value to search for.
positionnumber-1Optional. 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

NameType
TT
Uextends Record<string, unknown>

Parameters

NameTypeDescription
targetTThe target object.
sourceUThe 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

NameTypeDescription
fn(...args: any[]) => anyThe function to be curried.

Returns

fn

A curried function.

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

Parameters
NameType
...argsany[]
Returns

fn

▸ (...args): any

Parameters
NameType
...argsany[]
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

NameType
Argsextends any[]

Parameters

NameTypeDescription
fn(...args: Args) => voidThe function to wrap.
delaynumberThe delay time (in milliseconds) before the function is executed.
immediate?booleanWhether 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

NameType
objT

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

NameTypeDefault valueDescription
arrT[]undefinedThe array to inspect.
valuesT[][]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

NameTypeDescription
anumberThe dividend.
bnumberThe 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

NameTypeDescription
collectionRecord<string, T> | T[]The collection to iterate over.
func(value: T, key?: string | number, collection?: Record<string, T> | T[]) => anyThe 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

NameTypeDescription
parentObjectType<any>The parent object to extend.
childObjectType<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

NameType
Textends Record<string, unknown> | unknown[]

Parameters

NameTypeDescription
collectionTThe array or object to filter.
callback(value: T extends U[] ? U : Tkeyof T, indexOrKey: T extends unknown[] ? number : keyof T, collection: T) => booleanThe 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

NameTypeDescription
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

NameTypeDefault valueDescription
moneynumberundefinedThe number to be formatted.
currencySymbolstring'$'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

NameTypeDefault valueDescription
valnumberundefinedThe input number to be formatted.
separatorstringundefinedThe decimal separator to use for formatting the number.
digitNumnumber0The 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

NameTypeDescription
minnumberThe minimum value (inclusive).
maxnumberThe 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

NameTypeDescription
valueanyThe 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

NameType
objunknown
keyPropertyKey

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

NameTypeDescription
valueunknownThe 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

NameTypeDescription
valueanyThe 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

NameTypeDescription
valueunknownThe 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

NameTypeDescription
valueanyThe 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

NameTypeDescription
valueunknownThe 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

NameTypeDescription
valueunknownThe 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

NameTypeDescription
valueunknownThe 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

NameTypeDescription
numunknownThe 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

NameDescription
TThe type of the value to check.

Parameters

NameTypeDescription
valundefined | null | TThe 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

NameTypeDescription
ounknownThe 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

NameTypeDescription
valueanyThe 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

NameTypeDescription
valueanyThe value to compare.
otheranyThe 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

NameTypeDescription
valueTThe value to compare.
otherTThe other value to compare.
fn(v1: T, v2: T) => booleanThe 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

NameTypeDescription
valueunknownThe 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

NameTypeDescription
numnumberThe 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

NameTypeDescription
valueunknownThe 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

NameType
numberunknown

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

NameTypeDescription
valueunknownThe 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

NameTypeDescription
valueunknownThe 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

NameTypeDescription
valueunknownThe 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

NameTypeDescription
valueunknownThe 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

NameTypeDescription
objanyThe 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

NameTypeDescription
valueunknownThe 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

NameTypeDescription
valueunknownThe 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

NameTypeDescription
valueunknownThe 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

NameTypeDescription
typestringThe type string to check against.
valueunknownThe 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

NameTypeDescription
Textends IItem<T, T>The type of the items in the list.

Parameters

NameTypeDescription
listT[]The list of items to convert.
pidPidTypeThe 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

NameTypeDescription
valuestringThe 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

NameTypeDescription
arrnumber[]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

NameType
Textends MemoizeFn

Parameters

NameTypeDescription
fnTThe 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

NameTypeDescription
arrnumber[]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

NameTypeDescription
...mixinsany[]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

NameTypeDescription
anumberThe first number to multiply.
bnumberThe 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

NameType
TT
Kextends string | number | symbol

Parameters

NameTypeDescription
objTThe source object.
...keysK[]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

NameTypeDescription
startnumberThe start of the range.
end?numberThe end of the range.
step?numberThe 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

NameTypeDescription
arrT[]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

NameTypeDescription
msnumberThe 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

NameTypeDescription
anumberThe first number to subtract.
bnumberThe 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

NameType
TArgsextends any[]

Parameters

NameTypeDescription
fn(...args: TArgs) => voidThe original function to be throttled.
delaynumberThe number of milliseconds to throttle.
options?ObjectOptional configuration for leading and/or trailing invocation.
options.leading?booleanSpecify invoking the original function on the leading edge of the throttle. Default is false.
options.trailing?booleanSpecify 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
NameType
...argsTArgs
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

NameTypeDescription
valueanyThe 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

NameTypeDescription
Textends IItem<T, T>Type of items in the tree.

Parameters

NameTypeDescription
treeT[]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

NameTypeDescription
valuestringThe string to modify.

Returns

string

The modified string.

Defined in

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