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