dozy 1.0.0
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/README.md +3 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +45 -0
- package/package.json +30 -0
package/README.md
ADDED
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare function isObject(value: unknown): value is Record<string, unknown>;
|
|
2
|
+
export declare function deepClone<T>(value: T): T;
|
|
3
|
+
export declare function debounce<T extends (...args: any[]) => any>(fn: T, wait?: number): (...args: Parameters<T>) => void;
|
|
4
|
+
export declare function throttle<T extends (...args: any[]) => any>(fn: T, limit?: number): (...args: Parameters<T>) => void;
|
|
5
|
+
export declare function capitalize(s: string): string;
|
|
6
|
+
export declare function clamp(n: number, min: number, max: number): number;
|
|
7
|
+
declare const _default: {
|
|
8
|
+
isObject: typeof isObject;
|
|
9
|
+
deepClone: typeof deepClone;
|
|
10
|
+
debounce: typeof debounce;
|
|
11
|
+
throttle: typeof throttle;
|
|
12
|
+
capitalize: typeof capitalize;
|
|
13
|
+
clamp: typeof clamp;
|
|
14
|
+
};
|
|
15
|
+
export default _default;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// Common utility functions to publish in the `dozy` package
|
|
2
|
+
export function isObject(value) {
|
|
3
|
+
return value !== null && typeof value === 'object';
|
|
4
|
+
}
|
|
5
|
+
export function deepClone(value) {
|
|
6
|
+
if (typeof structuredClone === 'function') {
|
|
7
|
+
// @ts-ignore -- structuredClone exists in modern runtimes
|
|
8
|
+
return structuredClone(value);
|
|
9
|
+
}
|
|
10
|
+
return JSON.parse(JSON.stringify(value));
|
|
11
|
+
}
|
|
12
|
+
export function debounce(fn, wait = 200) {
|
|
13
|
+
let timer = null;
|
|
14
|
+
return function (...args) {
|
|
15
|
+
if (timer)
|
|
16
|
+
clearTimeout(timer);
|
|
17
|
+
timer = setTimeout(() => fn(...args), wait);
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export function throttle(fn, limit = 200) {
|
|
21
|
+
let inThrottle = false;
|
|
22
|
+
return function (...args) {
|
|
23
|
+
if (!inThrottle) {
|
|
24
|
+
fn(...args);
|
|
25
|
+
inThrottle = true;
|
|
26
|
+
setTimeout(() => (inThrottle = false), limit);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
export function capitalize(s) {
|
|
31
|
+
if (!s)
|
|
32
|
+
return s;
|
|
33
|
+
return s.charAt(0).toUpperCase() + s.slice(1);
|
|
34
|
+
}
|
|
35
|
+
export function clamp(n, min, max) {
|
|
36
|
+
return Math.min(max, Math.max(min, n));
|
|
37
|
+
}
|
|
38
|
+
export default {
|
|
39
|
+
isObject,
|
|
40
|
+
deepClone,
|
|
41
|
+
debounce,
|
|
42
|
+
throttle,
|
|
43
|
+
capitalize,
|
|
44
|
+
clamp,
|
|
45
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "dozy",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "My shared typescript utilities.",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts"
|
|
12
|
+
},
|
|
13
|
+
"./package.json": "./package.json"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"README.md"
|
|
18
|
+
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"clean": "rimraf dist || rmdir /s /q dist",
|
|
21
|
+
"build": "npm run clean&tsc -p tsconfig.json",
|
|
22
|
+
"prepare": "npm run build"
|
|
23
|
+
},
|
|
24
|
+
"author": "xaidozy",
|
|
25
|
+
"license": "ISC",
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"typescript": "^5.4.2",
|
|
28
|
+
"rimraf": "^5.0.0"
|
|
29
|
+
}
|
|
30
|
+
}
|