UNPKG

@yantrix/functions

Version:

Typescript built-ins for Yantrix framework

372 lines (367 loc) 20.5 kB
import * as _yantrix_automata from '@yantrix/automata'; import * as lodash from 'lodash'; import * as _yantrix_utils from '@yantrix/utils'; type TCollection<K extends string | number | symbol = string, V = unknown> = Record<K, V>[]; /** * Evaluates a condition and returns the corresponding value. * * @template T - The type of the return value if the condition is true. * @param condition - The condition that needs to be checked. * @param trueValue - The return value if the condition is true. Defaults to the condition value if not provided. * @param falseValue - The return value if the condition is false. Defaults to null if not provided. * @returns The return value if the condition is true, otherwise the alternative value. */ declare function _if<T>(condition: any, trueValue?: T, falseValue?: T): T | null; /** * Selects the element at the specified index from a list of options. * If the only argument after the index is an array, it flattens the array before selecting the element. * * @template T - The type of the elements in the options. * * @param index - The zero-based index of the element to select. * @param options - A list of options to choose from, one by one. * @returns The element at the specified index, or undefined if the index is out of bounds. * * @throws {Error} If no options are provided. * @throws {Error} If the index is out of bounds. * * @example * choose(1, 'a', 'b', 'c'); // Returns 'b' * choose(2, ['a', 'b', 'c', 'd']); // throws error * choose(0); // Throws error * choose(5, 'a', 'b', 'c'); // Throws error */ declare function choose<T>(index: number, ...options: T[]): T | undefined; /** * @namespace * Functions that execute conditional logic. * * See also: * [Conditionals](/syntax/140_functions.html#built-ins-conditional-expressions) * */ declare const Conditionals: { case: <T = any>(...args: [...Array<boolean | T>, T]) => T; choose: typeof choose; coalesce: <T = any>(...values: (T | null | undefined)[]) => T | null; if: typeof _if; }; /** * @namespace * Functions that evaluate boolean conditions. * * See also: * [Predicates](/syntax/150_predicates.html) */ declare const Predicates: { isEven(n: number): boolean | null; isOdd(n: number): boolean | null; isInteger(value: number): boolean | null; isGreater(a: number, b: number): boolean; isGreaterOrEqual(a: number, b: number): boolean; isLess(a: number, b: number): boolean; isLessOrEqual(a: number, b: number): boolean; isNegative(value: number): boolean; isPositive(value: number): boolean; contains(str: string, substr: string): boolean; contains<T extends object>(obj: T, value: any): boolean; contains<T, V>(list: ArrayLike<T>, value: V): boolean; has<T>(list: T[], index: number): boolean; has<T extends object>(obj: T, key: any): key is keyof T; and: (...conditions: any[]) => boolean; all: (...conditions: any[]) => boolean; or: (...conditions: any[]) => boolean; any: (...conditions: any[]) => boolean; not: (condition: any) => boolean; none: (...conditions: any[]) => boolean; isEqual: (value: any, other: any) => boolean; isNull: (value: any) => value is null; }; /** * @namespace * Functions that transform data. * * See also: * [Transformers](/syntax/160_transformers.html) */ declare const Transformers: { len(str: string): number; len<T>(list: T[]): number; lookup<T>(list: T[], value: T): _yantrix_utils.TNullable<T>; substr(str: string, start: number, end?: number): string; pluck(collection: TCollection, prop: string): any[]; left: <T>(array: lodash.List<T> | null | undefined, n?: number) => T[]; right: <T>(array: lodash.List<T> | null | undefined, n?: number) => T[]; reverse: <TList extends lodash.List<any>>(array: TList) => TList; indexOf: <T>(array: lodash.List<T> | null | undefined, value: T, fromIndex?: number) => number; repeat: (string?: string, n?: number) => string; filterBy: { (collection: string | null | undefined, predicate?: lodash.StringIterator<boolean>): string[]; <T, S extends T>(collection: lodash.List<T> | null | undefined, predicate: lodash.ListIteratorTypeGuard<T, S>): S[]; <T>(collection: lodash.List<T> | null | undefined, predicate?: lodash.ListIterateeCustom<T, boolean>): T[]; <T extends object, S extends T[keyof T]>(collection: T | null | undefined, predicate: lodash.ObjectIteratorTypeGuard<T, S>): S[]; <T extends object>(collection: T | null | undefined, predicate?: lodash.ObjectIterateeCustom<T, boolean>): Array<T[keyof T]>; }; sort: { <T>(collection: lodash.List<T> | null | undefined, ...iteratees: Array<lodash.Many<lodash.ListIteratee<T>>>): T[]; <T extends object>(collection: T | null | undefined, ...iteratees: Array<lodash.Many<lodash.ObjectIteratee<T>>>): Array<T[keyof T]>; }; shuffle: { <T>(collection: lodash.List<T> | null | undefined): T[]; <T extends object>(collection: T | null | undefined): Array<T[keyof T]>; }; concat: <T>(...values: Array<lodash.Many<T>>) => T[]; find: { <T, S extends T>(collection: lodash.List<T> | null | undefined, predicate: lodash.ListIteratorTypeGuard<T, S>, fromIndex?: number): S | undefined; <T>(collection: lodash.List<T> | null | undefined, predicate?: lodash.ListIterateeCustom<T, boolean>, fromIndex?: number): T | undefined; <T extends object, S extends T[keyof T]>(collection: T | null | undefined, predicate: lodash.ObjectIteratorTypeGuard<T, S>, fromIndex?: number): S | undefined; <T extends object>(collection: T | null | undefined, predicate?: lodash.ObjectIterateeCustom<T, boolean>, fromIndex?: number): T[keyof T] | undefined; }; every: { <T>(collection: lodash.List<T> | null | undefined, predicate?: lodash.ListIterateeCustom<T, boolean>): boolean; <T extends object>(collection: T | null | undefined, predicate?: lodash.ObjectIterateeCustom<T, boolean>): boolean; }; intersect: <T>(...arrays: Array<lodash.List<T> | null | undefined>) => T[]; keys: (object?: any) => string[]; merge: { <TObject, TSource>(object: TObject, source: TSource): TObject & TSource; <TObject, TSource1, TSource2>(object: TObject, source1: TSource1, source2: TSource2): TObject & TSource1 & TSource2; <TObject, TSource1, TSource2, TSource3>(object: TObject, source1: TSource1, source2: TSource2, source3: TSource3): TObject & TSource1 & TSource2 & TSource3; <TObject, TSource1, TSource2, TSource3, TSource4>(object: TObject, source1: TSource1, source2: TSource2, source3: TSource3, source4: TSource4): TObject & TSource1 & TSource2 & TSource3 & TSource4; (object: any, ...otherArgs: any[]): any; }; omit: { <T extends object, K extends lodash.PropertyName[]>(object: T | null | undefined, ...paths: K): Pick<T, Exclude<keyof T, K[number]>>; <T extends object, K extends keyof T>(object: T | null | undefined, ...paths: Array<lodash.Many<K>>): lodash.Omit<T, K>; <T extends object>(object: T | null | undefined, ...paths: Array<lodash.Many<lodash.PropertyName>>): lodash.PartialObject<T>; }; padRight: (string?: string, length?: number, chars?: string) => string; padLeft: (string?: string, length?: number, chars?: string) => string; pick: { <T extends object, U extends keyof T>(object: T, ...props: Array<lodash.Many<U>>): Pick<T, U>; <T>(object: T | null | undefined, ...props: Array<lodash.Many<lodash.PropertyPath>>): lodash.PartialObject<T>; }; sample: { <T>(collection: readonly [T, ...T[]]): T; <T>(collection: lodash.Dictionary<T> | lodash.NumericDictionary<T> | null | undefined): T | undefined; <T extends object>(collection: T | null | undefined): T[keyof T] | undefined; }; setAttr: { <T extends object>(object: T, path: lodash.PropertyPath, value: any): T; <TResult>(object: object, path: lodash.PropertyPath, value: any): TResult; }; unsetAttr: (object: any, path: lodash.PropertyPath) => boolean; values: { <T>(object: lodash.Dictionary<T> | lodash.NumericDictionary<T> | lodash.List<T> | null | undefined): T[]; <T extends object>(object: T | null | undefined): Array<T[keyof T]>; (object: any): any[]; }; zip: { <T1, T2>(arrays1: lodash.List<T1>, arrays2: lodash.List<T2>): Array<[T1 | undefined, T2 | undefined]>; <T1, T2, T3>(arrays1: lodash.List<T1>, arrays2: lodash.List<T2>, arrays3: lodash.List<T3>): Array<[T1 | undefined, T2 | undefined, T3 | undefined]>; <T1, T2, T3, T4>(arrays1: lodash.List<T1>, arrays2: lodash.List<T2>, arrays3: lodash.List<T3>, arrays4: lodash.List<T4>): Array<[T1 | undefined, T2 | undefined, T3 | undefined, T4 | undefined]>; <T1, T2, T3, T4, T5>(arrays1: lodash.List<T1>, arrays2: lodash.List<T2>, arrays3: lodash.List<T3>, arrays4: lodash.List<T4>, arrays5: lodash.List<T5>): Array<[T1 | undefined, T2 | undefined, T3 | undefined, T4 | undefined, T5 | undefined]>; <T>(...arrays: Array<lodash.List<T> | null | undefined>): Array<Array<T | undefined>>; }; add(nums: number[]): number | null; add(...nums: number[]): number | null; diff(a: number, b: number): number; mult(...nums: number[]): number | null; mult(nums: number[]): number | null; div(a: number, b: number): number; pow(n: number, exp: number): number; inc(n: number): number | null; dec(n: number): number | null; neg(n: number): number | null; inv(n: number): number; mod(a: number, b: number): number; trunc(n: number): number; ceil(n: number): number; round(n: number, precision?: number): number | null; sin(n: number): number; cos(n: number): number; sqrt(n: number): number; ln(n: number): number; log(num: number, base: number): number; lg(n: number): number; deg(rads: number): number; rad(degs: number): number; max(...nums: number[]): number | null; max(nums: number[]): number | null; min(...nums: number[]): number | null; min(nums: number[]): number | null; sum(...nums: number[]): number | null; sum(nums: number[]): number | null; avg(...nums: number[]): number | null; avg(nums: number[]): number | null; med(...nums: number[]): number | null; med(nums: number[]): number | null; sumsq(...nums: number[]): number | null; sumsq(nums: number[]): number | null; sumProduct: (...lists: number[][]) => number | null; }; /** * @hidden */ declare const builtInFunctions: { len(str: string): number; len<T>(list: T[]): number; lookup<T>(list: T[], value: T): _yantrix_utils.TNullable<T>; substr(str: string, start: number, end?: number): string; pluck(collection: TCollection, prop: string): any[]; left: <T>(array: lodash.List<T> | null | undefined, n?: number) => T[]; right: <T>(array: lodash.List<T> | null | undefined, n?: number) => T[]; reverse: <TList extends lodash.List<any>>(array: TList) => TList; indexOf: <T>(array: lodash.List<T> | null | undefined, value: T, fromIndex?: number) => number; repeat: (string?: string, n?: number) => string; filterBy: { (collection: string | null | undefined, predicate?: lodash.StringIterator<boolean>): string[]; <T, S extends T>(collection: lodash.List<T> | null | undefined, predicate: lodash.ListIteratorTypeGuard<T, S>): S[]; <T>(collection: lodash.List<T> | null | undefined, predicate?: lodash.ListIterateeCustom<T, boolean>): T[]; <T extends object, S extends T[keyof T]>(collection: T | null | undefined, predicate: lodash.ObjectIteratorTypeGuard<T, S>): S[]; <T extends object>(collection: T | null | undefined, predicate?: lodash.ObjectIterateeCustom<T, boolean>): Array<T[keyof T]>; }; sort: { <T>(collection: lodash.List<T> | null | undefined, ...iteratees: Array<lodash.Many<lodash.ListIteratee<T>>>): T[]; <T extends object>(collection: T | null | undefined, ...iteratees: Array<lodash.Many<lodash.ObjectIteratee<T>>>): Array<T[keyof T]>; }; shuffle: { <T>(collection: lodash.List<T> | null | undefined): T[]; <T extends object>(collection: T | null | undefined): Array<T[keyof T]>; }; concat: <T>(...values: Array<lodash.Many<T>>) => T[]; find: { <T, S extends T>(collection: lodash.List<T> | null | undefined, predicate: lodash.ListIteratorTypeGuard<T, S>, fromIndex?: number): S | undefined; <T>(collection: lodash.List<T> | null | undefined, predicate?: lodash.ListIterateeCustom<T, boolean>, fromIndex?: number): T | undefined; <T extends object, S extends T[keyof T]>(collection: T | null | undefined, predicate: lodash.ObjectIteratorTypeGuard<T, S>, fromIndex?: number): S | undefined; <T extends object>(collection: T | null | undefined, predicate?: lodash.ObjectIterateeCustom<T, boolean>, fromIndex?: number): T[keyof T] | undefined; }; every: { <T>(collection: lodash.List<T> | null | undefined, predicate?: lodash.ListIterateeCustom<T, boolean>): boolean; <T extends object>(collection: T | null | undefined, predicate?: lodash.ObjectIterateeCustom<T, boolean>): boolean; }; intersect: <T>(...arrays: Array<lodash.List<T> | null | undefined>) => T[]; keys: (object?: any) => string[]; merge: { <TObject, TSource>(object: TObject, source: TSource): TObject & TSource; <TObject, TSource1, TSource2>(object: TObject, source1: TSource1, source2: TSource2): TObject & TSource1 & TSource2; <TObject, TSource1, TSource2, TSource3>(object: TObject, source1: TSource1, source2: TSource2, source3: TSource3): TObject & TSource1 & TSource2 & TSource3; <TObject, TSource1, TSource2, TSource3, TSource4>(object: TObject, source1: TSource1, source2: TSource2, source3: TSource3, source4: TSource4): TObject & TSource1 & TSource2 & TSource3 & TSource4; (object: any, ...otherArgs: any[]): any; }; omit: { <T extends object, K extends lodash.PropertyName[]>(object: T | null | undefined, ...paths: K): Pick<T, Exclude<keyof T, K[number]>>; <T extends object, K extends keyof T>(object: T | null | undefined, ...paths: Array<lodash.Many<K>>): lodash.Omit<T, K>; <T extends object>(object: T | null | undefined, ...paths: Array<lodash.Many<lodash.PropertyName>>): lodash.PartialObject<T>; }; padRight: (string?: string, length?: number, chars?: string) => string; padLeft: (string?: string, length?: number, chars?: string) => string; pick: { <T extends object, U extends keyof T>(object: T, ...props: Array<lodash.Many<U>>): Pick<T, U>; <T>(object: T | null | undefined, ...props: Array<lodash.Many<lodash.PropertyPath>>): lodash.PartialObject<T>; }; sample: { <T>(collection: readonly [T, ...T[]]): T; <T>(collection: lodash.Dictionary<T> | lodash.NumericDictionary<T> | null | undefined): T | undefined; <T extends object>(collection: T | null | undefined): T[keyof T] | undefined; }; setAttr: { <T extends object>(object: T, path: lodash.PropertyPath, value: any): T; <TResult>(object: object, path: lodash.PropertyPath, value: any): TResult; }; unsetAttr: (object: any, path: lodash.PropertyPath) => boolean; values: { <T>(object: lodash.Dictionary<T> | lodash.NumericDictionary<T> | lodash.List<T> | null | undefined): T[]; <T extends object>(object: T | null | undefined): Array<T[keyof T]>; (object: any): any[]; }; zip: { <T1, T2>(arrays1: lodash.List<T1>, arrays2: lodash.List<T2>): Array<[T1 | undefined, T2 | undefined]>; <T1, T2, T3>(arrays1: lodash.List<T1>, arrays2: lodash.List<T2>, arrays3: lodash.List<T3>): Array<[T1 | undefined, T2 | undefined, T3 | undefined]>; <T1, T2, T3, T4>(arrays1: lodash.List<T1>, arrays2: lodash.List<T2>, arrays3: lodash.List<T3>, arrays4: lodash.List<T4>): Array<[T1 | undefined, T2 | undefined, T3 | undefined, T4 | undefined]>; <T1, T2, T3, T4, T5>(arrays1: lodash.List<T1>, arrays2: lodash.List<T2>, arrays3: lodash.List<T3>, arrays4: lodash.List<T4>, arrays5: lodash.List<T5>): Array<[T1 | undefined, T2 | undefined, T3 | undefined, T4 | undefined, T5 | undefined]>; <T>(...arrays: Array<lodash.List<T> | null | undefined>): Array<Array<T | undefined>>; }; add(nums: number[]): number | null; add(...nums: number[]): number | null; diff(a: number, b: number): number; mult(...nums: number[]): number | null; mult(nums: number[]): number | null; div(a: number, b: number): number; pow(n: number, exp: number): number; inc(n: number): number | null; dec(n: number): number | null; neg(n: number): number | null; inv(n: number): number; mod(a: number, b: number): number; trunc(n: number): number; ceil(n: number): number; round(n: number, precision?: number): number | null; sin(n: number): number; cos(n: number): number; sqrt(n: number): number; ln(n: number): number; log(num: number, base: number): number; lg(n: number): number; deg(rads: number): number; rad(degs: number): number; max(...nums: number[]): number | null; max(nums: number[]): number | null; min(...nums: number[]): number | null; min(nums: number[]): number | null; sum(...nums: number[]): number | null; sum(nums: number[]): number | null; avg(...nums: number[]): number | null; avg(nums: number[]): number | null; med(...nums: number[]): number | null; med(nums: number[]): number | null; sumsq(...nums: number[]): number | null; sumsq(nums: number[]): number | null; sumProduct: (...lists: number[][]) => number | null; isEven(n: number): boolean | null; isOdd(n: number): boolean | null; isInteger(value: number): boolean | null; isGreater(a: number, b: number): boolean; isGreaterOrEqual(a: number, b: number): boolean; isLess(a: number, b: number): boolean; isLessOrEqual(a: number, b: number): boolean; isNegative(value: number): boolean; isPositive(value: number): boolean; contains(str: string, substr: string): boolean; contains<T extends object>(obj: T, value: any): boolean; contains<T, V>(list: ArrayLike<T>, value: V): boolean; has<T>(list: T[], index: number): boolean; has<T extends object>(obj: T, key: any): key is keyof T; and: (...conditions: any[]) => boolean; all: (...conditions: any[]) => boolean; or: (...conditions: any[]) => boolean; any: (...conditions: any[]) => boolean; not: (condition: any) => boolean; none: (...conditions: any[]) => boolean; isEqual: (value: any, other: any) => boolean; isNull: (value: any) => value is null; case: <T = any>(...args: [...Array<boolean | T>, T]) => T; choose: typeof choose; coalesce: <T = any>(...values: (T | null | undefined)[]) => T | null; if: typeof _if; }; declare const internalFunctions: { currentTimestamp: () => number; currentTime: () => string; random: (min?: number, max?: number) => number; weightedRandom: (object: { [key: string]: number; }) => string; currentStateId: <T extends _yantrix_automata.GenericAutomata>(automataClass: _yantrix_automata.TAbstractConstructor<T>) => (automata: T) => number | null; currentStateName: <T extends _yantrix_automata.GenericAutomata>(automataClass: _yantrix_automata.TAbstractConstructor<T>, statesDictionary: Record<string, number>) => (automata: T) => string | null; currentActionId: <T extends _yantrix_automata.GenericAutomata>(automataClass: _yantrix_automata.TAbstractConstructor<T>) => (automata: T) => number | null; currentActionName: <T extends _yantrix_automata.GenericAutomata>(automataClass: _yantrix_automata.TAbstractConstructor<T>, actionsDictionary: Record<string, number>) => (automata: T) => string | null; currentCycle: <T extends _yantrix_automata.GenericAutomata>(automataClass: _yantrix_automata.TAbstractConstructor<T>) => (automata: T) => number | null; currentEpoch: (epochRef: { val: number; }) => () => { val: number; }; }; declare const ReservedInternalFunctionNames: string[]; export { Conditionals, Predicates, ReservedInternalFunctionNames, Transformers, builtInFunctions, internalFunctions };