mirror of
https://github.com/zoriya/v10.git
synced 2026-08-16 02:45:09 +00:00
build(utils): build26 from 45504a2b
This commit is contained in:
Vendored
+15
@@ -0,0 +1,15 @@
|
||||
//#region src/function/compose-callbacks.d.ts
|
||||
/**
|
||||
* Composes multiple callbacks into one. All callbacks receive same args, no return value.
|
||||
* Returns undefined if no callbacks provided.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* const onSetup = composeCallbacks(base.onSetup, extension.onSetup);
|
||||
* onSetup?.(ctx); // Calls both if defined
|
||||
* ```
|
||||
*/
|
||||
declare function composeCallbacks<T extends (...args: any[]) => void>(...fns: (T | undefined | null)[]): T | undefined;
|
||||
//#endregion
|
||||
export { composeCallbacks };
|
||||
//# sourceMappingURL=compose-callbacks.d.ts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"compose-callbacks.d.ts","names":[],"sources":["../../src/function/compose-callbacks.ts"],"mappings":";;;;;;;;;;;iBAYgB,iBAAiB,cAAc,yBAAyB,MAAM,0BAA0B"}
|
||||
Vendored
+24
@@ -0,0 +1,24 @@
|
||||
import { isNil } from "../predicate/predicate.js";
|
||||
//#region src/function/compose-callbacks.ts
|
||||
/**
|
||||
* Composes multiple callbacks into one. All callbacks receive same args, no return value.
|
||||
* Returns undefined if no callbacks provided.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* const onSetup = composeCallbacks(base.onSetup, extension.onSetup);
|
||||
* onSetup?.(ctx); // Calls both if defined
|
||||
* ```
|
||||
*/
|
||||
function composeCallbacks(...fns) {
|
||||
const defined = fns.filter((fn) => !isNil(fn));
|
||||
if (defined.length === 0) return void 0;
|
||||
if (defined.length === 1) return defined[0];
|
||||
return ((...args) => {
|
||||
defined.forEach((fn) => fn(...args));
|
||||
});
|
||||
}
|
||||
//#endregion
|
||||
export { composeCallbacks };
|
||||
|
||||
//# sourceMappingURL=compose-callbacks.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"compose-callbacks.js","names":[],"sources":["../../src/function/compose-callbacks.ts"],"sourcesContent":["import { isNil } from '../predicate';\n\n/**\n * Composes multiple callbacks into one. All callbacks receive same args, no return value.\n * Returns undefined if no callbacks provided.\n *\n * @example\n * ```ts\n * const onSetup = composeCallbacks(base.onSetup, extension.onSetup);\n * onSetup?.(ctx); // Calls both if defined\n * ```\n */\nexport function composeCallbacks<T extends (...args: any[]) => void>(...fns: (T | undefined | null)[]): T | undefined {\n const defined = fns.filter((fn): fn is T => !isNil(fn));\n\n if (defined.length === 0) return undefined;\n\n if (defined.length === 1) return defined[0];\n\n return ((...args: Parameters<T>) => {\n defined.forEach((fn) => fn(...args));\n }) as T;\n}\n"],"mappings":";;;;;;;;;;;;AAYA,SAAgB,iBAAqD,GAAG,KAA8C;CACpH,MAAM,UAAU,IAAI,QAAQ,OAAgB,CAAC,MAAM,EAAE,CAAC;CAEtD,IAAI,QAAQ,WAAW,GAAG,OAAO,KAAA;CAEjC,IAAI,QAAQ,WAAW,GAAG,OAAO,QAAQ;CAEzC,SAAS,GAAG,SAAwB;EAClC,QAAQ,SAAS,OAAO,GAAG,GAAG,IAAI,CAAC;CACrC;AACF"}
|
||||
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
//#region src/function/identity.d.ts
|
||||
declare function identity<T>(value: T): T;
|
||||
//#endregion
|
||||
export { identity };
|
||||
//# sourceMappingURL=identity.d.ts.map
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"identity.d.ts","names":[],"sources":["../../src/function/identity.ts"],"mappings":";iBAAgB,SAAS,GAAG,OAAO,IAAI"}
|
||||
Vendored
+8
@@ -0,0 +1,8 @@
|
||||
//#region src/function/identity.ts
|
||||
function identity(value) {
|
||||
return value;
|
||||
}
|
||||
//#endregion
|
||||
export { identity };
|
||||
|
||||
//# sourceMappingURL=identity.js.map
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"identity.js","names":[],"sources":["../../src/function/identity.ts"],"sourcesContent":["export function identity<T>(value: T): T {\n return value;\n}\n"],"mappings":";AAAA,SAAgB,SAAY,OAAa;CACvC,OAAO;AACT"}
|
||||
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
//#region src/function/noop.d.ts
|
||||
declare function noop(..._args: unknown[]): void;
|
||||
//#endregion
|
||||
export { noop };
|
||||
//# sourceMappingURL=noop.d.ts.map
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"noop.d.ts","names":[],"sources":["../../src/function/noop.ts"],"mappings":";iBAAgB,QAAQ"}
|
||||
Vendored
+6
@@ -0,0 +1,6 @@
|
||||
//#region src/function/noop.ts
|
||||
function noop(..._args) {}
|
||||
//#endregion
|
||||
export { noop };
|
||||
|
||||
//# sourceMappingURL=noop.js.map
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"noop.js","names":[],"sources":["../../src/function/noop.ts"],"sourcesContent":["export function noop(..._args: unknown[]): void {}\n"],"mappings":";AAAA,SAAgB,KAAK,GAAG,OAAwB,CAAC"}
|
||||
Vendored
+30
@@ -0,0 +1,30 @@
|
||||
//#region src/function/throttle.d.ts
|
||||
/** A throttled function that can be cancelled. */
|
||||
interface Throttled<Args extends unknown[]> {
|
||||
(...args: Args): void;
|
||||
/** Cancel any pending trailing-edge invocation. */
|
||||
cancel(): void;
|
||||
}
|
||||
interface ThrottleOptions {
|
||||
/**
|
||||
* When `true`, the first call invokes `fn` immediately (leading edge) and
|
||||
* starts the cooldown window. Calls during cooldown are coalesced and fire
|
||||
* on the trailing edge. If no calls arrive during the window the next call
|
||||
* is treated as a fresh leading invocation.
|
||||
*/
|
||||
leading?: boolean;
|
||||
}
|
||||
/**
|
||||
* Throttle: limits `fn` to at most once per `ms` window.
|
||||
*
|
||||
* - Default (no options): trailing-edge only — the first call schedules a
|
||||
* timer; subsequent calls within the window update the arguments. The
|
||||
* function fires once per window with the latest arguments.
|
||||
* - `{ leading: true }`: leading + trailing — the first call invokes
|
||||
* immediately and opens a cooldown window. Subsequent calls within the
|
||||
* window are coalesced to a single trailing-edge invocation.
|
||||
*/
|
||||
declare function throttle<Args extends unknown[]>(fn: (...args: Args) => void, ms: number, options?: ThrottleOptions): Throttled<Args>;
|
||||
//#endregion
|
||||
export { ThrottleOptions, Throttled, throttle };
|
||||
//# sourceMappingURL=throttle.d.ts.map
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"throttle.d.ts","names":[],"sources":["../../src/function/throttle.ts"],"mappings":";;UACiB,UAAU;MACrB,MAAM;;EAEV;;UAGe;;;;;;;EAOf;;;;;;;;;;;;iBAac,SAAS,wBACvB,QAAQ,MAAM,eACd,YACA,UAAU,kBACT,UAAU"}
|
||||
Vendored
+53
@@ -0,0 +1,53 @@
|
||||
//#region src/function/throttle.ts
|
||||
/**
|
||||
* Throttle: limits `fn` to at most once per `ms` window.
|
||||
*
|
||||
* - Default (no options): trailing-edge only — the first call schedules a
|
||||
* timer; subsequent calls within the window update the arguments. The
|
||||
* function fires once per window with the latest arguments.
|
||||
* - `{ leading: true }`: leading + trailing — the first call invokes
|
||||
* immediately and opens a cooldown window. Subsequent calls within the
|
||||
* window are coalesced to a single trailing-edge invocation.
|
||||
*/
|
||||
function throttle(fn, ms, options) {
|
||||
const leading = options?.leading ?? false;
|
||||
let timerId = null;
|
||||
let latestArgs;
|
||||
let hasPending = false;
|
||||
function startCooldown() {
|
||||
timerId = setTimeout(() => {
|
||||
timerId = null;
|
||||
if (hasPending) {
|
||||
hasPending = false;
|
||||
fn(...latestArgs);
|
||||
startCooldown();
|
||||
}
|
||||
}, ms);
|
||||
}
|
||||
const throttled = (...args) => {
|
||||
latestArgs = args;
|
||||
if (leading) if (timerId === null) {
|
||||
fn(...latestArgs);
|
||||
startCooldown();
|
||||
} else hasPending = true;
|
||||
else {
|
||||
if (timerId !== null) return;
|
||||
timerId = setTimeout(() => {
|
||||
timerId = null;
|
||||
fn(...latestArgs);
|
||||
}, ms);
|
||||
}
|
||||
};
|
||||
throttled.cancel = () => {
|
||||
if (timerId !== null) {
|
||||
clearTimeout(timerId);
|
||||
timerId = null;
|
||||
}
|
||||
hasPending = false;
|
||||
};
|
||||
return throttled;
|
||||
}
|
||||
//#endregion
|
||||
export { throttle };
|
||||
|
||||
//# sourceMappingURL=throttle.js.map
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"throttle.js","names":[],"sources":["../../src/function/throttle.ts"],"sourcesContent":["/** A throttled function that can be cancelled. */\nexport interface Throttled<Args extends unknown[]> {\n (...args: Args): void;\n /** Cancel any pending trailing-edge invocation. */\n cancel(): void;\n}\n\nexport interface ThrottleOptions {\n /**\n * When `true`, the first call invokes `fn` immediately (leading edge) and\n * starts the cooldown window. Calls during cooldown are coalesced and fire\n * on the trailing edge. If no calls arrive during the window the next call\n * is treated as a fresh leading invocation.\n */\n leading?: boolean;\n}\n\n/**\n * Throttle: limits `fn` to at most once per `ms` window.\n *\n * - Default (no options): trailing-edge only — the first call schedules a\n * timer; subsequent calls within the window update the arguments. The\n * function fires once per window with the latest arguments.\n * - `{ leading: true }`: leading + trailing — the first call invokes\n * immediately and opens a cooldown window. Subsequent calls within the\n * window are coalesced to a single trailing-edge invocation.\n */\nexport function throttle<Args extends unknown[]>(\n fn: (...args: Args) => void,\n ms: number,\n options?: ThrottleOptions\n): Throttled<Args> {\n const leading = options?.leading ?? false;\n\n let timerId: ReturnType<typeof setTimeout> | null = null;\n let latestArgs: Args;\n let hasPending = false;\n\n function startCooldown(): void {\n timerId = setTimeout(() => {\n timerId = null;\n\n if (hasPending) {\n hasPending = false;\n fn(...latestArgs);\n startCooldown();\n }\n }, ms);\n }\n\n const throttled = (...args: Args): void => {\n latestArgs = args;\n\n if (leading) {\n if (timerId === null) {\n // No active window — fire immediately (leading edge).\n fn(...latestArgs);\n startCooldown();\n } else {\n // Inside cooldown — mark pending for trailing edge.\n hasPending = true;\n }\n } else {\n // Trailing-only (original behavior).\n if (timerId !== null) return;\n timerId = setTimeout(() => {\n timerId = null;\n fn(...latestArgs);\n }, ms);\n }\n };\n\n throttled.cancel = (): void => {\n if (timerId !== null) {\n clearTimeout(timerId);\n timerId = null;\n }\n hasPending = false;\n };\n\n return throttled;\n}\n"],"mappings":";;;;;;;;;;;AA2BA,SAAgB,SACd,IACA,IACA,SACiB;CACjB,MAAM,UAAU,SAAS,WAAW;CAEpC,IAAI,UAAgD;CACpD,IAAI;CACJ,IAAI,aAAa;CAEjB,SAAS,gBAAsB;EAC7B,UAAU,iBAAiB;GACzB,UAAU;GAEV,IAAI,YAAY;IACd,aAAa;IACb,GAAG,GAAG,UAAU;IAChB,cAAc;GAChB;EACF,GAAG,EAAE;CACP;CAEA,MAAM,aAAa,GAAG,SAAqB;EACzC,aAAa;EAEb,IAAI,SACF,IAAI,YAAY,MAAM;GAEpB,GAAG,GAAG,UAAU;GAChB,cAAc;EAChB,OAEE,aAAa;OAEV;GAEL,IAAI,YAAY,MAAM;GACtB,UAAU,iBAAiB;IACzB,UAAU;IACV,GAAG,GAAG,UAAU;GAClB,GAAG,EAAE;EACP;CACF;CAEA,UAAU,eAAqB;EAC7B,IAAI,YAAY,MAAM;GACpB,aAAa,OAAO;GACpB,UAAU;EACZ;EACA,aAAa;CACf;CAEA,OAAO;AACT"}
|
||||
Vendored
+14
@@ -0,0 +1,14 @@
|
||||
//#region src/function/try-catch.d.ts
|
||||
/**
|
||||
* Wrap a function to catch and handle errors instead of throwing.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* const safeFn = tryCatch(riskyFn, (e) => logger.error(e));
|
||||
* safeFn?.(); // Never throws
|
||||
* ```
|
||||
*/
|
||||
declare function tryCatch<T extends (...args: any[]) => unknown>(fn: T | undefined, onError?: (error: unknown) => void): T | undefined;
|
||||
//#endregion
|
||||
export { tryCatch };
|
||||
//# sourceMappingURL=try-catch.d.ts.map
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"try-catch.d.ts","names":[],"sources":["../../src/function/try-catch.ts"],"mappings":";;;;;;;;;;iBASgB,SAAS,cAAc,yBACrC,IAAI,eACJ,WAAU,0BACT"}
|
||||
Vendored
+25
@@ -0,0 +1,25 @@
|
||||
//#region src/function/try-catch.ts
|
||||
/**
|
||||
* Wrap a function to catch and handle errors instead of throwing.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* const safeFn = tryCatch(riskyFn, (e) => logger.error(e));
|
||||
* safeFn?.(); // Never throws
|
||||
* ```
|
||||
*/
|
||||
function tryCatch(fn, onError = console.error) {
|
||||
if (!fn) return void 0;
|
||||
return ((...args) => {
|
||||
try {
|
||||
return fn(...args);
|
||||
} catch (error) {
|
||||
onError(error);
|
||||
return;
|
||||
}
|
||||
});
|
||||
}
|
||||
//#endregion
|
||||
export { tryCatch };
|
||||
|
||||
//# sourceMappingURL=try-catch.js.map
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"try-catch.js","names":[],"sources":["../../src/function/try-catch.ts"],"sourcesContent":["/**\n * Wrap a function to catch and handle errors instead of throwing.\n *\n * @example\n * ```ts\n * const safeFn = tryCatch(riskyFn, (e) => logger.error(e));\n * safeFn?.(); // Never throws\n * ```\n */\nexport function tryCatch<T extends (...args: any[]) => unknown>(\n fn: T | undefined,\n onError: (error: unknown) => void = console.error\n): T | undefined {\n if (!fn) return undefined;\n\n return ((...args: Parameters<T>) => {\n try {\n return fn(...args);\n } catch (error) {\n onError(error);\n return undefined;\n }\n }) as T;\n}\n"],"mappings":";;;;;;;;;;AASA,SAAgB,SACd,IACA,UAAoC,QAAQ,OAC7B;CACf,IAAI,CAAC,IAAI,OAAO,KAAA;CAEhB,SAAS,GAAG,SAAwB;EAClC,IAAI;GACF,OAAO,GAAG,GAAG,IAAI;EACnB,SAAS,OAAO;GACd,QAAQ,KAAK;GACb;EACF;CACF;AACF"}
|
||||
Reference in New Issue
Block a user