@varlet/shared 2.11.3-alpha.1685462737961 → 2.11.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.d.ts +2 -0
- package/lib/index.js +2 -0
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -19,3 +19,5 @@ export declare const camelize: (s: string) => string;
|
|
|
19
19
|
export declare const kebabCase: (s: string) => string;
|
|
20
20
|
export declare const find: <T>(arr: T[], callback: (item: T, index: number, array: T[]) => any, from?: 'start' | 'end') => [T, number] | [null, -1];
|
|
21
21
|
export declare const normalizeToArray: <T>(value: T | T[]) => T[];
|
|
22
|
+
export declare const clamp: (num: number, min: number, max: number) => number;
|
|
23
|
+
export declare const clampArrayRange: (index: number, arr: Array<unknown>) => number;
|
package/lib/index.js
CHANGED
|
@@ -80,3 +80,5 @@ export const find = (arr, callback, from = 'start') => {
|
|
|
80
80
|
return [null, -1];
|
|
81
81
|
};
|
|
82
82
|
export const normalizeToArray = (value) => (isArray(value) ? value : [value]);
|
|
83
|
+
export const clamp = (num, min, max) => Math.min(max, Math.max(min, num));
|
|
84
|
+
export const clampArrayRange = (index, arr) => clamp(index, 0, arr.length - 1);
|