superjs-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.
@@ -0,0 +1,272 @@
1
+ // src/core/index.ts
2
+ function isPlainObject(value) {
3
+ if (value === null || typeof value !== "object") return false;
4
+ const proto = Object.getPrototypeOf(value);
5
+ return proto === Object.prototype || proto === null;
6
+ }
7
+ function getType(value) {
8
+ return Object.prototype.toString.call(value);
9
+ }
10
+ function clone(value, seen) {
11
+ if (value === null || typeof value !== "object") return value;
12
+ if (seen.has(value)) return seen.get(value);
13
+ const tag = getType(value);
14
+ if (tag === "[object Date]") {
15
+ const cloned = new Date(value.getTime());
16
+ seen.set(value, cloned);
17
+ return cloned;
18
+ }
19
+ if (tag === "[object RegExp]") {
20
+ const regExp = value;
21
+ const cloned = new RegExp(regExp.source, regExp.flags);
22
+ cloned.lastIndex = regExp.lastIndex;
23
+ seen.set(value, cloned);
24
+ return cloned;
25
+ }
26
+ if (tag === "[object Map]") {
27
+ const cloned = /* @__PURE__ */ new Map();
28
+ seen.set(value, cloned);
29
+ value.forEach((v, k) => {
30
+ cloned.set(clone(k, seen), clone(v, seen));
31
+ });
32
+ return cloned;
33
+ }
34
+ if (tag === "[object Set]") {
35
+ const cloned = /* @__PURE__ */ new Set();
36
+ seen.set(value, cloned);
37
+ value.forEach((v) => {
38
+ cloned.add(clone(v, seen));
39
+ });
40
+ return cloned;
41
+ }
42
+ if (Array.isArray(value)) {
43
+ const cloned = [];
44
+ seen.set(value, cloned);
45
+ for (let i = 0; i < value.length; i++) {
46
+ cloned[i] = clone(value[i], seen);
47
+ }
48
+ return cloned;
49
+ }
50
+ if (tag === "[object Object]") {
51
+ const cloned = {};
52
+ seen.set(value, cloned);
53
+ const keys = Object.keys(value);
54
+ for (let i = 0; i < keys.length; i++) {
55
+ const key = keys[i];
56
+ cloned[key] = clone(value[key], seen);
57
+ }
58
+ return cloned;
59
+ }
60
+ return value;
61
+ }
62
+ function deepClone(value) {
63
+ const seen = /* @__PURE__ */ new WeakMap();
64
+ return clone(value, seen);
65
+ }
66
+ function deepMerge(...objects) {
67
+ const result = {};
68
+ for (let i = 0; i < objects.length; i++) {
69
+ const obj = objects[i];
70
+ if (obj === null || obj === void 0) continue;
71
+ const keys = Object.keys(obj);
72
+ for (let j = 0; j < keys.length; j++) {
73
+ const key = keys[j];
74
+ const val = obj[key];
75
+ const existing = result[key];
76
+ if (val !== void 0 && isPlainObject(val) && isPlainObject(existing)) {
77
+ result[key] = deepMerge(
78
+ existing,
79
+ val
80
+ );
81
+ } else if (val !== void 0) {
82
+ result[key] = val;
83
+ }
84
+ }
85
+ }
86
+ return result;
87
+ }
88
+ function debounce(fn, wait, options) {
89
+ const { leading = false, trailing = true, maxWait } = options ?? {};
90
+ let timer = null;
91
+ let maxTimer = null;
92
+ let lastArgs = null;
93
+ let lastCallTime = null;
94
+ let lastInvokeTime = 0;
95
+ function invoke(time) {
96
+ lastInvokeTime = time;
97
+ if (lastArgs) {
98
+ fn(...lastArgs);
99
+ lastArgs = null;
100
+ }
101
+ }
102
+ function startTimer(waitTime) {
103
+ if (timer) clearTimeout(timer);
104
+ timer = setTimeout(() => {
105
+ const now = Date.now();
106
+ if (lastArgs && trailing) {
107
+ invoke(now);
108
+ }
109
+ timer = null;
110
+ lastCallTime = null;
111
+ }, waitTime);
112
+ }
113
+ function startMaxTimer() {
114
+ if (maxWait === void 0 || maxTimer) return;
115
+ maxTimer = setTimeout(() => {
116
+ if (lastArgs) {
117
+ invoke(Date.now());
118
+ if (timer) {
119
+ clearTimeout(timer);
120
+ timer = null;
121
+ }
122
+ lastCallTime = null;
123
+ }
124
+ }, maxWait);
125
+ }
126
+ function clearAllTimers() {
127
+ if (timer) {
128
+ clearTimeout(timer);
129
+ timer = null;
130
+ }
131
+ if (maxTimer) {
132
+ clearTimeout(maxTimer);
133
+ maxTimer = null;
134
+ }
135
+ }
136
+ function shouldInvoke(time) {
137
+ if (lastCallTime === null) return true;
138
+ const timeSinceLastCall = time - lastCallTime;
139
+ const timeSinceLastInvoke = time - lastInvokeTime;
140
+ return timeSinceLastCall >= wait || maxWait !== void 0 && timeSinceLastInvoke >= maxWait;
141
+ }
142
+ const debounced = function(...args) {
143
+ const time = Date.now();
144
+ const isInvoking = shouldInvoke(time);
145
+ lastArgs = args;
146
+ lastCallTime = time;
147
+ if (isInvoking && !timer && leading) {
148
+ invoke(time);
149
+ }
150
+ if (!timer) {
151
+ startTimer(wait);
152
+ if (maxWait !== void 0) {
153
+ startMaxTimer();
154
+ }
155
+ }
156
+ };
157
+ debounced.cancel = () => {
158
+ clearAllTimers();
159
+ lastArgs = null;
160
+ lastCallTime = null;
161
+ lastInvokeTime = 0;
162
+ };
163
+ debounced.flush = () => {
164
+ if (timer && lastArgs) {
165
+ invoke(Date.now());
166
+ clearAllTimers();
167
+ lastCallTime = null;
168
+ }
169
+ };
170
+ return debounced;
171
+ }
172
+ function throttle(fn, wait) {
173
+ let lastTime = 0;
174
+ let timer = null;
175
+ let lastArgs = null;
176
+ const throttled = function(...args) {
177
+ const now = Date.now();
178
+ const remaining = wait - (now - lastTime);
179
+ if (remaining <= 0) {
180
+ if (timer) {
181
+ clearTimeout(timer);
182
+ timer = null;
183
+ }
184
+ lastTime = now;
185
+ lastArgs = null;
186
+ fn.apply(this, args);
187
+ } else {
188
+ lastArgs = args;
189
+ if (!timer) {
190
+ timer = setTimeout(() => {
191
+ lastTime = Date.now();
192
+ timer = null;
193
+ if (lastArgs) {
194
+ fn.apply(this, lastArgs);
195
+ lastArgs = null;
196
+ }
197
+ }, remaining);
198
+ }
199
+ }
200
+ };
201
+ return throttled;
202
+ }
203
+ function memoize(fn, resolver) {
204
+ const cache = /* @__PURE__ */ new Map();
205
+ const memoized = function(...args) {
206
+ const key = resolver ? resolver(...args) : String(args[0]);
207
+ if (cache.has(key)) {
208
+ return cache.get(key);
209
+ }
210
+ const result = fn.apply(this, args);
211
+ cache.set(key, result);
212
+ return result;
213
+ };
214
+ memoized.cache = cache;
215
+ return memoized;
216
+ }
217
+ function retry(fn, options) {
218
+ const {
219
+ attempts = 3,
220
+ baseDelay = 1e3,
221
+ maxDelay = 3e4,
222
+ shouldRetry = () => true
223
+ } = options ?? {};
224
+ let attempt = 0;
225
+ const execute = () => {
226
+ attempt++;
227
+ return fn().catch((error) => {
228
+ if (attempt >= attempts || !shouldRetry(error)) {
229
+ throw error;
230
+ }
231
+ const delay = Math.min(
232
+ baseDelay * Math.pow(2, attempt - 1) + Math.random() * baseDelay,
233
+ maxDelay
234
+ );
235
+ return new Promise((resolve) => {
236
+ setTimeout(() => {
237
+ resolve(execute());
238
+ }, delay);
239
+ });
240
+ });
241
+ };
242
+ return execute();
243
+ }
244
+ function noop() {
245
+ return void 0;
246
+ }
247
+ function identity(value) {
248
+ return value;
249
+ }
250
+ function once(fn) {
251
+ let called = false;
252
+ let result;
253
+ return function(...args) {
254
+ if (!called) {
255
+ called = true;
256
+ result = fn.apply(this, args);
257
+ }
258
+ return result;
259
+ };
260
+ }
261
+ export {
262
+ debounce,
263
+ deepClone,
264
+ deepMerge,
265
+ identity,
266
+ memoize,
267
+ noop,
268
+ once,
269
+ retry,
270
+ throttle
271
+ };
272
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/core/index.ts"],"sourcesContent":["export interface DebounceOptions {\n leading?: boolean\n trailing?: boolean\n maxWait?: number\n}\n\nexport interface DebouncedFunction<T extends (...args: unknown[]) => unknown> {\n (...args: Parameters<T>): void\n cancel(): void\n flush(): void\n}\n\nexport interface MemoizedFunction<T extends (...args: unknown[]) => unknown> {\n (...args: Parameters<T>): ReturnType<T>\n cache: Map<string, ReturnType<T>>\n}\n\nexport interface RetryOptions {\n attempts?: number\n baseDelay?: number\n maxDelay?: number\n shouldRetry?: (error: unknown) => boolean\n}\n\nfunction isPlainObject(value: unknown): value is Record<string, unknown> {\n if (value === null || typeof value !== 'object') return false\n const proto = Object.getPrototypeOf(value)\n return proto === Object.prototype || proto === null\n}\n\nfunction getType(value: unknown): string {\n return Object.prototype.toString.call(value)\n}\n\nfunction clone<T>(value: T, seen: WeakMap<object, unknown>): T {\n if (value === null || typeof value !== 'object') return value\n\n if (seen.has(value as object)) return seen.get(value as object) as T\n\n const tag = getType(value)\n\n if (tag === '[object Date]') {\n const cloned = new Date((value as unknown as Date).getTime())\n seen.set(value as object, cloned)\n return cloned as unknown as T\n }\n\n if (tag === '[object RegExp]') {\n const regExp = value as unknown as RegExp\n const cloned = new RegExp(regExp.source, regExp.flags)\n cloned.lastIndex = regExp.lastIndex\n seen.set(value as object, cloned)\n return cloned as unknown as T\n }\n\n if (tag === '[object Map]') {\n const cloned = new Map<unknown, unknown>()\n seen.set(value as object, cloned)\n ;(value as unknown as Map<unknown, unknown>).forEach((v, k) => {\n cloned.set(clone(k, seen), clone(v, seen))\n })\n return cloned as unknown as T\n }\n\n if (tag === '[object Set]') {\n const cloned = new Set<unknown>()\n seen.set(value as object, cloned)\n ;(value as unknown as Set<unknown>).forEach(v => {\n cloned.add(clone(v, seen))\n })\n return cloned as unknown as T\n }\n\n if (Array.isArray(value)) {\n const cloned: unknown[] = []\n seen.set(value as object, cloned)\n for (let i = 0; i < value.length; i++) {\n cloned[i] = clone(value[i], seen)\n }\n return cloned as unknown as T\n }\n\n if (tag === '[object Object]') {\n const cloned: Record<string, unknown> = {}\n seen.set(value as object, cloned)\n const keys = Object.keys(value as Record<string, unknown>)\n for (let i = 0; i < keys.length; i++) {\n const key = keys[i]!\n cloned[key] = clone((value as Record<string, unknown>)[key], seen)\n }\n return cloned as unknown as T\n }\n\n return value\n}\n\n/**\n * Deep clone a value, supporting objects, arrays, Date, RegExp, Map, Set,\n * and cyclic references.\n *\n * @param value - The value to clone.\n * @returns A deep copy of the input value.\n */\nexport function deepClone<T>(value: T): T {\n const seen = new WeakMap<object, unknown>()\n return clone(value, seen)\n}\n\n/**\n * Deep merge multiple objects. Arrays are overwritten, not concatenated.\n * `null` and `undefined` source objects are skipped.\n *\n * @param objects - The objects to merge.\n * @returns A new object with merged properties.\n */\nexport function deepMerge<T extends Record<string, unknown>>(...objects: Partial<T>[]): T {\n const result = {} as T\n\n for (let i = 0; i < objects.length; i++) {\n const obj = objects[i]\n if (obj === null || obj === undefined) continue\n\n const keys = Object.keys(obj) as (keyof T)[]\n for (let j = 0; j < keys.length; j++) {\n const key = keys[j]!\n const val = obj[key]\n const existing = result[key]\n\n if (val !== undefined && isPlainObject(val) && isPlainObject(existing)) {\n result[key] = deepMerge(\n existing as Record<string, unknown>,\n val as Record<string, unknown>\n ) as T[keyof T]\n } else if (val !== undefined) {\n result[key] = val as T[keyof T]\n }\n }\n }\n\n return result\n}\n\n/**\n * Creates a debounced function that delays invoking `fn` until after `wait`\n * milliseconds have elapsed since the last invocation. Supports leading,\n * trailing, and maxWait options. The returned function also has `.cancel()`\n * and `.flush()` methods.\n *\n * @param fn - The function to debounce.\n * @param wait - The number of milliseconds to delay.\n * @param options - Optional configuration.\n * @returns A debounced function with `.cancel()` and `.flush()`.\n */\nexport function debounce<T extends (...args: unknown[]) => unknown>(\n fn: T,\n wait: number,\n options?: DebounceOptions\n): DebouncedFunction<T> {\n const { leading = false, trailing = true, maxWait } = options ?? {}\n\n let timer: ReturnType<typeof setTimeout> | null = null\n let maxTimer: ReturnType<typeof setTimeout> | null = null\n let lastArgs: Parameters<T> | null = null\n let lastCallTime: number | null = null\n let lastInvokeTime = 0\n\n function invoke(time: number): void {\n lastInvokeTime = time\n if (lastArgs) {\n fn(...lastArgs)\n lastArgs = null\n }\n }\n\n function startTimer(waitTime: number): void {\n if (timer) clearTimeout(timer)\n timer = setTimeout(() => {\n const now = Date.now()\n if (lastArgs && trailing) {\n invoke(now)\n }\n timer = null\n lastCallTime = null\n }, waitTime)\n }\n\n function startMaxTimer(): void {\n if (maxWait === undefined || maxTimer) return\n maxTimer = setTimeout(() => {\n if (lastArgs) {\n invoke(Date.now())\n if (timer) {\n clearTimeout(timer)\n timer = null\n }\n lastCallTime = null\n }\n }, maxWait)\n }\n\n function clearAllTimers(): void {\n if (timer) {\n clearTimeout(timer)\n timer = null\n }\n if (maxTimer) {\n clearTimeout(maxTimer)\n maxTimer = null\n }\n }\n\n function shouldInvoke(time: number): boolean {\n if (lastCallTime === null) return true\n const timeSinceLastCall = time - lastCallTime\n const timeSinceLastInvoke = time - lastInvokeTime\n return (\n timeSinceLastCall >= wait ||\n (maxWait !== undefined && timeSinceLastInvoke >= maxWait)\n )\n }\n\n const debounced = function (this: unknown, ...args: Parameters<T>): void {\n const time = Date.now()\n const isInvoking = shouldInvoke(time)\n\n lastArgs = args\n lastCallTime = time\n\n if (isInvoking && !timer && leading) {\n invoke(time)\n }\n\n if (!timer) {\n startTimer(wait)\n if (maxWait !== undefined) {\n startMaxTimer()\n }\n }\n } as DebouncedFunction<T>\n\n debounced.cancel = (): void => {\n clearAllTimers()\n lastArgs = null\n lastCallTime = null\n lastInvokeTime = 0\n }\n\n debounced.flush = (): void => {\n if (timer && lastArgs) {\n invoke(Date.now())\n clearAllTimers()\n lastCallTime = null\n }\n }\n\n return debounced\n}\n\n/**\n * Creates a throttled function that only invokes `fn` at most once per\n * `wait` milliseconds.\n *\n * @param fn - The function to throttle.\n * @param wait - The number of milliseconds to throttle invocations to.\n * @returns A throttled function.\n */\nexport function throttle<T extends (...args: unknown[]) => unknown>(\n fn: T,\n wait: number\n): (...args: Parameters<T>) => void {\n let lastTime = 0\n let timer: ReturnType<typeof setTimeout> | null = null\n let lastArgs: Parameters<T> | null = null\n\n const throttled = function (this: unknown, ...args: Parameters<T>): void {\n const now = Date.now()\n const remaining = wait - (now - lastTime)\n\n if (remaining <= 0) {\n if (timer) {\n clearTimeout(timer)\n timer = null\n }\n lastTime = now\n lastArgs = null\n fn.apply(this, args)\n } else {\n lastArgs = args\n if (!timer) {\n timer = setTimeout(() => {\n lastTime = Date.now()\n timer = null\n if (lastArgs) {\n fn.apply(this, lastArgs)\n lastArgs = null\n }\n }, remaining)\n }\n }\n }\n\n return throttled\n}\n\n/**\n * Creates a memoized version of `fn`. Uses a `Map` cache keyed by the\n * first argument by default, or by a custom `resolver` function.\n *\n * @param fn - The function to memoize.\n * @param resolver - Optional function to determine the cache key.\n * @returns The memoized function with a `.cache` property.\n */\nexport function memoize<T extends (...args: unknown[]) => unknown>(\n fn: T,\n resolver?: (...args: Parameters<T>) => string\n): MemoizedFunction<T> {\n const cache = new Map<string, ReturnType<T>>()\n\n const memoized = function (this: unknown, ...args: Parameters<T>): ReturnType<T> {\n const key = resolver ? resolver(...args) : String(args[0])\n if (cache.has(key)) {\n return cache.get(key) as ReturnType<T>\n }\n const result = fn.apply(this, args) as ReturnType<T>\n cache.set(key, result)\n return result\n }\n\n memoized.cache = cache\n\n return memoized as MemoizedFunction<T>\n}\n\n/**\n * Retries an async function with exponential backoff and jitter.\n *\n * @param fn - The async function to retry.\n * @param options - Retry configuration.\n * @returns A promise that resolves with the function result.\n */\nexport function retry<T>(\n fn: () => Promise<T>,\n options?: RetryOptions\n): Promise<T> {\n const {\n attempts = 3,\n baseDelay = 1000,\n maxDelay = 30000,\n shouldRetry = () => true,\n } = options ?? {}\n\n let attempt = 0\n\n const execute = (): Promise<T> => {\n attempt++\n return fn().catch((error: unknown) => {\n if (attempt >= attempts || !shouldRetry(error)) {\n throw error\n }\n\n const delay = Math.min(\n baseDelay * Math.pow(2, attempt - 1) + Math.random() * baseDelay,\n maxDelay\n )\n\n return new Promise<T>(resolve => {\n setTimeout(() => {\n resolve(execute())\n }, delay)\n })\n })\n }\n\n return execute()\n}\n\n/**\n * A no-operation function that returns `undefined`.\n */\nexport function noop(): void {\n return undefined\n}\n\n/**\n * Returns the given value unchanged.\n *\n * @param value - The value to return.\n * @returns The same value.\n */\nexport function identity<T>(value: T): T {\n return value\n}\n\n/**\n * Creates a function that invokes `fn` only once. Subsequent calls return\n * the result of the first invocation.\n *\n * @param fn - The function to wrap.\n * @returns A function that runs only once.\n */\nexport function once<T extends (...args: unknown[]) => unknown>(\n fn: T\n): (...args: Parameters<T>) => ReturnType<T> {\n let called = false\n let result: ReturnType<T>\n\n return function (this: unknown, ...args: Parameters<T>): ReturnType<T> {\n if (!called) {\n called = true\n result = fn.apply(this, args) as ReturnType<T>\n }\n return result\n }\n}\n"],"mappings":";AAwBA,SAAS,cAAc,OAAkD;AACvE,MAAI,UAAU,QAAQ,OAAO,UAAU,SAAU,QAAO;AACxD,QAAM,QAAQ,OAAO,eAAe,KAAK;AACzC,SAAO,UAAU,OAAO,aAAa,UAAU;AACjD;AAEA,SAAS,QAAQ,OAAwB;AACvC,SAAO,OAAO,UAAU,SAAS,KAAK,KAAK;AAC7C;AAEA,SAAS,MAAS,OAAU,MAAmC;AAC7D,MAAI,UAAU,QAAQ,OAAO,UAAU,SAAU,QAAO;AAExD,MAAI,KAAK,IAAI,KAAe,EAAG,QAAO,KAAK,IAAI,KAAe;AAE9D,QAAM,MAAM,QAAQ,KAAK;AAEzB,MAAI,QAAQ,iBAAiB;AAC3B,UAAM,SAAS,IAAI,KAAM,MAA0B,QAAQ,CAAC;AAC5D,SAAK,IAAI,OAAiB,MAAM;AAChC,WAAO;AAAA,EACT;AAEA,MAAI,QAAQ,mBAAmB;AAC7B,UAAM,SAAS;AACf,UAAM,SAAS,IAAI,OAAO,OAAO,QAAQ,OAAO,KAAK;AACrD,WAAO,YAAY,OAAO;AAC1B,SAAK,IAAI,OAAiB,MAAM;AAChC,WAAO;AAAA,EACT;AAEA,MAAI,QAAQ,gBAAgB;AAC1B,UAAM,SAAS,oBAAI,IAAsB;AACzC,SAAK,IAAI,OAAiB,MAAM;AAC/B,IAAC,MAA2C,QAAQ,CAAC,GAAG,MAAM;AAC7D,aAAO,IAAI,MAAM,GAAG,IAAI,GAAG,MAAM,GAAG,IAAI,CAAC;AAAA,IAC3C,CAAC;AACD,WAAO;AAAA,EACT;AAEA,MAAI,QAAQ,gBAAgB;AAC1B,UAAM,SAAS,oBAAI,IAAa;AAChC,SAAK,IAAI,OAAiB,MAAM;AAC/B,IA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C,CAAC;AACzD,QAAI,MAAM,IAAI,GAAG,GAAG;AAClB,aAAO,MAAM,IAAI,GAAG;AAAA,IACtB;AACA,UAAM,SAAS,GAAG,MAAM,MAAM,IAAI;AAClC,UAAM,IAAI,KAAK,MAAM;AACrB,WAAO;AAAA,EACT;AAEA,WAAS,QAAQ;AAEjB,SAAO;AACT;AASO,SAAS,MACd,IACA,SACY;AACZ,QAAM;AAAA,IACJ,WAAW;AAAA,IACX,YAAY;AAAA,IACZ,WAAW;AAAA,IACX,cAAc,MAAM;AAAA,EACtB,IAAI,WAAW,CAAC;AAEhB,MAAI,UAAU;AAEd,QAAM,UAAU,MAAkB;AAChC;AACA,WAAO,GAAG,EAAE,MAAM,CAAC,UAAmB;AACpC,UAAI,WAAW,YAAY,CAAC,YAAY,KAAK,GAAG;AAC9C,cAAM;AAAA,MACR;AAEA,YAAM,QAAQ,KAAK;AAAA,QACjB,YAAY,KAAK,IAAI,GAAG,UAAU,CAAC,IAAI,KAAK,OAAO,IAAI;AAAA,QACvD;AAAA,MACF;AAEA,aAAO,IAAI,QAAW,aAAW;AAC/B,mBAAW,MAAM;AACf,kBAAQ,QAAQ,CAAC;AAAA,QACnB,GAAG,KAAK;AAAA,MACV,CAAC;AAAA,IACH,CAAC;AAAA,EACH;AAEA,SAAO,QAAQ;AACjB;AAKO,SAAS,OAAa;AAC3B,SAAO;AACT;AAQO,SAAS,SAAY,OAAa;AACvC,SAAO;AACT;AASO,SAAS,KACd,IAC2C;AAC3C,MAAI,SAAS;AACb,MAAI;AAEJ,SAAO,YAA4B,MAAoC;AACrE,QAAI,CAAC,QAAQ;AACX,eAAS;AACT,eAAS,GAAG,MAAM,MAAM,IAAI;AAAA,IAC9B;AACA,WAAO;AAAA,EACT;AACF;","names":[]}
@@ -0,0 +1,78 @@
1
+ /**
2
+ * Simple hash function using the djb2 algorithm.
3
+ * Fast, non-cryptographic — suitable for hashtables, not security.
4
+ *
5
+ * @param str - The string to hash.
6
+ * @returns A 32-bit integer hash.
7
+ */
8
+ declare function hash(str: string): number;
9
+ /**
10
+ * Produces a deterministic hex hash from a string.
11
+ * NOT actual MD5 — use for cache keys / deterministic IDs.
12
+ *
13
+ * @param str - The string to hash.
14
+ * @returns A 32-character hex string.
15
+ */
16
+ declare function simpleHash(str: string): string;
17
+ /**
18
+ * Generates random bytes as a hex string.
19
+ *
20
+ * @param size - Number of random bytes (default 16).
21
+ * @returns A hex string of length `size * 2`.
22
+ */
23
+ declare function randomHex(size?: number): string;
24
+ /**
25
+ * Encodes a string to base64. Works in both Node.js and browser.
26
+ * Handles UTF-8 characters correctly.
27
+ *
28
+ * @param str - The string to encode.
29
+ * @returns The base64-encoded string.
30
+ */
31
+ declare function base64Encode(str: string): string;
32
+ /**
33
+ * Decodes a base64-encoded string. Works in both Node.js and browser.
34
+ *
35
+ * @param str - The base64 string to decode.
36
+ * @returns The decoded string.
37
+ */
38
+ declare function base64Decode(str: string): string;
39
+ /**
40
+ * Generates a cryptographically random token string.
41
+ *
42
+ * @param bytes - Number of random bytes (default 32 → 64-char hex).
43
+ * @returns A hex string suitable for API keys, reset tokens, etc.
44
+ */
45
+ declare function generateToken(bytes?: number): string;
46
+ /**
47
+ * Generates a numeric OTP of the given length.
48
+ *
49
+ * @param length - Number of digits (default 6).
50
+ * @returns A numeric string of the specified length.
51
+ */
52
+ declare function generateOTP(length?: number): string;
53
+ /**
54
+ * Simple XOR cipher — symmetrical, for light obfuscation only.
55
+ * NOT real encryption.
56
+ *
57
+ * @param str - The input string.
58
+ * @param key - The cipher key.
59
+ * @returns The XOR-transformed string.
60
+ */
61
+ declare function xorCipher(str: string, key: string): string;
62
+ /**
63
+ * Computes a simple checksum (CRC-like) for file integrity checks.
64
+ *
65
+ * @param input - The input string.
66
+ * @returns An 8-character hex checksum.
67
+ */
68
+ declare function checksum(input: string): string;
69
+ /**
70
+ * Constant-time string comparison to prevent timing attacks.
71
+ *
72
+ * @param a - First string.
73
+ * @param b - Second string.
74
+ * @returns Whether the strings are equal.
75
+ */
76
+ declare function constantTimeEqual(a: string, b: string): boolean;
77
+
78
+ export { base64Decode, base64Encode, checksum, constantTimeEqual, generateOTP, generateToken, hash, randomHex, simpleHash, xorCipher };
@@ -0,0 +1,147 @@
1
+ // src/crypto/index.ts
2
+ function hash(str) {
3
+ let h = 5381;
4
+ for (let i = 0; i < str.length; i++) {
5
+ h = (h << 5) + h + str.charCodeAt(i) | 0;
6
+ }
7
+ return h >>> 0;
8
+ }
9
+ function simpleHash(str) {
10
+ let h1 = 1732584193;
11
+ let h2 = 4023233417;
12
+ let h3 = 2562383102;
13
+ let h4 = 271733878;
14
+ for (let i = 0; i < str.length; i++) {
15
+ const c = str.charCodeAt(i);
16
+ h1 = h1 + c | 0;
17
+ h2 = h2 + (c << 3) + i | 0;
18
+ h3 = h3 ^ c | 0;
19
+ h4 = h4 + (c << 5) + (c << 1) | 0;
20
+ }
21
+ const toHex = (n) => (n >>> 0).toString(16).padStart(8, "0");
22
+ return toHex(h1) + toHex(h2) + toHex(h3) + toHex(h4);
23
+ }
24
+ function getRandomBytes(size) {
25
+ const bytes = new Uint8Array(size);
26
+ if (typeof crypto !== "undefined" && typeof crypto.getRandomValues === "function") {
27
+ crypto.getRandomValues(bytes);
28
+ } else {
29
+ for (let i = 0; i < size; i++) {
30
+ bytes[i] = Math.floor(Math.random() * 256);
31
+ }
32
+ }
33
+ return bytes;
34
+ }
35
+ function randomHex(size = 16) {
36
+ const bytes = getRandomBytes(size);
37
+ let result = "";
38
+ for (let i = 0; i < bytes.length; i++) {
39
+ result += bytes[i].toString(16).padStart(2, "0");
40
+ }
41
+ return result;
42
+ }
43
+ function utf8ToBytes(str) {
44
+ if (typeof TextEncoder !== "undefined") {
45
+ return new TextEncoder().encode(str);
46
+ }
47
+ const bytes = new Uint8Array(str.length);
48
+ for (let i = 0; i < str.length; i++) {
49
+ bytes[i] = str.charCodeAt(i);
50
+ }
51
+ return bytes;
52
+ }
53
+ function bytesToUtf8(bytes) {
54
+ if (typeof TextDecoder !== "undefined") {
55
+ return new TextDecoder().decode(bytes);
56
+ }
57
+ let result = "";
58
+ for (let i = 0; i < bytes.length; i++) {
59
+ result += String.fromCharCode(bytes[i]);
60
+ }
61
+ return result;
62
+ }
63
+ function bytesToBase64(bytes) {
64
+ let binary = "";
65
+ for (let i = 0; i < bytes.length; i++) {
66
+ binary += String.fromCharCode(bytes[i]);
67
+ }
68
+ if (typeof btoa === "function") {
69
+ return btoa(binary);
70
+ }
71
+ return Buffer.from(binary, "latin1").toString("base64");
72
+ }
73
+ function base64ToBytes(str) {
74
+ let binary;
75
+ if (typeof atob === "function") {
76
+ binary = atob(str);
77
+ } else {
78
+ binary = Buffer.from(str, "base64").toString("latin1");
79
+ }
80
+ const bytes = new Uint8Array(binary.length);
81
+ for (let i = 0; i < binary.length; i++) {
82
+ bytes[i] = binary.charCodeAt(i);
83
+ }
84
+ return bytes;
85
+ }
86
+ function base64Encode(str) {
87
+ const bytes = utf8ToBytes(str);
88
+ return bytesToBase64(bytes);
89
+ }
90
+ function base64Decode(str) {
91
+ const bytes = base64ToBytes(str);
92
+ return bytesToUtf8(bytes);
93
+ }
94
+ function generateToken(bytes = 32) {
95
+ return randomHex(bytes);
96
+ }
97
+ function generateOTP(length = 6) {
98
+ const bytes = getRandomBytes(length);
99
+ let otp = "";
100
+ for (let i = 0; i < length; i++) {
101
+ otp += (bytes[i] % 10).toString();
102
+ }
103
+ return otp;
104
+ }
105
+ function xorCipher(str, key) {
106
+ let result = "";
107
+ for (let i = 0; i < str.length; i++) {
108
+ const code = str.charCodeAt(i) ^ key.charCodeAt(i % key.length);
109
+ result += String.fromCharCode(code);
110
+ }
111
+ return result;
112
+ }
113
+ function checksum(input) {
114
+ let crc = 4294967295;
115
+ for (let i = 0; i < input.length; i++) {
116
+ crc ^= input.charCodeAt(i);
117
+ for (let j = 0; j < 8; j++) {
118
+ if (crc & 1) {
119
+ crc = crc >>> 1 ^ 3988292384;
120
+ } else {
121
+ crc = crc >>> 1;
122
+ }
123
+ }
124
+ }
125
+ return ((crc ^ 4294967295) >>> 0).toString(16).padStart(8, "0");
126
+ }
127
+ function constantTimeEqual(a, b) {
128
+ if (a.length !== b.length) return false;
129
+ let result = 0;
130
+ for (let i = 0; i < a.length; i++) {
131
+ result |= a.charCodeAt(i) ^ b.charCodeAt(i);
132
+ }
133
+ return result === 0;
134
+ }
135
+ export {
136
+ base64Decode,
137
+ base64Encode,
138
+ checksum,
139
+ constantTimeEqual,
140
+ generateOTP,
141
+ generateToken,
142
+ hash,
143
+ randomHex,
144
+ simpleHash,
145
+ xorCipher
146
+ };
147
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/crypto/index.ts"],"sourcesContent":["/**\n * Simple hash function using the djb2 algorithm.\n * Fast, non-cryptographic — suitable for hashtables, not security.\n *\n * @param str - The string to hash.\n * @returns A 32-bit integer hash.\n */\nexport function hash(str: string): number {\n let h = 5381\n for (let i = 0; i < str.length; i++) {\n h = ((h << 5) + h + str.charCodeAt(i)) | 0\n }\n return h >>> 0\n}\n\n/**\n * Produces a deterministic hex hash from a string.\n * NOT actual MD5 — use for cache keys / deterministic IDs.\n *\n * @param str - The string to hash.\n * @returns A 32-character hex string.\n */\nexport function simpleHash(str: string): string {\n let h1 = 0x67452301\n let h2 = 0xefcdab89\n let h3 = 0x98badcfe\n let h4 = 0x10325476\n\n for (let i = 0; i < str.length; i++) {\n const c = str.charCodeAt(i)\n h1 = (h1 + c) | 0\n h2 = (h2 + (c << 3) + i) | 0\n h3 = (h3 ^ c) | 0\n h4 = (h4 + (c << 5) + (c << 1)) | 0\n }\n\n const toHex = (n: number): string => (n >>> 0).toString(16).padStart(8, '0')\n return toHex(h1) + toHex(h2) + toHex(h3) + toHex(h4)\n}\n\nfunction getRandomBytes(size: number): Uint8Array {\n const bytes = new Uint8Array(size)\n if (typeof crypto !== 'undefined' && typeof crypto.getRandomValues === 'function') {\n crypto.getRandomValues(bytes)\n } else {\n for (let i = 0; i < size; i++) {\n bytes[i] = Math.floor(Math.random() * 256)\n }\n }\n return bytes\n}\n\n/**\n * Generates random bytes as a hex string.\n *\n * @param size - Number of random bytes (default 16).\n * @returns A hex string of length `size * 2`.\n */\nexport function randomHex(size: number = 16): string {\n const bytes = getRandomBytes(size)\n let result = ''\n for (let i = 0; i < bytes.length; i++) {\n result += bytes[i]!.toString(16).padStart(2, '0')\n }\n return result\n}\n\nfunction utf8ToBytes(str: string): Uint8Array {\n if (typeof TextEncoder !== 'undefined') {\n return new TextEncoder().encode(str)\n }\n const bytes = new Uint8Array(str.length)\n for (let i = 0; i < str.length; i++) {\n bytes[i] = str.charCodeAt(i)\n }\n return bytes\n}\n\nfunction bytesToUtf8(bytes: Uint8Array): string {\n if (typeof TextDecoder !== 'undefined') {\n return new TextDecoder().decode(bytes)\n }\n let result = ''\n for (let i = 0; i < bytes.length; i++) {\n result += String.fromCharCode(bytes[i]!)\n }\n return result\n}\n\nfunction bytesToBase64(bytes: Uint8Array): string {\n let binary = ''\n for (let i = 0; i < bytes.length; i++) {\n binary += String.fromCharCode(bytes[i]!)\n }\n if (typeof btoa === 'function') {\n return btoa(binary)\n }\n return Buffer.from(binary, 'latin1').toString('base64')\n}\n\nfunction base64ToBytes(str: string): Uint8Array {\n let binary: string\n if (typeof atob === 'function') {\n binary = atob(str)\n } else {\n binary = Buffer.from(str, 'base64').toString('latin1')\n }\n const bytes = new Uint8Array(binary.length)\n for (let i = 0; i < binary.length; i++) {\n bytes[i] = binary.charCodeAt(i)\n }\n return bytes\n}\n\n/**\n * Encodes a string to base64. Works in both Node.js and browser.\n * Handles UTF-8 characters correctly.\n *\n * @param str - The string to encode.\n * @returns The base64-encoded string.\n */\nexport function base64Encode(str: string): string {\n const bytes = utf8ToBytes(str)\n return bytesToBase64(bytes)\n}\n\n/**\n * Decodes a base64-encoded string. Works in both Node.js and browser.\n *\n * @param str - The base64 string to decode.\n * @returns The decoded string.\n */\nexport function base64Decode(str: string): string {\n const bytes = base64ToBytes(str)\n return bytesToUtf8(bytes)\n}\n\n/**\n * Generates a cryptographically random token string.\n *\n * @param bytes - Number of random bytes (default 32 → 64-char hex).\n * @returns A hex string suitable for API keys, reset tokens, etc.\n */\nexport function generateToken(bytes: number = 32): string {\n return randomHex(bytes)\n}\n\n/**\n * Generates a numeric OTP of the given length.\n *\n * @param length - Number of digits (default 6).\n * @returns A numeric string of the specified length.\n */\nexport function generateOTP(length: number = 6): string {\n const bytes = getRandomBytes(length)\n let otp = ''\n for (let i = 0; i < length; i++) {\n otp += (bytes[i]! % 10).toString()\n }\n return otp\n}\n\n/**\n * Simple XOR cipher — symmetrical, for light obfuscation only.\n * NOT real encryption.\n *\n * @param str - The input string.\n * @param key - The cipher key.\n * @returns The XOR-transformed string.\n */\nexport function xorCipher(str: string, key: string): string {\n let result = ''\n for (let i = 0; i < str.length; i++) {\n const code = str.charCodeAt(i) ^ key.charCodeAt(i % key.length)\n result += String.fromCharCode(code)\n }\n return result\n}\n\n/**\n * Computes a simple checksum (CRC-like) for file integrity checks.\n *\n * @param input - The input string.\n * @returns An 8-character hex checksum.\n */\nexport function checksum(input: string): string {\n let crc = 0xffffffff\n for (let i = 0; i < input.length; i++) {\n crc ^= input.charCodeAt(i)\n for (let j = 0; j < 8; j++) {\n if (crc & 1) {\n crc = (crc >>> 1) ^ 0xedb88320\n } else {\n crc = crc >>> 1\n }\n }\n }\n return ((crc ^ 0xffffffff) >>> 0).toString(16).padStart(8, '0')\n}\n\n/**\n * Constant-time string comparison to prevent timing attacks.\n *\n * @param a - First string.\n * @param b - Second string.\n * @returns Whether the strings are equal.\n */\nexport function constantTimeEqual(a: string, b: string): boolean {\n if (a.length !== b.length) return false\n let result = 0\n for (let i = 0; i < a.length; i++) {\n result |= a.charCodeAt(i) ^ b.charCodeAt(i)\n }\n return result === 0\n}\n"],"mappings":";AAOO,SAAS,KAAK,KAAqB;AACxC,MAAI,IAAI;AACR,WAAS,IAAI,GAAG,IAAI,IAAI,QAAQ,KAAK;AACnC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