@n8n/utils 1.17.0 → 1.18.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/dist/assert.cjs +7 -5
- package/dist/assert.cjs.map +1 -1
- package/dist/assert.d.cts +3 -1
- package/dist/assert.d.ts +3 -1
- package/dist/assert.js +8 -7
- package/dist/assert.js.map +1 -1
- package/dist/event-bus.cjs +39 -35
- package/dist/event-bus.cjs.map +1 -1
- package/dist/event-bus.d.cts +9 -9
- package/dist/event-bus.d.ts +9 -9
- package/dist/event-bus.js +40 -37
- package/dist/event-bus.js.map +1 -1
- package/dist/event-queue.cjs +36 -25
- package/dist/event-queue.cjs.map +1 -1
- package/dist/event-queue.d.cts +4 -2
- package/dist/event-queue.d.ts +4 -2
- package/dist/event-queue.js +37 -27
- package/dist/event-queue.js.map +1 -1
- package/dist/number/smartDecimal.cjs +7 -10
- package/dist/number/smartDecimal.cjs.map +1 -1
- package/dist/number/smartDecimal.d.cts +3 -1
- package/dist/number/smartDecimal.d.ts +3 -1
- package/dist/number/smartDecimal.js +8 -12
- package/dist/number/smartDecimal.js.map +1 -1
- package/dist/retry.cjs +35 -26
- package/dist/retry.cjs.map +1 -1
- package/dist/retry.d.cts +3 -1
- package/dist/retry.d.ts +3 -1
- package/dist/retry.js +36 -28
- package/dist/retry.js.map +1 -1
- package/dist/search/reRankSearchResults.cjs +15 -17
- package/dist/search/reRankSearchResults.cjs.map +1 -1
- package/dist/search/reRankSearchResults.d.cts +8 -6
- package/dist/search/reRankSearchResults.d.ts +8 -6
- package/dist/search/reRankSearchResults.js +16 -19
- package/dist/search/reRankSearchResults.js.map +1 -1
- package/dist/search/sublimeSearch.cjs +161 -186
- package/dist/search/sublimeSearch.cjs.map +1 -1
- package/dist/search/sublimeSearch.d.cts +9 -7
- package/dist/search/sublimeSearch.d.ts +9 -7
- package/dist/search/sublimeSearch.js +160 -187
- package/dist/search/sublimeSearch.js.map +1 -1
- package/dist/sort/sortByProperty.cjs +9 -8
- package/dist/sort/sortByProperty.cjs.map +1 -1
- package/dist/sort/sortByProperty.d.cts +3 -1
- package/dist/sort/sortByProperty.d.ts +3 -1
- package/dist/sort/sortByProperty.js +10 -10
- package/dist/sort/sortByProperty.js.map +1 -1
- package/dist/string/truncate.cjs +27 -27
- package/dist/string/truncate.cjs.map +1 -1
- package/dist/string/truncate.d.cts +3 -1
- package/dist/string/truncate.d.ts +3 -1
- package/dist/string/truncate.js +26 -28
- package/dist/string/truncate.js.map +1 -1
- package/package.json +8 -8
package/dist/assert.cjs
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
|
|
2
|
+
//#region src/assert.ts
|
|
3
|
+
/**
|
|
4
|
+
* Asserts given condition
|
|
5
|
+
*/
|
|
2
6
|
function assert(condition, message) {
|
|
3
|
-
|
|
4
|
-
throw new Error(_nullishCoalesce(message, () => ( "Assertion failed")));
|
|
5
|
-
}
|
|
7
|
+
if (!condition) throw new Error(message ?? "Assertion failed");
|
|
6
8
|
}
|
|
7
9
|
|
|
8
|
-
|
|
10
|
+
//#endregion
|
|
9
11
|
exports.assert = assert;
|
|
10
12
|
//# sourceMappingURL=assert.cjs.map
|
package/dist/assert.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"assert.cjs","names":[],"sources":["../src/assert.ts"],"sourcesContent":["/**\n * Asserts given condition\n */\nexport function assert(condition: unknown, message?: string): asserts condition {\n\tif (!condition) {\n\t\t// eslint-disable-next-line n8n-local-rules/no-plain-errors\n\t\tthrow new Error(message ?? 'Assertion failed');\n\t}\n}\n"],"mappings":";;;;;AAGA,SAAgB,OAAO,WAAoB,SAAqC;AAC/E,KAAI,CAAC,UAEJ,OAAM,IAAI,MAAM,WAAW,mBAAmB"}
|
package/dist/assert.d.cts
CHANGED
package/dist/assert.d.ts
CHANGED
package/dist/assert.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/assert.ts
|
|
2
|
+
/**
|
|
3
|
+
* Asserts given condition
|
|
4
|
+
*/
|
|
2
5
|
function assert(condition, message) {
|
|
3
|
-
|
|
4
|
-
throw new Error(message ?? "Assertion failed");
|
|
5
|
-
}
|
|
6
|
+
if (!condition) throw new Error(message ?? "Assertion failed");
|
|
6
7
|
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
};
|
|
8
|
+
|
|
9
|
+
//#endregion
|
|
10
|
+
export { assert };
|
|
10
11
|
//# sourceMappingURL=assert.js.map
|
package/dist/assert.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/assert.ts"],"sourcesContent":["/**\n * Asserts given condition\n */\nexport function assert(condition: unknown, message?: string): asserts condition {\n\tif (!condition) {\n\t\t// eslint-disable-next-line n8n-local-rules/no-plain-errors\n\t\tthrow new Error(message ?? 'Assertion failed');\n\t}\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"assert.js","names":[],"sources":["../src/assert.ts"],"sourcesContent":["/**\n * Asserts given condition\n */\nexport function assert(condition: unknown, message?: string): asserts condition {\n\tif (!condition) {\n\t\t// eslint-disable-next-line n8n-local-rules/no-plain-errors\n\t\tthrow new Error(message ?? 'Assertion failed');\n\t}\n}\n"],"mappings":";;;;AAGA,SAAgB,OAAO,WAAoB,SAAqC;AAC/E,KAAI,CAAC,UAEJ,OAAM,IAAI,MAAM,WAAW,mBAAmB"}
|
package/dist/event-bus.cjs
CHANGED
|
@@ -1,40 +1,44 @@
|
|
|
1
|
-
|
|
1
|
+
|
|
2
|
+
//#region src/event-bus.ts
|
|
3
|
+
/**
|
|
4
|
+
* Creates an event bus with the given listener map.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* const eventBus = createEventBus<{
|
|
9
|
+
* 'user-logged-in': { username: string };
|
|
10
|
+
* 'user-logged-out': never;
|
|
11
|
+
* }>();
|
|
12
|
+
*/
|
|
2
13
|
function createEventBus() {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
if (eventFns) {
|
|
30
|
-
eventFns.slice().forEach((handler) => {
|
|
31
|
-
handler(event);
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
};
|
|
14
|
+
const handlers = /* @__PURE__ */ new Map();
|
|
15
|
+
return {
|
|
16
|
+
on(eventName, fn) {
|
|
17
|
+
let eventFns = handlers.get(eventName);
|
|
18
|
+
if (!eventFns) eventFns = [fn];
|
|
19
|
+
else eventFns.push(fn);
|
|
20
|
+
handlers.set(eventName, eventFns);
|
|
21
|
+
},
|
|
22
|
+
once(eventName, fn) {
|
|
23
|
+
const handler = (payload) => {
|
|
24
|
+
this.off(eventName, handler);
|
|
25
|
+
fn(payload);
|
|
26
|
+
};
|
|
27
|
+
this.on(eventName, handler);
|
|
28
|
+
},
|
|
29
|
+
off(eventName, fn) {
|
|
30
|
+
const eventFns = handlers.get(eventName);
|
|
31
|
+
if (eventFns) eventFns.splice(eventFns.indexOf(fn) >>> 0, 1);
|
|
32
|
+
},
|
|
33
|
+
emit(eventName, event) {
|
|
34
|
+
const eventFns = handlers.get(eventName);
|
|
35
|
+
if (eventFns) eventFns.slice().forEach((handler) => {
|
|
36
|
+
handler(event);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
};
|
|
36
40
|
}
|
|
37
41
|
|
|
38
|
-
|
|
42
|
+
//#endregion
|
|
39
43
|
exports.createEventBus = createEventBus;
|
|
40
44
|
//# sourceMappingURL=event-bus.cjs.map
|
package/dist/event-bus.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"event-bus.cjs","names":["handler: typeof fn"],"sources":["../src/event-bus.ts"],"sourcesContent":["// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type CallbackFn = (...args: any[]) => any;\n\ntype Payloads<ListenerMap> = {\n\t[E in keyof ListenerMap]: unknown;\n};\n\ntype Listener<Payload> = (payload: Payload) => void;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport interface EventBus<ListenerMap extends Payloads<ListenerMap> = Record<string, any>> {\n\ton<EventName extends keyof ListenerMap & string>(\n\t\teventName: EventName,\n\t\tfn: Listener<ListenerMap[EventName]>,\n\t): void;\n\n\tonce<EventName extends keyof ListenerMap & string>(\n\t\teventName: EventName,\n\t\tfn: Listener<ListenerMap[EventName]>,\n\t): void;\n\n\toff<EventName extends keyof ListenerMap & string>(\n\t\teventName: EventName,\n\t\tfn: Listener<ListenerMap[EventName]>,\n\t): void;\n\n\temit<EventName extends keyof ListenerMap & string>(\n\t\teventName: EventName,\n\t\tevent?: ListenerMap[EventName],\n\t): void;\n}\n\n/**\n * Creates an event bus with the given listener map.\n *\n * @example\n * ```ts\n * const eventBus = createEventBus<{\n * 'user-logged-in': { username: string };\n * 'user-logged-out': never;\n * }>();\n */\nexport function createEventBus<\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tListenerMap extends Payloads<ListenerMap> = Record<string, any>,\n>(): EventBus<ListenerMap> {\n\tconst handlers = new Map<string, CallbackFn[]>();\n\n\treturn {\n\t\ton(eventName, fn) {\n\t\t\tlet eventFns = handlers.get(eventName);\n\t\t\tif (!eventFns) {\n\t\t\t\teventFns = [fn];\n\t\t\t} else {\n\t\t\t\teventFns.push(fn);\n\t\t\t}\n\t\t\thandlers.set(eventName, eventFns);\n\t\t},\n\n\t\tonce(eventName, fn) {\n\t\t\tconst handler: typeof fn = (payload) => {\n\t\t\t\tthis.off(eventName, handler);\n\t\t\t\tfn(payload);\n\t\t\t};\n\t\t\tthis.on(eventName, handler);\n\t\t},\n\n\t\toff(eventName, fn) {\n\t\t\tconst eventFns = handlers.get(eventName);\n\t\t\tif (eventFns) {\n\t\t\t\teventFns.splice(eventFns.indexOf(fn) >>> 0, 1);\n\t\t\t}\n\t\t},\n\n\t\temit(eventName, event) {\n\t\t\tconst eventFns = handlers.get(eventName);\n\t\t\tif (eventFns) {\n\t\t\t\teventFns.slice().forEach((handler) => {\n\t\t\t\t\thandler(event);\n\t\t\t\t});\n\t\t\t}\n\t\t},\n\t};\n}\n"],"mappings":";;;;;;;;;;;;AA0CA,SAAgB,iBAGW;CAC1B,MAAM,2BAAW,IAAI,KAA2B;AAEhD,QAAO;EACN,GAAG,WAAW,IAAI;GACjB,IAAI,WAAW,SAAS,IAAI,UAAU;AACtC,OAAI,CAAC,SACJ,YAAW,CAAC,GAAG;OAEf,UAAS,KAAK,GAAG;AAElB,YAAS,IAAI,WAAW,SAAS;;EAGlC,KAAK,WAAW,IAAI;GACnB,MAAMA,WAAsB,YAAY;AACvC,SAAK,IAAI,WAAW,QAAQ;AAC5B,OAAG,QAAQ;;AAEZ,QAAK,GAAG,WAAW,QAAQ;;EAG5B,IAAI,WAAW,IAAI;GAClB,MAAM,WAAW,SAAS,IAAI,UAAU;AACxC,OAAI,SACH,UAAS,OAAO,SAAS,QAAQ,GAAG,KAAK,GAAG,EAAE;;EAIhD,KAAK,WAAW,OAAO;GACtB,MAAM,WAAW,SAAS,IAAI,UAAU;AACxC,OAAI,SACH,UAAS,OAAO,CAAC,SAAS,YAAY;AACrC,YAAQ,MAAM;KACb;;EAGJ"}
|
package/dist/event-bus.d.cts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
+
//#region src/event-bus.d.ts
|
|
1
2
|
type CallbackFn = (...args: any[]) => any;
|
|
2
|
-
type Payloads<ListenerMap> = {
|
|
3
|
-
[E in keyof ListenerMap]: unknown;
|
|
4
|
-
};
|
|
3
|
+
type Payloads<ListenerMap> = { [E in keyof ListenerMap]: unknown };
|
|
5
4
|
type Listener<Payload> = (payload: Payload) => void;
|
|
6
5
|
interface EventBus<ListenerMap extends Payloads<ListenerMap> = Record<string, any>> {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
on<EventName extends keyof ListenerMap & string>(eventName: EventName, fn: Listener<ListenerMap[EventName]>): void;
|
|
7
|
+
once<EventName extends keyof ListenerMap & string>(eventName: EventName, fn: Listener<ListenerMap[EventName]>): void;
|
|
8
|
+
off<EventName extends keyof ListenerMap & string>(eventName: EventName, fn: Listener<ListenerMap[EventName]>): void;
|
|
9
|
+
emit<EventName extends keyof ListenerMap & string>(eventName: EventName, event?: ListenerMap[EventName]): void;
|
|
11
10
|
}
|
|
12
11
|
declare function createEventBus<ListenerMap extends Payloads<ListenerMap> = Record<string, any>>(): EventBus<ListenerMap>;
|
|
13
|
-
|
|
14
|
-
export {
|
|
12
|
+
//#endregion
|
|
13
|
+
export { CallbackFn, EventBus, createEventBus };
|
|
14
|
+
//# sourceMappingURL=event-bus.d.cts.map
|
package/dist/event-bus.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
+
//#region src/event-bus.d.ts
|
|
1
2
|
type CallbackFn = (...args: any[]) => any;
|
|
2
|
-
type Payloads<ListenerMap> = {
|
|
3
|
-
[E in keyof ListenerMap]: unknown;
|
|
4
|
-
};
|
|
3
|
+
type Payloads<ListenerMap> = { [E in keyof ListenerMap]: unknown };
|
|
5
4
|
type Listener<Payload> = (payload: Payload) => void;
|
|
6
5
|
interface EventBus<ListenerMap extends Payloads<ListenerMap> = Record<string, any>> {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
on<EventName extends keyof ListenerMap & string>(eventName: EventName, fn: Listener<ListenerMap[EventName]>): void;
|
|
7
|
+
once<EventName extends keyof ListenerMap & string>(eventName: EventName, fn: Listener<ListenerMap[EventName]>): void;
|
|
8
|
+
off<EventName extends keyof ListenerMap & string>(eventName: EventName, fn: Listener<ListenerMap[EventName]>): void;
|
|
9
|
+
emit<EventName extends keyof ListenerMap & string>(eventName: EventName, event?: ListenerMap[EventName]): void;
|
|
11
10
|
}
|
|
12
11
|
declare function createEventBus<ListenerMap extends Payloads<ListenerMap> = Record<string, any>>(): EventBus<ListenerMap>;
|
|
13
|
-
|
|
14
|
-
export {
|
|
12
|
+
//#endregion
|
|
13
|
+
export { CallbackFn, EventBus, createEventBus };
|
|
14
|
+
//# sourceMappingURL=event-bus.d.ts.map
|
package/dist/event-bus.js
CHANGED
|
@@ -1,40 +1,43 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/event-bus.ts
|
|
2
|
+
/**
|
|
3
|
+
* Creates an event bus with the given listener map.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* const eventBus = createEventBus<{
|
|
8
|
+
* 'user-logged-in': { username: string };
|
|
9
|
+
* 'user-logged-out': never;
|
|
10
|
+
* }>();
|
|
11
|
+
*/
|
|
2
12
|
function createEventBus() {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
if (eventFns) {
|
|
30
|
-
eventFns.slice().forEach((handler) => {
|
|
31
|
-
handler(event);
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
};
|
|
13
|
+
const handlers = /* @__PURE__ */ new Map();
|
|
14
|
+
return {
|
|
15
|
+
on(eventName, fn) {
|
|
16
|
+
let eventFns = handlers.get(eventName);
|
|
17
|
+
if (!eventFns) eventFns = [fn];
|
|
18
|
+
else eventFns.push(fn);
|
|
19
|
+
handlers.set(eventName, eventFns);
|
|
20
|
+
},
|
|
21
|
+
once(eventName, fn) {
|
|
22
|
+
const handler = (payload) => {
|
|
23
|
+
this.off(eventName, handler);
|
|
24
|
+
fn(payload);
|
|
25
|
+
};
|
|
26
|
+
this.on(eventName, handler);
|
|
27
|
+
},
|
|
28
|
+
off(eventName, fn) {
|
|
29
|
+
const eventFns = handlers.get(eventName);
|
|
30
|
+
if (eventFns) eventFns.splice(eventFns.indexOf(fn) >>> 0, 1);
|
|
31
|
+
},
|
|
32
|
+
emit(eventName, event) {
|
|
33
|
+
const eventFns = handlers.get(eventName);
|
|
34
|
+
if (eventFns) eventFns.slice().forEach((handler) => {
|
|
35
|
+
handler(event);
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
};
|
|
36
39
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
};
|
|
40
|
+
|
|
41
|
+
//#endregion
|
|
42
|
+
export { createEventBus };
|
|
40
43
|
//# sourceMappingURL=event-bus.js.map
|
package/dist/event-bus.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/event-bus.ts"],"sourcesContent":["// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type CallbackFn = (...args: any[]) => any;\n\ntype Payloads<ListenerMap> = {\n\t[E in keyof ListenerMap]: unknown;\n};\n\ntype Listener<Payload> = (payload: Payload) => void;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport interface EventBus<ListenerMap extends Payloads<ListenerMap> = Record<string, any>> {\n\ton<EventName extends keyof ListenerMap & string>(\n\t\teventName: EventName,\n\t\tfn: Listener<ListenerMap[EventName]>,\n\t): void;\n\n\tonce<EventName extends keyof ListenerMap & string>(\n\t\teventName: EventName,\n\t\tfn: Listener<ListenerMap[EventName]>,\n\t): void;\n\n\toff<EventName extends keyof ListenerMap & string>(\n\t\teventName: EventName,\n\t\tfn: Listener<ListenerMap[EventName]>,\n\t): void;\n\n\temit<EventName extends keyof ListenerMap & string>(\n\t\teventName: EventName,\n\t\tevent?: ListenerMap[EventName],\n\t): void;\n}\n\n/**\n * Creates an event bus with the given listener map.\n *\n * @example\n * ```ts\n * const eventBus = createEventBus<{\n * 'user-logged-in': { username: string };\n * 'user-logged-out': never;\n * }>();\n */\nexport function createEventBus<\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tListenerMap extends Payloads<ListenerMap> = Record<string, any>,\n>(): EventBus<ListenerMap> {\n\tconst handlers = new Map<string, CallbackFn[]>();\n\n\treturn {\n\t\ton(eventName, fn) {\n\t\t\tlet eventFns = handlers.get(eventName);\n\t\t\tif (!eventFns) {\n\t\t\t\teventFns = [fn];\n\t\t\t} else {\n\t\t\t\teventFns.push(fn);\n\t\t\t}\n\t\t\thandlers.set(eventName, eventFns);\n\t\t},\n\n\t\tonce(eventName, fn) {\n\t\t\tconst handler: typeof fn = (payload) => {\n\t\t\t\tthis.off(eventName, handler);\n\t\t\t\tfn(payload);\n\t\t\t};\n\t\t\tthis.on(eventName, handler);\n\t\t},\n\n\t\toff(eventName, fn) {\n\t\t\tconst eventFns = handlers.get(eventName);\n\t\t\tif (eventFns) {\n\t\t\t\teventFns.splice(eventFns.indexOf(fn) >>> 0, 1);\n\t\t\t}\n\t\t},\n\n\t\temit(eventName, event) {\n\t\t\tconst eventFns = handlers.get(eventName);\n\t\t\tif (eventFns) {\n\t\t\t\teventFns.slice().forEach((handler) => {\n\t\t\t\t\thandler(event);\n\t\t\t\t});\n\t\t\t}\n\t\t},\n\t};\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"event-bus.js","names":["handler: typeof fn"],"sources":["../src/event-bus.ts"],"sourcesContent":["// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type CallbackFn = (...args: any[]) => any;\n\ntype Payloads<ListenerMap> = {\n\t[E in keyof ListenerMap]: unknown;\n};\n\ntype Listener<Payload> = (payload: Payload) => void;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport interface EventBus<ListenerMap extends Payloads<ListenerMap> = Record<string, any>> {\n\ton<EventName extends keyof ListenerMap & string>(\n\t\teventName: EventName,\n\t\tfn: Listener<ListenerMap[EventName]>,\n\t): void;\n\n\tonce<EventName extends keyof ListenerMap & string>(\n\t\teventName: EventName,\n\t\tfn: Listener<ListenerMap[EventName]>,\n\t): void;\n\n\toff<EventName extends keyof ListenerMap & string>(\n\t\teventName: EventName,\n\t\tfn: Listener<ListenerMap[EventName]>,\n\t): void;\n\n\temit<EventName extends keyof ListenerMap & string>(\n\t\teventName: EventName,\n\t\tevent?: ListenerMap[EventName],\n\t): void;\n}\n\n/**\n * Creates an event bus with the given listener map.\n *\n * @example\n * ```ts\n * const eventBus = createEventBus<{\n * 'user-logged-in': { username: string };\n * 'user-logged-out': never;\n * }>();\n */\nexport function createEventBus<\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tListenerMap extends Payloads<ListenerMap> = Record<string, any>,\n>(): EventBus<ListenerMap> {\n\tconst handlers = new Map<string, CallbackFn[]>();\n\n\treturn {\n\t\ton(eventName, fn) {\n\t\t\tlet eventFns = handlers.get(eventName);\n\t\t\tif (!eventFns) {\n\t\t\t\teventFns = [fn];\n\t\t\t} else {\n\t\t\t\teventFns.push(fn);\n\t\t\t}\n\t\t\thandlers.set(eventName, eventFns);\n\t\t},\n\n\t\tonce(eventName, fn) {\n\t\t\tconst handler: typeof fn = (payload) => {\n\t\t\t\tthis.off(eventName, handler);\n\t\t\t\tfn(payload);\n\t\t\t};\n\t\t\tthis.on(eventName, handler);\n\t\t},\n\n\t\toff(eventName, fn) {\n\t\t\tconst eventFns = handlers.get(eventName);\n\t\t\tif (eventFns) {\n\t\t\t\teventFns.splice(eventFns.indexOf(fn) >>> 0, 1);\n\t\t\t}\n\t\t},\n\n\t\temit(eventName, event) {\n\t\t\tconst eventFns = handlers.get(eventName);\n\t\t\tif (eventFns) {\n\t\t\t\teventFns.slice().forEach((handler) => {\n\t\t\t\t\thandler(event);\n\t\t\t\t});\n\t\t\t}\n\t\t},\n\t};\n}\n"],"mappings":";;;;;;;;;;;AA0CA,SAAgB,iBAGW;CAC1B,MAAM,2BAAW,IAAI,KAA2B;AAEhD,QAAO;EACN,GAAG,WAAW,IAAI;GACjB,IAAI,WAAW,SAAS,IAAI,UAAU;AACtC,OAAI,CAAC,SACJ,YAAW,CAAC,GAAG;OAEf,UAAS,KAAK,GAAG;AAElB,YAAS,IAAI,WAAW,SAAS;;EAGlC,KAAK,WAAW,IAAI;GACnB,MAAMA,WAAsB,YAAY;AACvC,SAAK,IAAI,WAAW,QAAQ;AAC5B,OAAG,QAAQ;;AAEZ,QAAK,GAAG,WAAW,QAAQ;;EAG5B,IAAI,WAAW,IAAI;GAClB,MAAM,WAAW,SAAS,IAAI,UAAU;AACxC,OAAI,SACH,UAAS,OAAO,SAAS,QAAQ,GAAG,KAAK,GAAG,EAAE;;EAIhD,KAAK,WAAW,OAAO;GACtB,MAAM,WAAW,SAAS,IAAI,UAAU;AACxC,OAAI,SACH,UAAS,OAAO,CAAC,SAAS,YAAY;AACrC,YAAQ,MAAM;KACb;;EAGJ"}
|
package/dist/event-queue.cjs
CHANGED
|
@@ -1,30 +1,41 @@
|
|
|
1
|
-
|
|
1
|
+
|
|
2
|
+
//#region src/event-queue.ts
|
|
3
|
+
/**
|
|
4
|
+
* Create an event queue that processes events sequentially.
|
|
5
|
+
*
|
|
6
|
+
* @param processEvent - Async function that processes a single event.
|
|
7
|
+
* @returns A function that enqueues events for processing.
|
|
8
|
+
*/
|
|
2
9
|
function createEventQueue(processEvent) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
10
|
+
const queue = [];
|
|
11
|
+
let processing = false;
|
|
12
|
+
/**
|
|
13
|
+
* Process the next event in the queue (if not already processing).
|
|
14
|
+
*/
|
|
15
|
+
async function processNext() {
|
|
16
|
+
if (processing || queue.length === 0) return;
|
|
17
|
+
processing = true;
|
|
18
|
+
const currentEvent = queue.shift();
|
|
19
|
+
if (currentEvent !== void 0) try {
|
|
20
|
+
await processEvent(currentEvent);
|
|
21
|
+
} catch (error) {
|
|
22
|
+
console.error("Error processing event:", error);
|
|
23
|
+
}
|
|
24
|
+
processing = false;
|
|
25
|
+
await processNext();
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Enqueue an event and trigger processing.
|
|
29
|
+
*
|
|
30
|
+
* @param event - The event to enqueue.
|
|
31
|
+
*/
|
|
32
|
+
function enqueue(event) {
|
|
33
|
+
queue.push(event);
|
|
34
|
+
processNext();
|
|
35
|
+
}
|
|
36
|
+
return { enqueue };
|
|
26
37
|
}
|
|
27
38
|
|
|
28
|
-
|
|
39
|
+
//#endregion
|
|
29
40
|
exports.createEventQueue = createEventQueue;
|
|
30
41
|
//# sourceMappingURL=event-queue.cjs.map
|
package/dist/event-queue.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"event-queue.cjs","names":["queue: T[]"],"sources":["../src/event-queue.ts"],"sourcesContent":["/**\n * Create an event queue that processes events sequentially.\n *\n * @param processEvent - Async function that processes a single event.\n * @returns A function that enqueues events for processing.\n */\nexport function createEventQueue<T>(processEvent: (event: T) => Promise<void>) {\n\t// The internal queue holding events.\n\tconst queue: T[] = [];\n\n\t// Flag to indicate whether an event is currently being processed.\n\tlet processing = false;\n\n\t/**\n\t * Process the next event in the queue (if not already processing).\n\t */\n\tasync function processNext(): Promise<void> {\n\t\tif (processing || queue.length === 0) {\n\t\t\treturn;\n\t\t}\n\n\t\tprocessing = true;\n\t\tconst currentEvent = queue.shift();\n\n\t\tif (currentEvent !== undefined) {\n\t\t\ttry {\n\t\t\t\tawait processEvent(currentEvent);\n\t\t\t} catch (error) {\n\t\t\t\tconsole.error('Error processing event:', error);\n\t\t\t}\n\t\t}\n\n\t\tprocessing = false;\n\n\t\t// Recursively process the next event.\n\t\tawait processNext();\n\t}\n\n\t/**\n\t * Enqueue an event and trigger processing.\n\t *\n\t * @param event - The event to enqueue.\n\t */\n\tfunction enqueue(event: T): void {\n\t\tqueue.push(event);\n\t\tvoid processNext();\n\t}\n\n\treturn { enqueue };\n}\n"],"mappings":";;;;;;;;AAMA,SAAgB,iBAAoB,cAA2C;CAE9E,MAAMA,QAAa,EAAE;CAGrB,IAAI,aAAa;;;;CAKjB,eAAe,cAA6B;AAC3C,MAAI,cAAc,MAAM,WAAW,EAClC;AAGD,eAAa;EACb,MAAM,eAAe,MAAM,OAAO;AAElC,MAAI,iBAAiB,OACpB,KAAI;AACH,SAAM,aAAa,aAAa;WACxB,OAAO;AACf,WAAQ,MAAM,2BAA2B,MAAM;;AAIjD,eAAa;AAGb,QAAM,aAAa;;;;;;;CAQpB,SAAS,QAAQ,OAAgB;AAChC,QAAM,KAAK,MAAM;AACjB,EAAK,aAAa;;AAGnB,QAAO,EAAE,SAAS"}
|
package/dist/event-queue.d.cts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
//#region src/event-queue.d.ts
|
|
1
2
|
declare function createEventQueue<T>(processEvent: (event: T) => Promise<void>): {
|
|
2
|
-
|
|
3
|
+
enqueue: (event: T) => void;
|
|
3
4
|
};
|
|
4
|
-
|
|
5
|
+
//#endregion
|
|
5
6
|
export { createEventQueue };
|
|
7
|
+
//# sourceMappingURL=event-queue.d.cts.map
|
package/dist/event-queue.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
//#region src/event-queue.d.ts
|
|
1
2
|
declare function createEventQueue<T>(processEvent: (event: T) => Promise<void>): {
|
|
2
|
-
|
|
3
|
+
enqueue: (event: T) => void;
|
|
3
4
|
};
|
|
4
|
-
|
|
5
|
+
//#endregion
|
|
5
6
|
export { createEventQueue };
|
|
7
|
+
//# sourceMappingURL=event-queue.d.ts.map
|
package/dist/event-queue.js
CHANGED
|
@@ -1,30 +1,40 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/event-queue.ts
|
|
2
|
+
/**
|
|
3
|
+
* Create an event queue that processes events sequentially.
|
|
4
|
+
*
|
|
5
|
+
* @param processEvent - Async function that processes a single event.
|
|
6
|
+
* @returns A function that enqueues events for processing.
|
|
7
|
+
*/
|
|
2
8
|
function createEventQueue(processEvent) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
9
|
+
const queue = [];
|
|
10
|
+
let processing = false;
|
|
11
|
+
/**
|
|
12
|
+
* Process the next event in the queue (if not already processing).
|
|
13
|
+
*/
|
|
14
|
+
async function processNext() {
|
|
15
|
+
if (processing || queue.length === 0) return;
|
|
16
|
+
processing = true;
|
|
17
|
+
const currentEvent = queue.shift();
|
|
18
|
+
if (currentEvent !== void 0) try {
|
|
19
|
+
await processEvent(currentEvent);
|
|
20
|
+
} catch (error) {
|
|
21
|
+
console.error("Error processing event:", error);
|
|
22
|
+
}
|
|
23
|
+
processing = false;
|
|
24
|
+
await processNext();
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Enqueue an event and trigger processing.
|
|
28
|
+
*
|
|
29
|
+
* @param event - The event to enqueue.
|
|
30
|
+
*/
|
|
31
|
+
function enqueue(event) {
|
|
32
|
+
queue.push(event);
|
|
33
|
+
processNext();
|
|
34
|
+
}
|
|
35
|
+
return { enqueue };
|
|
26
36
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
};
|
|
37
|
+
|
|
38
|
+
//#endregion
|
|
39
|
+
export { createEventQueue };
|
|
30
40
|
//# sourceMappingURL=event-queue.js.map
|
package/dist/event-queue.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/event-queue.ts"],"sourcesContent":["/**\n * Create an event queue that processes events sequentially.\n *\n * @param processEvent - Async function that processes a single event.\n * @returns A function that enqueues events for processing.\n */\nexport function createEventQueue<T>(processEvent: (event: T) => Promise<void>) {\n\t// The internal queue holding events.\n\tconst queue: T[] = [];\n\n\t// Flag to indicate whether an event is currently being processed.\n\tlet processing = false;\n\n\t/**\n\t * Process the next event in the queue (if not already processing).\n\t */\n\tasync function processNext(): Promise<void> {\n\t\tif (processing || queue.length === 0) {\n\t\t\treturn;\n\t\t}\n\n\t\tprocessing = true;\n\t\tconst currentEvent = queue.shift();\n\n\t\tif (currentEvent !== undefined) {\n\t\t\ttry {\n\t\t\t\tawait processEvent(currentEvent);\n\t\t\t} catch (error) {\n\t\t\t\tconsole.error('Error processing event:', error);\n\t\t\t}\n\t\t}\n\n\t\tprocessing = false;\n\n\t\t// Recursively process the next event.\n\t\tawait processNext();\n\t}\n\n\t/**\n\t * Enqueue an event and trigger processing.\n\t *\n\t * @param event - The event to enqueue.\n\t */\n\tfunction enqueue(event: T): void {\n\t\tqueue.push(event);\n\t\tvoid processNext();\n\t}\n\n\treturn { enqueue };\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"event-queue.js","names":["queue: T[]"],"sources":["../src/event-queue.ts"],"sourcesContent":["/**\n * Create an event queue that processes events sequentially.\n *\n * @param processEvent - Async function that processes a single event.\n * @returns A function that enqueues events for processing.\n */\nexport function createEventQueue<T>(processEvent: (event: T) => Promise<void>) {\n\t// The internal queue holding events.\n\tconst queue: T[] = [];\n\n\t// Flag to indicate whether an event is currently being processed.\n\tlet processing = false;\n\n\t/**\n\t * Process the next event in the queue (if not already processing).\n\t */\n\tasync function processNext(): Promise<void> {\n\t\tif (processing || queue.length === 0) {\n\t\t\treturn;\n\t\t}\n\n\t\tprocessing = true;\n\t\tconst currentEvent = queue.shift();\n\n\t\tif (currentEvent !== undefined) {\n\t\t\ttry {\n\t\t\t\tawait processEvent(currentEvent);\n\t\t\t} catch (error) {\n\t\t\t\tconsole.error('Error processing event:', error);\n\t\t\t}\n\t\t}\n\n\t\tprocessing = false;\n\n\t\t// Recursively process the next event.\n\t\tawait processNext();\n\t}\n\n\t/**\n\t * Enqueue an event and trigger processing.\n\t *\n\t * @param event - The event to enqueue.\n\t */\n\tfunction enqueue(event: T): void {\n\t\tqueue.push(event);\n\t\tvoid processNext();\n\t}\n\n\treturn { enqueue };\n}\n"],"mappings":";;;;;;;AAMA,SAAgB,iBAAoB,cAA2C;CAE9E,MAAMA,QAAa,EAAE;CAGrB,IAAI,aAAa;;;;CAKjB,eAAe,cAA6B;AAC3C,MAAI,cAAc,MAAM,WAAW,EAClC;AAGD,eAAa;EACb,MAAM,eAAe,MAAM,OAAO;AAElC,MAAI,iBAAiB,OACpB,KAAI;AACH,SAAM,aAAa,aAAa;WACxB,OAAO;AACf,WAAQ,MAAM,2BAA2B,MAAM;;AAIjD,eAAa;AAGb,QAAM,aAAa;;;;;;;CAQpB,SAAS,QAAQ,OAAgB;AAChC,QAAM,KAAK,MAAM;AACjB,EAAK,aAAa;;AAGnB,QAAO,EAAE,SAAS"}
|
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/number/smartDecimal.ts
|
|
2
|
-
var smartDecimal = (value, decimals = 2) => {
|
|
3
|
-
if (Number.isInteger(value)) {
|
|
4
|
-
return value;
|
|
5
|
-
}
|
|
6
|
-
if (value.toString().split(".")[1].length <= decimals) {
|
|
7
|
-
return value;
|
|
8
|
-
}
|
|
9
|
-
return Number(value.toFixed(decimals));
|
|
10
|
-
};
|
|
11
1
|
|
|
2
|
+
//#region src/number/smartDecimal.ts
|
|
3
|
+
const smartDecimal = (value, decimals = 2) => {
|
|
4
|
+
if (Number.isInteger(value)) return value;
|
|
5
|
+
if (value.toString().split(".")[1].length <= decimals) return value;
|
|
6
|
+
return Number(value.toFixed(decimals));
|
|
7
|
+
};
|
|
12
8
|
|
|
9
|
+
//#endregion
|
|
13
10
|
exports.smartDecimal = smartDecimal;
|
|
14
11
|
//# sourceMappingURL=smartDecimal.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"smartDecimal.cjs","names":[],"sources":["../../src/number/smartDecimal.ts"],"sourcesContent":["export const smartDecimal = (value: number, decimals = 2): number => {\n\t// Check if integer\n\tif (Number.isInteger(value)) {\n\t\treturn value;\n\t}\n\n\t// Check if it has only one decimal place\n\tif (value.toString().split('.')[1].length <= decimals) {\n\t\treturn value;\n\t}\n\n\treturn Number(value.toFixed(decimals));\n};\n"],"mappings":";;AAAA,MAAa,gBAAgB,OAAe,WAAW,MAAc;AAEpE,KAAI,OAAO,UAAU,MAAM,CAC1B,QAAO;AAIR,KAAI,MAAM,UAAU,CAAC,MAAM,IAAI,CAAC,GAAG,UAAU,SAC5C,QAAO;AAGR,QAAO,OAAO,MAAM,QAAQ,SAAS,CAAC"}
|
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
if (value.toString().split(".")[1].length <= decimals) {
|
|
7
|
-
return value;
|
|
8
|
-
}
|
|
9
|
-
return Number(value.toFixed(decimals));
|
|
10
|
-
};
|
|
11
|
-
export {
|
|
12
|
-
smartDecimal
|
|
1
|
+
//#region src/number/smartDecimal.ts
|
|
2
|
+
const smartDecimal = (value, decimals = 2) => {
|
|
3
|
+
if (Number.isInteger(value)) return value;
|
|
4
|
+
if (value.toString().split(".")[1].length <= decimals) return value;
|
|
5
|
+
return Number(value.toFixed(decimals));
|
|
13
6
|
};
|
|
7
|
+
|
|
8
|
+
//#endregion
|
|
9
|
+
export { smartDecimal };
|
|
14
10
|
//# sourceMappingURL=smartDecimal.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/number/smartDecimal.ts"],"sourcesContent":["export const smartDecimal = (value: number, decimals = 2): number => {\n\t// Check if integer\n\tif (Number.isInteger(value)) {\n\t\treturn value;\n\t}\n\n\t// Check if it has only one decimal place\n\tif (value.toString().split('.')[1].length <= decimals) {\n\t\treturn value;\n\t}\n\n\treturn Number(value.toFixed(decimals));\n};\n"],"mappings":";
|
|
1
|
+
{"version":3,"file":"smartDecimal.js","names":[],"sources":["../../src/number/smartDecimal.ts"],"sourcesContent":["export const smartDecimal = (value: number, decimals = 2): number => {\n\t// Check if integer\n\tif (Number.isInteger(value)) {\n\t\treturn value;\n\t}\n\n\t// Check if it has only one decimal place\n\tif (value.toString().split('.')[1].length <= decimals) {\n\t\treturn value;\n\t}\n\n\treturn Number(value.toFixed(decimals));\n};\n"],"mappings":";AAAA,MAAa,gBAAgB,OAAe,WAAW,MAAc;AAEpE,KAAI,OAAO,UAAU,MAAM,CAC1B,QAAO;AAIR,KAAI,MAAM,UAAU,CAAC,MAAM,IAAI,CAAC,GAAG,UAAU,SAC5C,QAAO;AAGR,QAAO,OAAO,MAAM,QAAQ,SAAS,CAAC"}
|