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 ADDED
@@ -0,0 +1,7 @@
1
+ # @zakir/core
2
+
3
+ Zero-dependency core utility library.
4
+
5
+ ## Install
6
+ ```bash
7
+ npm i @zakir/core
@@ -0,0 +1,2 @@
1
+ export declare function unique<T>(arr: T[]): T[];
2
+ export declare function chunk<T>(arr: T[], size: number): T[][];
package/dist/array.js ADDED
@@ -0,0 +1,10 @@
1
+ export function unique(arr) {
2
+ return Array.from(new Set(arr));
3
+ }
4
+ export function chunk(arr, size) {
5
+ const res = [];
6
+ for (let i = 0; i < arr.length; i += size) {
7
+ res.push(arr.slice(i, i + size));
8
+ }
9
+ return res;
10
+ }
@@ -0,0 +1,2 @@
1
+ export declare function debounce<T extends (...args: any[]) => void>(fn: T, delay?: number): (...args: Parameters<T>) => void;
2
+ export declare function throttle<T extends (...args: any[]) => void>(fn: T, delay?: number): (...args: Parameters<T>) => void;
@@ -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
+ }
@@ -0,0 +1,6 @@
1
+ export * from "./object";
2
+ export * from "./function";
3
+ export * from "./string";
4
+ export * from "./number";
5
+ export * from "./time";
6
+ export * from "./array";
package/dist/index.js ADDED
@@ -0,0 +1,6 @@
1
+ export * from "./object";
2
+ export * from "./function";
3
+ export * from "./string";
4
+ export * from "./number";
5
+ export * from "./time";
6
+ export * from "./array";
@@ -0,0 +1,2 @@
1
+ export declare function clamp(value: number, min: number, max: number): number;
2
+ export declare function random(min?: number, max?: number): number;
package/dist/number.js ADDED
@@ -0,0 +1,6 @@
1
+ export function clamp(value, min, max) {
2
+ return Math.min(Math.max(value, min), max);
3
+ }
4
+ export function random(min = 0, max = 1) {
5
+ return Math.random() * (max - min) + min;
6
+ }
@@ -0,0 +1,3 @@
1
+ export declare function deepClone<T>(value: T): T;
2
+ export declare function isEmpty(value: any): boolean;
3
+ export declare function merge<T extends object, U extends object>(target: T, source: U): T & U;
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
+ }
@@ -0,0 +1,2 @@
1
+ export declare function uuid(): string;
2
+ export declare function capitalize(str: string): string;
package/dist/string.js ADDED
@@ -0,0 +1,8 @@
1
+ export function uuid() {
2
+ return crypto.randomUUID();
3
+ }
4
+ export function capitalize(str) {
5
+ if (!str)
6
+ return str;
7
+ return str[0].toUpperCase() + str.slice(1);
8
+ }
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
@@ -0,0 +1,3 @@
1
+ export function sleep(ms) {
2
+ return new Promise(resolve => setTimeout(resolve, ms));
3
+ }
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
+ }