zakir-core 0.1.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 +7 -0
- package/dist/array.d.ts +2 -0
- package/dist/array.js +10 -0
- package/dist/function.d.ts +2 -0
- package/dist/function.js +17 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +6 -0
- package/dist/number.d.ts +2 -0
- package/dist/number.js +6 -0
- package/dist/object.d.ts +3 -0
- package/dist/object.js +32 -0
- package/dist/string.d.ts +2 -0
- package/dist/string.js +8 -0
- package/dist/test.d.ts +1 -0
- package/dist/test.js +16 -0
- package/dist/time.d.ts +1 -0
- package/dist/time.js +3 -0
- package/package.json +25 -0
package/README.md
ADDED
package/dist/array.d.ts
ADDED
package/dist/array.js
ADDED
package/dist/function.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export function debounce(fn, delay = 300) {
|
|
2
|
+
let timer;
|
|
3
|
+
return (...args) => {
|
|
4
|
+
clearTimeout(timer);
|
|
5
|
+
timer = setTimeout(() => fn(...args), delay);
|
|
6
|
+
};
|
|
7
|
+
}
|
|
8
|
+
export function throttle(fn, delay = 300) {
|
|
9
|
+
let last = 0;
|
|
10
|
+
return (...args) => {
|
|
11
|
+
const now = Date.now();
|
|
12
|
+
if (now - last >= delay) {
|
|
13
|
+
last = now;
|
|
14
|
+
fn(...args);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
package/dist/number.d.ts
ADDED
package/dist/number.js
ADDED
package/dist/object.d.ts
ADDED
package/dist/object.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export function deepClone(value) {
|
|
2
|
+
if (value === null || typeof value !== "object")
|
|
3
|
+
return value;
|
|
4
|
+
if (Array.isArray(value)) {
|
|
5
|
+
return value.map(deepClone);
|
|
6
|
+
}
|
|
7
|
+
const result = {};
|
|
8
|
+
for (const key in value) {
|
|
9
|
+
result[key] = deepClone(value[key]);
|
|
10
|
+
}
|
|
11
|
+
return result;
|
|
12
|
+
}
|
|
13
|
+
export function isEmpty(value) {
|
|
14
|
+
if (value == null)
|
|
15
|
+
return true;
|
|
16
|
+
if (Array.isArray(value) || typeof value === "string")
|
|
17
|
+
return value.length === 0;
|
|
18
|
+
if (typeof value === "object")
|
|
19
|
+
return Object.keys(value).length === 0;
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
export function merge(target, source) {
|
|
23
|
+
const result = { ...target };
|
|
24
|
+
for (const key in source) {
|
|
25
|
+
const val = source[key];
|
|
26
|
+
result[key] =
|
|
27
|
+
typeof val === "object" && !Array.isArray(val)
|
|
28
|
+
? merge(target[key] || {}, val)
|
|
29
|
+
: val;
|
|
30
|
+
}
|
|
31
|
+
return result;
|
|
32
|
+
}
|
package/dist/string.d.ts
ADDED
package/dist/string.js
ADDED
package/dist/test.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/test.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { deepClone, isEmpty, merge } from "./index";
|
|
2
|
+
// deepClone
|
|
3
|
+
const original = { a: 1, b: { c: 2 } };
|
|
4
|
+
const cloned = deepClone(original);
|
|
5
|
+
cloned.b.c = 99;
|
|
6
|
+
console.log(original.b.c); // 2
|
|
7
|
+
console.log(cloned.b.c); // 99
|
|
8
|
+
// isEmpty
|
|
9
|
+
console.log(isEmpty([])); // true
|
|
10
|
+
console.log(isEmpty({})); // true
|
|
11
|
+
console.log(isEmpty("")); // true
|
|
12
|
+
console.log(isEmpty(null)); // true
|
|
13
|
+
console.log(isEmpty({ a: 1 })); // false
|
|
14
|
+
// merge
|
|
15
|
+
const merged = merge({ a: 1, b: { c: 2 } }, { b: { d: 3 } });
|
|
16
|
+
console.log(merged);
|
package/dist/time.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function sleep(ms: number): Promise<void>;
|
package/dist/time.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "zakir-core",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Core utility functions – zero dependency",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
11
|
+
"scripts": {
|
|
12
|
+
"build": "tsc",
|
|
13
|
+
"clean": "rm -rf dist"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"utils",
|
|
17
|
+
"core",
|
|
18
|
+
"vanilla-js"
|
|
19
|
+
],
|
|
20
|
+
"author": "Zakir",
|
|
21
|
+
"license": "MIT",
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"typescript": "^5.9.3"
|
|
24
|
+
}
|
|
25
|
+
}
|