@ch1/utility
Version:
Utility functions I end up adding to all my projects
49 lines (48 loc) • 3.16 kB
TypeScript
import { Dictionary } from './interfaces';
export declare function arrToObj<T>(arr: T[], prop?: string, aggregate?: boolean): Dictionary<T> | Dictionary<T[]>;
/** assumes number is between 0 - 1 inclusive of 0 but not 1 */
export declare function createBetween(random: () => number): (minimum: number, maximum: number) => number;
export declare function deepFreeze<T>(obj: T): T;
export declare function identity<T>(thing: T): T;
export declare function findCaseInsensitivePropInObj<T>(obj: Dictionary<T>, prop: string): T | boolean;
export declare function hasProp(prop: string, haystack: Dictionary<any>): boolean;
export declare function isBoolean(arg: any): arg is boolean;
export declare function isFunction(thing: any): thing is (() => any);
export declare function isNaN(thing: any): boolean;
export declare function isNull(thing: any): thing is null;
export declare function isNumber(thing: any): thing is number;
export declare function isObject(thing: any): thing is Object;
export declare function isString(thing: any): thing is string;
export declare function isUndefined(thing: any): thing is void;
export declare function noop(): void;
export declare function objEach<T>(d: Dictionary<T>, callback: (value: T, key?: string, index?: number, d?: Dictionary<T>) => any): void;
export declare function objFilter<T>(d: Dictionary<T>, callback: (value: T, key: string, index: number) => boolean): Dictionary<T>;
export declare function objReduce<T, R>(d: Dictionary<T>, callback: (state: R, value: T, key: string, index: number, d: Dictionary<T>) => R, init: R): R;
export declare function partial<T>(f: Function, ...boundArg: any[]): (...args: any[]) => T;
export declare function pluck<T>(prop: string, haystack: Dictionary<T>): T;
export declare function toGtZeroIntMax(max: number, val: any): number;
export declare function toInt(val: any): number;
export declare function toIntArray(inputArr: any[]): number[];
export declare function toIntArrayMax(max: number, inputArr: any[]): number[];
export declare function toIntArrayMin(max: number, inputArr: any[]): number[];
export declare function toIntBetween(min: number, max: number, val: any): number;
export declare function toIntBetweenOptional(min: number | undefined, max: number | undefined, val: any): number;
export declare function toIntMax(max: number, val: any): number;
export declare function toIntMin(min: number, val: any): number;
export declare function toString(val: any): string;
export declare function toStringArray(input: any[]): string[];
export declare function toStringArrayMax(max: number, input: any[]): string[];
export declare function toStringMax(max: number, val: any): string;
export declare function unzip<T>(dictionary: Dictionary<T>): {
keys: string[];
values: T[];
};
/**
* If keys/values have different lengths the expect behavior is to "underflow"
* values. Non values will be initialized to undefined. Non keys will be
* ignored.
*
* If there are duplicate keys the last assignment "wins", this would be the
* key with the highest index in the given keys array
*/
export declare function zip<T>(keys: string[], values: T[]): Dictionary<T>;