-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelpers.core.d.ts
More file actions
147 lines (147 loc) · 6.97 KB
/
helpers.core.d.ts
File metadata and controls
147 lines (147 loc) · 6.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/**
* @namespace Chart.helpers
*/
import type { AnyObject } from '../types/basic.js';
import type { ActiveDataPoint, ChartEvent } from '../types/index.js';
/**
* An empty function that can be used, for example, for optional callback.
*/
export declare function noop(): void;
/**
* Returns a unique id, sequentially generated from a global variable.
*/
export declare const uid: () => number;
/**
* Returns true if `value` is neither null nor undefined, else returns false.
* @param value - The value to test.
* @since 2.7.0
*/
export declare function isNullOrUndef(value: unknown): value is null | undefined;
/**
* Returns true if `value` is an array (including typed arrays), else returns false.
* @param value - The value to test.
* @function
*/
export declare function isArray<T = unknown>(value: unknown): value is T[];
/**
* Returns true if `value` is an object (excluding null), else returns false.
* @param value - The value to test.
* @since 2.7.0
*/
export declare function isObject(value: unknown): value is AnyObject;
/**
* Returns true if `value` is a finite number, else returns false
* @param value - The value to test.
*/
declare function isNumberFinite(value: unknown): value is number;
export { isNumberFinite as isFinite, };
/**
* Returns `value` if finite, else returns `defaultValue`.
* @param value - The value to return if defined.
* @param defaultValue - The value to return if `value` is not finite.
*/
export declare function finiteOrDefault(value: unknown, defaultValue: number): number;
/**
* Returns `value` if defined, else returns `defaultValue`.
* @param value - The value to return if defined.
* @param defaultValue - The value to return if `value` is undefined.
*/
export declare function valueOrDefault<T>(value: T | undefined, defaultValue: T): T;
export declare const toPercentage: (value: number | string, dimension: number) => number;
export declare const toDimension: (value: number | string, dimension: number) => number;
/**
* Calls `fn` with the given `args` in the scope defined by `thisArg` and returns the
* value returned by `fn`. If `fn` is not a function, this method returns undefined.
* @param fn - The function to call.
* @param args - The arguments with which `fn` should be called.
* @param [thisArg] - The value of `this` provided for the call to `fn`.
*/
export declare function callback<T extends (this: TA, ...restArgs: unknown[]) => R, TA, R>(fn: T | undefined, args: unknown[], thisArg?: TA): R | undefined;
/**
* Note(SB) for performance sake, this method should only be used when loopable type
* is unknown or in none intensive code (not called often and small loopable). Else
* it's preferable to use a regular for() loop and save extra function calls.
* @param loopable - The object or array to be iterated.
* @param fn - The function to call for each item.
* @param [thisArg] - The value of `this` provided for the call to `fn`.
* @param [reverse] - If true, iterates backward on the loopable.
*/
export declare function each<T, TA>(loopable: Record<string, T>, fn: (this: TA, v: T, i: string) => void, thisArg?: TA, reverse?: boolean): void;
export declare function each<T, TA>(loopable: T[], fn: (this: TA, v: T, i: number) => void, thisArg?: TA, reverse?: boolean): void;
/**
* Returns true if the `a0` and `a1` arrays have the same content, else returns false.
* @param a0 - The array to compare
* @param a1 - The array to compare
* @private
*/
export declare function _elementsEqual(a0: ActiveDataPoint[], a1: ActiveDataPoint[]): boolean;
/**
* Returns a deep copy of `source` without keeping references on objects and arrays.
* @param source - The value to clone.
*/
export declare function clone<T>(source: T): T;
/**
* The default merger when Chart.helpers.merge is called without merger option.
* Note(SB): also used by mergeConfig and mergeScaleConfig as fallback.
* @private
*/
export declare function _merger(key: string, target: AnyObject, source: AnyObject, options: AnyObject): void;
export interface MergeOptions {
merger?: (key: string, target: AnyObject, source: AnyObject, options?: AnyObject) => void;
}
/**
* Recursively deep copies `source` properties into `target` with the given `options`.
* IMPORTANT: `target` is not cloned and will be updated with `source` properties.
* @param target - The target object in which all sources are merged into.
* @param source - Object(s) to merge into `target`.
* @param [options] - Merging options:
* @param [options.merger] - The merge method (key, target, source, options)
* @returns The `target` object.
*/
export declare function merge<T>(target: T, source: [], options?: MergeOptions): T;
export declare function merge<T, S1>(target: T, source: S1, options?: MergeOptions): T & S1;
export declare function merge<T, S1>(target: T, source: [S1], options?: MergeOptions): T & S1;
export declare function merge<T, S1, S2>(target: T, source: [S1, S2], options?: MergeOptions): T & S1 & S2;
export declare function merge<T, S1, S2, S3>(target: T, source: [S1, S2, S3], options?: MergeOptions): T & S1 & S2 & S3;
export declare function merge<T, S1, S2, S3, S4>(target: T, source: [S1, S2, S3, S4], options?: MergeOptions): T & S1 & S2 & S3 & S4;
export declare function merge<T>(target: T, source: AnyObject[], options?: MergeOptions): AnyObject;
/**
* Recursively deep copies `source` properties into `target` *only* if not defined in target.
* IMPORTANT: `target` is not cloned and will be updated with `source` properties.
* @param target - The target object in which all sources are merged into.
* @param source - Object(s) to merge into `target`.
* @returns The `target` object.
*/
export declare function mergeIf<T>(target: T, source: []): T;
export declare function mergeIf<T, S1>(target: T, source: S1): T & S1;
export declare function mergeIf<T, S1>(target: T, source: [S1]): T & S1;
export declare function mergeIf<T, S1, S2>(target: T, source: [S1, S2]): T & S1 & S2;
export declare function mergeIf<T, S1, S2, S3>(target: T, source: [S1, S2, S3]): T & S1 & S2 & S3;
export declare function mergeIf<T, S1, S2, S3, S4>(target: T, source: [S1, S2, S3, S4]): T & S1 & S2 & S3 & S4;
export declare function mergeIf<T>(target: T, source: AnyObject[]): AnyObject;
/**
* Merges source[key] in target[key] only if target[key] is undefined.
* @private
*/
export declare function _mergerIf(key: string, target: AnyObject, source: AnyObject): void;
/**
* @private
*/
export declare function _deprecated(scope: string, value: unknown, previous: string, current: string): void;
/**
* @private
*/
export declare function _splitKey(key: string): string[];
export declare function resolveObjectKey(obj: AnyObject, key: string): any;
/**
* @private
*/
export declare function _capitalize(str: string): string;
export declare const defined: (value: unknown) => boolean;
export declare const isFunction: (value: unknown) => value is (...args: any[]) => any;
export declare const setsEqual: <T>(a: Set<T>, b: Set<T>) => boolean;
/**
* @param e - The event
* @private
*/
export declare function _isClickEvent(e: ChartEvent): boolean;