UNPKG

3.26 kBTypeScriptView Raw
1/**
2 * This method returns `undefined`.
3 */
4export declare function noop(): undefined;
5/**
6 * This method returns `false`.
7 */
8export declare function never(): false;
9/**
10 * This method returns `true`.
11 */
12export declare function always(): true;
13/**
14 * This method returns the first argument it receives.
15 *
16 * @typeparam T type of `value`
17 * @param value to return
18 */
19export declare function identity<T>(value: T): T;
20/**
21 * Creates a function that returns `value`.
22 *
23 * @typeparam T type of `value`
24 * @param value to return
25 */
26export declare function constant<T>(value: T): () => T;
27/**
28 * Checks `value` to determine whether a default value should be returned in its place.
29 *
30 * The `defaultValue` is returned if `value` is `NaN`, `null`, or `undefined`.
31 *
32 * @param value to check
33 * @param defaultValue to use
34 */
35export declare function defaultTo<T, TDefault = T>(value: T | null | undefined, defaultValue: TDefault): Exclude<T, null | undefined> | TDefault;
36/**
37 * Computes `number` rounded to `precision`.
38 * @param number to round
39 * @param precision to round to should be between `0` and `11`
40 * @returns the rounded number.
41 */
42export declare function roundTo(number: number, precision?: number): number;
43/**
44 * Clamps `number` within the inclusive `lower` and `upper` bounds.
45 *
46 * **Note**: If any argument is `NaN`, `NaN` is returned.
47 *
48 * @param number to clamp
49 * @param lower The lower bound.
50 * @param upper The upper bound.
51 */
52export declare function clamp(number: number, lower: number, upper: number): number;
53/**
54 * Throws the given `error`.
55 * @param error to throw
56 */
57export declare function fail(error: Error): never;
58/**
59 * Gets the first element of `array`.
60 * @param array to query
61 */
62export declare function first<T>(array: T[] | unknown): T | undefined;
63/**
64 * Gets the last element of `array`.
65 * @param array to query
66 */
67export declare function last<T>(array: T[] | unknown): T | undefined;
68/**
69 * Casts `value` as an array if it's not one.
70 *
71 * ```js
72 * castArray(1);
73 * // => [1]
74 *
75 * castArray({ 'a': 1 });
76 * // => [{ 'a': 1 }]
77 *
78 * castArray('abc');
79 * // => ['abc']
80 *
81 * castArray(null);
82 * // => [null]
83 *
84 * castArray(undefined);
85 * // => []
86 *
87 * castArray([]);
88 * // => []
89
90 * castArray([1]);
91 * // => [1]
92 * ```
93 * @param value to inspect
94 */
95export declare function castArray<T>(value?: T[] | T | undefined): T extends (infer V)[] ? V[] : T extends undefined ? any[] : T[];
96/**
97 * Invokes `array.push(value)` and returns `value`.
98 *
99 * @param array to modify
100 * @param value to push into `array`
101 */
102export declare function push<V, T extends V = V>(array: {
103 push(value: V): void;
104}, value: T): T;
105/**
106 * Invokes `set.add(value)` and returns `value`.
107 *
108 * @param set to modify
109 * @param value to add to `set`
110 */
111export declare function add<V, T extends V = V>(set: {
112 add(value: V): void;
113}, value: T): T;
114/**
115 * Invokes `map.set(key, value)` and returns `value`.
116 *
117 * @param map to modify
118 * @param key to set in `map`
119 * @param value to set in `map`
120 */
121export declare function set<K, V, T extends V = V>(map: {
122 set(key: K, value: V): void;
123}, key: K, value: T): T;