@byloth/core 1.1.8 → 1.2.0-rc.2
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/core.js +132 -58
- package/dist/core.js.map +1 -1
- package/dist/core.umd.cjs +2 -2
- package/dist/core.umd.cjs.map +1 -1
- package/package.json +6 -6
- package/src/index.ts +2 -2
- package/src/models/index.ts +2 -1
- package/src/models/smart-iterator.ts +119 -0
- package/src/types.ts +3 -1
- package/src/utils/date.ts +15 -10
- package/src/utils/iterator.ts +42 -22
package/dist/core.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var o = (r, e, t) => (
|
|
4
|
-
class
|
|
1
|
+
var a = Object.defineProperty;
|
|
2
|
+
var h = (r, e, t) => e in r ? a(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
|
|
3
|
+
var o = (r, e, t) => (h(r, typeof e != "symbol" ? e + "" : e, t), t);
|
|
4
|
+
class m {
|
|
5
5
|
constructor(e, t) {
|
|
6
6
|
o(this, "_resolve");
|
|
7
7
|
o(this, "_reject");
|
|
8
8
|
o(this, "_promise");
|
|
9
9
|
let n, s;
|
|
10
|
-
this._promise = new Promise((i,
|
|
11
|
-
n = i, s =
|
|
10
|
+
this._promise = new Promise((i, l) => {
|
|
11
|
+
n = i, s = l;
|
|
12
12
|
}).then(e, t), this._resolve = n, this._reject = s;
|
|
13
13
|
}
|
|
14
14
|
get resolve() {
|
|
@@ -51,7 +51,7 @@ Caused by ${t.stack}` : this.stack += `
|
|
|
51
51
|
Caused by ${t}`);
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
|
-
class
|
|
54
|
+
class v {
|
|
55
55
|
constructor(e = !0) {
|
|
56
56
|
o(this, "_preferPersistence");
|
|
57
57
|
o(this, "_volatile");
|
|
@@ -186,7 +186,70 @@ class m {
|
|
|
186
186
|
this._volatile.removeItem(e), this._persistent.removeItem(e);
|
|
187
187
|
}
|
|
188
188
|
}
|
|
189
|
-
class
|
|
189
|
+
class u {
|
|
190
|
+
constructor(e) {
|
|
191
|
+
o(this, "_iterator");
|
|
192
|
+
o(this, "return");
|
|
193
|
+
o(this, "throw");
|
|
194
|
+
e instanceof Function ? this._iterator = e() : Symbol.iterator in e ? this._iterator = e[Symbol.iterator]() : this._iterator = e, this._iterator.return && (this.return = (t) => this._iterator.return(t)), this._iterator.throw && (this.throw = (t) => this._iterator.throw(t));
|
|
195
|
+
}
|
|
196
|
+
filter(e) {
|
|
197
|
+
let t = 0;
|
|
198
|
+
const n = this._iterator;
|
|
199
|
+
return new u({
|
|
200
|
+
*[Symbol.iterator]() {
|
|
201
|
+
for (; ; ) {
|
|
202
|
+
const s = n.next();
|
|
203
|
+
if (s.done)
|
|
204
|
+
return s.value;
|
|
205
|
+
e(s.value, t) && (yield s.value), t += 1;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
map(e) {
|
|
211
|
+
let t = 0;
|
|
212
|
+
const n = this._iterator;
|
|
213
|
+
return new u({
|
|
214
|
+
*[Symbol.iterator]() {
|
|
215
|
+
for (; ; ) {
|
|
216
|
+
const s = n.next();
|
|
217
|
+
if (s.done)
|
|
218
|
+
return s.value;
|
|
219
|
+
yield e(s.value, t), t += 1;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
reduce(e, t) {
|
|
225
|
+
let n = 0, s = t;
|
|
226
|
+
for (; ; ) {
|
|
227
|
+
const i = this._iterator.next();
|
|
228
|
+
if (i.done)
|
|
229
|
+
return s;
|
|
230
|
+
s = e(s, i.value, n), n += 1;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
forEach(e) {
|
|
234
|
+
let t = 0;
|
|
235
|
+
for (; ; ) {
|
|
236
|
+
const n = this._iterator.next();
|
|
237
|
+
if (n.done)
|
|
238
|
+
return;
|
|
239
|
+
e(n.value, t), t += 1;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
next(...e) {
|
|
243
|
+
return this._iterator.next(...e);
|
|
244
|
+
}
|
|
245
|
+
toArray() {
|
|
246
|
+
return [...this];
|
|
247
|
+
}
|
|
248
|
+
[Symbol.iterator]() {
|
|
249
|
+
return this;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
class w {
|
|
190
253
|
constructor() {
|
|
191
254
|
o(this, "_subscribers");
|
|
192
255
|
this._subscribers = [];
|
|
@@ -204,32 +267,34 @@ class g {
|
|
|
204
267
|
return this._subscribers.slice().map((t) => t(...e));
|
|
205
268
|
}
|
|
206
269
|
}
|
|
207
|
-
async function
|
|
270
|
+
async function g(r) {
|
|
208
271
|
return new Promise((e, t) => setTimeout(e, r));
|
|
209
272
|
}
|
|
210
|
-
async function
|
|
273
|
+
async function y() {
|
|
211
274
|
return new Promise((r, e) => requestAnimationFrame(() => r()));
|
|
212
275
|
}
|
|
213
|
-
var
|
|
214
|
-
function
|
|
276
|
+
var f = /* @__PURE__ */ ((r) => (r[r.Second = 1e3] = "Second", r[r.Minute = 6e4] = "Minute", r[r.Hour = 36e5] = "Hour", r[r.Day = 864e5] = "Day", r[r.Week = 6048e5] = "Week", r[r.Month = 2592e6] = "Month", r[r.Year = 31536e6] = "Year", r))(f || {});
|
|
277
|
+
function b(r, e, t = 864e5) {
|
|
215
278
|
return Math.floor((e.getTime() - r.getTime()) / t);
|
|
216
279
|
}
|
|
217
|
-
function
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
280
|
+
function p(r, e, t = 864e5) {
|
|
281
|
+
return new u(function* () {
|
|
282
|
+
const n = e.getTime();
|
|
283
|
+
let s = r.getTime();
|
|
284
|
+
for (; s < n; )
|
|
285
|
+
yield new Date(s), s += t;
|
|
286
|
+
});
|
|
222
287
|
}
|
|
223
|
-
function
|
|
288
|
+
function x(r, e = 864e5) {
|
|
224
289
|
return new Date(Math.floor(r.getTime() / e) * e);
|
|
225
290
|
}
|
|
226
|
-
async function
|
|
291
|
+
async function S(r, e = "text/javascript") {
|
|
227
292
|
return new Promise((t, n) => {
|
|
228
293
|
const s = document.createElement("script");
|
|
229
294
|
s.async = !0, s.defer = !0, s.src = r, s.type = e, s.onload = () => t(), s.onerror = () => n(), document.body.appendChild(s);
|
|
230
295
|
});
|
|
231
296
|
}
|
|
232
|
-
function
|
|
297
|
+
function I(r) {
|
|
233
298
|
if (Array.isArray(r))
|
|
234
299
|
return r.length;
|
|
235
300
|
let e = 0;
|
|
@@ -237,10 +302,12 @@ function S(r) {
|
|
|
237
302
|
e += 1;
|
|
238
303
|
return e;
|
|
239
304
|
}
|
|
240
|
-
function
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
305
|
+
function M(r, e, t = 1) {
|
|
306
|
+
return new u(function* () {
|
|
307
|
+
e === void 0 && (e = r, r = 0), r > e && (t = t ?? -1);
|
|
308
|
+
for (let n = r; n < e; n += t)
|
|
309
|
+
yield n;
|
|
310
|
+
});
|
|
244
311
|
}
|
|
245
312
|
function k(r) {
|
|
246
313
|
const e = [...r];
|
|
@@ -251,30 +318,36 @@ function k(r) {
|
|
|
251
318
|
return e;
|
|
252
319
|
}
|
|
253
320
|
function j(r) {
|
|
254
|
-
return
|
|
321
|
+
return new u(function* () {
|
|
322
|
+
const e = /* @__PURE__ */ new Set();
|
|
323
|
+
for (const t of r)
|
|
324
|
+
e.has(t) || (e.add(t), yield t);
|
|
325
|
+
});
|
|
255
326
|
}
|
|
256
|
-
function
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
327
|
+
function _(r, e) {
|
|
328
|
+
return new u(function* () {
|
|
329
|
+
const t = r[Symbol.iterator](), n = e[Symbol.iterator]();
|
|
330
|
+
for (; ; ) {
|
|
331
|
+
const s = t.next(), i = n.next();
|
|
332
|
+
if (s.done || i.done)
|
|
333
|
+
break;
|
|
334
|
+
yield [s.value, i.value];
|
|
335
|
+
}
|
|
336
|
+
});
|
|
264
337
|
}
|
|
265
|
-
function
|
|
338
|
+
function P(r, e) {
|
|
266
339
|
if (e === void 0) {
|
|
267
340
|
let s = 0, i = 0;
|
|
268
|
-
for (const
|
|
269
|
-
s +=
|
|
341
|
+
for (const l of r)
|
|
342
|
+
s += l, i += 1;
|
|
270
343
|
return s / i;
|
|
271
344
|
}
|
|
272
345
|
let t = 0, n = 0;
|
|
273
|
-
for (const [s, i] of
|
|
346
|
+
for (const [s, i] of _(r, e))
|
|
274
347
|
t += s * i, n += i;
|
|
275
348
|
return t / n;
|
|
276
349
|
}
|
|
277
|
-
function
|
|
350
|
+
function T(r) {
|
|
278
351
|
let e = 0;
|
|
279
352
|
for (let t = 0; t < r.length; t++) {
|
|
280
353
|
const n = r.charCodeAt(t);
|
|
@@ -282,7 +355,7 @@ function P(r) {
|
|
|
282
355
|
}
|
|
283
356
|
return e;
|
|
284
357
|
}
|
|
285
|
-
function
|
|
358
|
+
function A(r = 1, e, t) {
|
|
286
359
|
if (e === void 0 && (e = r, r = 0), r === e)
|
|
287
360
|
return r;
|
|
288
361
|
let n;
|
|
@@ -304,32 +377,33 @@ function $(r) {
|
|
|
304
377
|
e += t;
|
|
305
378
|
return e;
|
|
306
379
|
}
|
|
307
|
-
function
|
|
380
|
+
function C(r) {
|
|
308
381
|
return `${r.charAt(0).toUpperCase()}${r.slice(1)}`;
|
|
309
382
|
}
|
|
310
|
-
const
|
|
383
|
+
const E = "1.2.0-rc.2";
|
|
311
384
|
export {
|
|
312
|
-
|
|
313
|
-
|
|
385
|
+
f as DateUnit,
|
|
386
|
+
m as DeferredPromise,
|
|
314
387
|
c as Exception,
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
388
|
+
v as JsonStorage,
|
|
389
|
+
u as SmartIterator,
|
|
390
|
+
w as Subscribers,
|
|
391
|
+
E as VERSION,
|
|
392
|
+
P as average,
|
|
393
|
+
C as capitalize,
|
|
394
|
+
I as count,
|
|
395
|
+
b as dateDifference,
|
|
396
|
+
p as dateRange,
|
|
397
|
+
x as dateRound,
|
|
398
|
+
g as delay,
|
|
399
|
+
T as hash,
|
|
400
|
+
S as loadScript,
|
|
401
|
+
y as nextAnimationFrame,
|
|
402
|
+
A as random,
|
|
329
403
|
M as range,
|
|
330
404
|
k as shuffle,
|
|
331
405
|
$ as sum,
|
|
332
406
|
j as unique,
|
|
333
|
-
|
|
407
|
+
_ as zip
|
|
334
408
|
};
|
|
335
409
|
//# sourceMappingURL=core.js.map
|
package/dist/core.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.js","sources":["../src/models/deferred-promise.ts","../src/models/exception.ts","../src/models/json-storage.ts","../src/models/subscribers.ts","../src/utils/async.ts","../src/utils/date.ts","../src/utils/dom.ts","../src/utils/iterator.ts","../src/utils/math.ts","../src/utils/string.ts","../src/index.ts"],"sourcesContent":["import type { PromiseResolver, PromiseRejecter, FulfilledHandler, RejectedHandler } from \"../types.js\";\n\nexport default class DeferredPromise<T = void, E = unknown, F = T, R = never>\n{\n protected _resolve!: PromiseResolver<T>;\n protected _reject!: PromiseRejecter<E>;\n\n protected _promise: Promise<F | R>;\n\n public constructor(onFulfilled?: FulfilledHandler<T, F> | null, onRejected?: RejectedHandler<E, R> | null)\n {\n let _resolve: PromiseResolver<T>;\n let _reject: PromiseRejecter<E>;\n\n this._promise = new Promise<T>((resolve, reject) =>\n {\n _resolve = resolve as PromiseResolver<T>;\n _reject = reject as PromiseRejecter<E>;\n\n }).then(onFulfilled, onRejected);\n\n this._resolve = _resolve!;\n this._reject = _reject!;\n }\n\n public get resolve(): PromiseResolver<T>\n {\n return this._resolve;\n }\n public get reject(): PromiseRejecter<E>\n {\n return this._reject;\n }\n\n public then<N = F | R, H = R>(\n onFulfilled?: FulfilledHandler<F | R, N> | null,\n onRejected?: RejectedHandler<R, H> | null): Promise<N | H>\n {\n return this._promise.then(onFulfilled, onRejected);\n }\n public catch<H = R>(onRejected?: RejectedHandler<R, H> | null): Promise<F | R | H>\n {\n return this._promise.catch(onRejected);\n }\n public finally(onFinally?: (() => void) | null): Promise<F | R>\n {\n return this._promise.finally(onFinally);\n }\n\n public watch(promise: Promise<T>): this\n {\n promise.then(this.resolve, this.reject);\n\n return this;\n }\n\n public get [Symbol.toStringTag]()\n {\n return \"DeferredPromise\";\n }\n}\n","export default class Exception extends Error\n{\n public static FromUnknown(error: unknown): Exception\n {\n if (error instanceof Exception)\n {\n return error;\n }\n if (error instanceof Error)\n {\n const exc = new Exception(error.message);\n\n exc.stack = error.stack;\n exc.name = error.name;\n\n return exc;\n }\n\n return new Exception(`${error}`);\n }\n\n public constructor(message: string, cause?: unknown, name = \"Exception\")\n {\n super(message);\n\n this.cause = cause;\n this.name = name;\n\n if (cause)\n {\n if (cause instanceof Error)\n {\n this.stack += `\\n\\nCaused by ${cause.stack}`;\n }\n else\n {\n this.stack += `\\n\\nCaused by ${cause}`;\n }\n }\n }\n}\n","/* eslint-disable no-trailing-spaces */\n\n/**\n * A wrapper around the `Storage` API to store and retrieve JSON values.\n *\n * It allows to handle either the `sessionStorage` or the `localStorage`\n * storage at the same time, depending on the required use case.\n */\nexport default class JsonStorage\n{\n protected _preferPersistence: boolean;\n\n protected _volatile: Storage;\n protected _persistent: Storage;\n\n public constructor(preferPersistence = true)\n {\n this._preferPersistence = preferPersistence;\n\n this._volatile = window.sessionStorage;\n this._persistent = window.localStorage;\n }\n\n protected _get<T>(storage: Storage, propertyName: string): T | undefined;\n protected _get<T>(storage: Storage, propertyName: string, defaultValue: T): T;\n protected _get<T>(storage: Storage, propertyName: string, defaultValue?: T): T | undefined;\n protected _get<T>(storage: Storage, propertyName: string, defaultValue?: T): T | undefined\n {\n const propertyValue = storage.getItem(propertyName);\n if (propertyValue)\n {\n try\n {\n return JSON.parse(propertyValue);\n }\n catch (error)\n {\n // eslint-disable-next-line no-console\n console.warn(\n `The \"${propertyValue}\" value for \"${propertyName}\"` +\n \" property cannot be parsed. Clearing the storage...\");\n\n storage.removeItem(propertyName);\n }\n }\n\n return defaultValue;\n }\n protected _set<T>(storage: Storage, propertyName: string, newValue?: T): void\n {\n const encodedValue = JSON.stringify(newValue);\n if (encodedValue)\n {\n storage.setItem(propertyName, encodedValue);\n }\n else\n {\n storage.removeItem(propertyName);\n }\n }\n\n /**\n * Retrieves the value with the specified name from the corresponding storage.\n *\n * @param propertyName The name of the property to retrieve.\n * @param defaultValue The default value to return if the property does not exist.\n * @param persistent Whether to use the persistent `localStorage` or the volatile `sessionStorage`.\n *\n * @returns The value of the property or the default value if the property does not exist.\n */\n public get<T>(propertyName: string, defaultValue: undefined, persistent?: boolean): T | undefined;\n public get<T>(propertyName: string, defaultValue: T, persistent?: boolean): T ;\n public get<T>(propertyName: string, defaultValue?: T, persistent?: boolean): T | undefined;\n public get<T>(propertyName: string, defaultValue?: T, persistent = this._preferPersistence): T | undefined\n {\n const storage = persistent ? this._persistent : this._volatile;\n\n return this._get<T>(storage, propertyName, defaultValue);\n }\n /**\n * Retrieves the value with the specified name from the volatile `sessionStorage`.\n *\n * @param propertyName The name of the property to retrieve.\n * @param defaultValue The default value to return if the property does not exist.\n *\n * @returns The value of the property or the default value if the property does not exist.\n */\n public recall<T>(propertyName: string): T | undefined;\n public recall<T>(propertyName: string, defaultValue: T): T;\n public recall<T>(propertyName: string, defaultValue?: T): T | undefined;\n public recall<T>(propertyName: string, defaultValue?: T): T | undefined\n {\n return this._get<T>(this._volatile, propertyName, defaultValue);\n }\n /**\n * Retrieves the value with the specified name looking first in the\n * volatile `sessionStorage` and then in the persistent `localStorage`.\n *\n * @param propertyName The name of the property to retrieve.\n * @param defaultValue The default value to return if the property does not exist.\n *\n * @returns The value of the property or the default value if the property does not exist.\n */\n public retrieve<T>(propertyName: string): T | undefined;\n public retrieve<T>(propertyName: string, defaultValue: T): T;\n public retrieve<T>(propertyName: string, defaultValue?: T): T | undefined;\n public retrieve<T>(propertyName: string, defaultValue?: T): T | undefined\n {\n return this.recall<T>(propertyName) ?? this.read<T>(propertyName, defaultValue);\n }\n /**\n * Retrieves the value with the specified name from the persistent `localStorage`.\n *\n * @param propertyName The name of the property to retrieve.\n * @param defaultValue The default value to return if the property does not exist.\n *\n * @returns The value of the property or the default value if the property does not exist.\n */\n public read<T>(propertyName: string): T | undefined;\n public read<T>(propertyName: string, defaultValue: T): T;\n public read<T>(propertyName: string, defaultValue?: T): T | undefined;\n public read<T>(propertyName: string, defaultValue?: T): T | undefined\n {\n return this._get<T>(this._persistent, propertyName, defaultValue);\n }\n\n /**\n * Checks whether the property with the specified name exists in the corresponding storage.\n *\n * @param propertyName The name of the property to check.\n * @param persistent Whether to use the persistent `localStorage` or the volatile `sessionStorage`.\n *\n * @returns `true` if the property exists, `false` otherwise.\n */\n public has(propertyName: string, persistent?: boolean): boolean\n {\n const storage = persistent ? this._persistent : this._volatile;\n\n return storage.getItem(propertyName) !== null;\n }\n /**\n * Checks whether the property with the specified name exists in the volatile `sessionStorage`.\n *\n * @param propertyName The name of the property to check.\n *\n * @returns `true` if the property exists, `false` otherwise.\n */\n public knows(propertyName: string): boolean\n {\n return this._volatile.getItem(propertyName) !== null;\n }\n /**\n * Checks whether the property with the specified name exists looking first in the\n * volatile `sessionStorage` and then in the persistent `localStorage`.\n *\n * @param propertyName The name of the property to check.\n *\n * @returns `true` if the property exists, `false` otherwise.\n */\n public find(propertyName: string): boolean\n {\n return this.knows(propertyName) ?? this.exists(propertyName);\n }\n /**\n * Checks whether the property with the specified name exists in the persistent `localStorage`.\n *\n * @param propertyName The name of the property to check.\n *\n * @returns `true` if the property exists, `false` otherwise.\n */\n public exists(propertyName: string): boolean\n {\n return this._persistent.getItem(propertyName) !== null;\n }\n\n /**\n * Sets the value with the specified name in the corresponding storage.\n * If the value is `undefined`, the property is removed from the storage.\n *\n * @param propertyName The name of the property to set.\n * @param newValue The new value to set.\n * @param persistent Whether to use the persistent `localStorage` or the volatile `sessionStorage`.\n */\n public set<T>(propertyName: string, newValue?: T, persistent = this._preferPersistence): void\n {\n const storage = persistent ? this._persistent : this._volatile;\n\n this._set<T>(storage, propertyName, newValue);\n }\n /**\n * Sets the value with the specified name in the volatile `sessionStorage`.\n * If the value is `undefined`, the property is removed from the storage.\n *\n * @param propertyName The name of the property to set.\n * @param newValue The new value to set.\n */\n public remember<T>(propertyName: string, newValue?: T): void\n {\n this._set<T>(this._volatile, propertyName, newValue);\n }\n /**\n * Sets the value with the specified name in the persistent `localStorage`.\n * If the value is `undefined`, the property is removed from the storage.\n *\n * @param propertyName The name of the property to set.\n * @param newValue The new value to set.\n */\n public write<T>(propertyName: string, newValue?: T): void\n {\n this._set<T>(this._persistent, propertyName, newValue);\n }\n\n /**\n * Removes the value with the specified name from the volatile `sessionStorage`.\n *\n * @param propertyName The name of the property to remove.\n */\n public forget(propertyName: string): void\n {\n this._volatile.removeItem(propertyName);\n }\n /**\n * Removes the value with the specified name from the persistent `localStorage`.\n *\n * @param propertyName The name of the property to remove.\n */\n public erase(propertyName: string): void\n {\n this._persistent.removeItem(propertyName);\n }\n /**\n * Removes the value with the specified name from all the storages.\n *\n * @param propertyName The name of the property to remove.\n */\n public clear(propertyName: string): void\n {\n this._volatile.removeItem(propertyName);\n this._persistent.removeItem(propertyName);\n }\n}\n","import Exception from \"./exception.js\";\n\nexport default class Subscribers<P extends unknown[] = [], R = void, T extends (...args: P) => R = (...args: P) => R>\n{\n protected _subscribers: T[];\n\n public constructor()\n {\n this._subscribers = [];\n }\n\n public add(subscriber: T): void\n {\n this._subscribers.push(subscriber);\n }\n public remove(subscriber: T): void\n {\n const index = this._subscribers.indexOf(subscriber);\n if (index < 0)\n {\n throw new Exception(\"Unable to remove the requested subscriber. It was not found.\");\n }\n\n this._subscribers.splice(index, 1);\n }\n\n public call(...args: P): R[]\n {\n return this._subscribers\n .slice()\n .map((subscriber) => subscriber(...args));\n }\n}\n","export async function delay(milliseconds: number): Promise<void>\n{\n return new Promise<void>((resolve, reject) => setTimeout(resolve, milliseconds));\n}\n\nexport async function nextAnimationFrame(): Promise<void>\n{\n return new Promise<void>((resolve, reject) => requestAnimationFrame(() => resolve()));\n}\n","export enum DateUnit\n{\n Second = 1000,\n Minute = 60 * Second,\n Hour = 60 * Minute,\n Day = 24 * Hour,\n Week = 7 * Day,\n Month = 30 * Day,\n Year = 365 * Day\n}\n\nexport function dateDifference(start: Date, end: Date, unit = DateUnit.Day)\n{\n return Math.floor((end.getTime() - start.getTime()) / unit);\n}\n\nexport function* dateRange(start: Date, end: Date, offset = DateUnit.Day)\n{\n const endTime = end.getTime();\n\n let unixTime: number = start.getTime();\n while (unixTime < endTime)\n {\n yield new Date(unixTime);\n\n unixTime += offset;\n }\n}\n\nexport function dateRound(date: Date, unit = DateUnit.Day)\n{\n return new Date(Math.floor(date.getTime() / unit) * unit);\n}\n","export async function loadScript(scriptUrl: string, scriptType = \"text/javascript\"): Promise<void>\n{\n return new Promise<void>((resolve, reject) =>\n {\n const script = document.createElement(\"script\");\n\n script.async = true;\n script.defer = true;\n script.src = scriptUrl;\n script.type = scriptType;\n\n script.onload = () => resolve();\n script.onerror = () => reject();\n\n document.body.appendChild(script);\n });\n}\n","export function count<T>(elements: Iterable<T>): number\n{\n if (Array.isArray(elements)) { return elements.length; }\n\n let _count = 0;\n for (const _ of elements) { _count += 1; }\n\n return _count;\n}\n\nexport function range(end: number): Generator<number, void>;\nexport function range(start: number, end: number): Generator<number, void>;\nexport function range(start: number, end: number, step: number): Generator<number, void>;\nexport function* range(start: number, end?: number, step = 1): Generator<number, void>\n{\n if (end === undefined)\n {\n end = start;\n start = 0;\n }\n\n if (start > end) { step = step ?? -1; }\n\n for (let index = start; index < end; index += step) { yield index; }\n}\n\nexport function shuffle<T>(iterable: Iterable<T>): T[]\n{\n const array = [...iterable];\n\n for (let index = array.length - 1; index > 0; index -= 1)\n {\n const jndex = Math.floor(Math.random() * (index + 1));\n\n [array[index], array[jndex]] = [array[jndex], array[index]];\n }\n\n return array;\n}\n\nexport function unique<T>(elements: Iterable<T>): T[]\n{\n return [...new Set(elements)];\n}\n\nexport function* zip<T, U>(first: Iterable<T>, second: Iterable<U>): Generator<[T, U], void>\n{\n const firstIterator = first[Symbol.iterator]();\n const secondIterator = second[Symbol.iterator]();\n\n while (true)\n {\n const firstResult = firstIterator.next();\n const secondResult = secondIterator.next();\n\n if ((firstResult.done) || (secondResult.done)) { break; }\n\n yield [firstResult.value, secondResult.value];\n }\n}\n","import { zip } from \"./iterator.js\";\n\nexport function average<T extends number>(values: Iterable<T>): number;\nexport function average<T extends number>(values: Iterable<T>, weights: Iterable<number>): number;\nexport function average<T extends number>(values: Iterable<T>, weights?: Iterable<number>): number\n{\n if (weights === undefined)\n {\n let _sum = 0;\n let _count = 0;\n\n for (const value of values)\n {\n _sum += value;\n _count += 1;\n }\n\n return _sum / _count;\n }\n\n let _sum = 0;\n let _count = 0;\n\n for (const [value, weight] of zip(values, weights))\n {\n _sum += value * weight;\n _count += weight;\n }\n\n return _sum / _count;\n}\n\nexport function hash(value: string): number\n{\n let hashedValue = 0;\n for (let i = 0; i < value.length; i++)\n {\n const char = value.charCodeAt(i);\n hashedValue = ((hashedValue << 5) - hashedValue) + char;\n hashedValue |= 0;\n }\n\n return hashedValue;\n}\n\nexport function random(): number;\nexport function random(max: number): number;\nexport function random(min: number, max: number): number;\nexport function random(min: number, max: number, isDecimal: boolean): number;\nexport function random(min: number, max: number, digits: number): number;\nexport function random(min: number = 1, max?: number, decimals?: boolean | number): number\n{\n if (max === undefined)\n {\n max = min;\n min = 0;\n }\n\n if (min === max)\n {\n return min;\n }\n\n let rounder: (value: number) => number;\n\n if (decimals === true)\n {\n rounder = (value) => value;\n }\n else if (decimals === undefined)\n {\n if (Math.abs(max - min) <= 1)\n {\n rounder = (value) => value;\n }\n else\n {\n rounder = Math.floor;\n }\n }\n else if (decimals === false)\n {\n rounder = Math.floor;\n }\n else\n {\n const digits = 10 ** decimals;\n\n rounder = (value) => Math.floor(value * digits) / digits;\n }\n\n return rounder(Math.random() * (max - min) + min);\n}\n\nexport function sum<T extends number>(values: Iterable<T>): number\n{\n let _sum = 0;\n for (const value of values) { _sum += value; }\n\n return _sum;\n}\n","export function capitalize(value: string): string\n{\n return `${value.charAt(0).toUpperCase()}${value.slice(1)}`;\n}\n","export const VERSION = \"1.1.8\";\n\nexport { DeferredPromise, Exception, JsonStorage, Subscribers } from \"./models/index.js\";\nexport {\n average,\n capitalize,\n count,\n delay,\n dateDifference,\n dateRange,\n dateRound,\n DateUnit,\n hash,\n loadScript,\n nextAnimationFrame,\n random,\n range,\n shuffle,\n sum,\n unique,\n zip\n\n} from \"./utils/index.js\";\n\nexport type {\n Constructor,\n FulfilledHandler,\n MaybePromise,\n PromiseExecutor,\n PromiseRejecter,\n PromiseResolver,\n RejectedHandler\n\n} from \"./types.js\";\n"],"names":["DeferredPromise","onFulfilled","onRejected","__publicField","_resolve","_reject","resolve","reject","onFinally","promise","Exception","error","exc","message","cause","name","JsonStorage","preferPersistence","storage","propertyName","defaultValue","propertyValue","newValue","encodedValue","persistent","Subscribers","subscriber","index","args","delay","milliseconds","nextAnimationFrame","DateUnit","dateDifference","start","end","unit","dateRange","offset","endTime","unixTime","dateRound","date","loadScript","scriptUrl","scriptType","script","count","elements","_count","_","range","step","shuffle","iterable","array","jndex","unique","zip","first","second","firstIterator","secondIterator","firstResult","secondResult","average","values","weights","_sum","value","weight","hash","hashedValue","i","char","random","min","max","decimals","rounder","digits","sum","capitalize","VERSION"],"mappings":";;;AAEA,MAAqBA,EACrB;AAAA,EAMW,YAAYC,GAA6CC,GAChE;AANU,IAAAC,EAAA;AACA,IAAAA,EAAA;AAEA,IAAAA,EAAA;AAIF,QAAAC,GACAC;AAEJ,SAAK,WAAW,IAAI,QAAW,CAACC,GAASC,MACzC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AAOD,EAAQ,KAAK,OAAA,KAAYF,IAAMD,KAAOA,CAAG;AACpD;AAEO,SAASK,EAAsBf,GACtC;AACI,MAAIE,IAAO;AACX,aAAWC,KAASH;AAAkB,IAAAE,KAAAC;AAE/B,SAAAD;AACX;ACpGO,SAASc,EAAWb,GAC3B;AACW,SAAA,GAAGA,EAAM,OAAO,CAAC,EAAE,aAAa,GAAGA,EAAM,MAAM,CAAC,CAAC;AAC5D;ACHO,MAAMc,IAAU;"}
|
|
1
|
+
{"version":3,"file":"core.js","sources":["../src/models/deferred-promise.ts","../src/models/exception.ts","../src/models/json-storage.ts","../src/models/smart-iterator.ts","../src/models/subscribers.ts","../src/utils/async.ts","../src/utils/date.ts","../src/utils/dom.ts","../src/utils/iterator.ts","../src/utils/math.ts","../src/utils/string.ts","../src/index.ts"],"sourcesContent":["import type { PromiseResolver, PromiseRejecter, FulfilledHandler, RejectedHandler } from \"../types.js\";\n\nexport default class DeferredPromise<T = void, E = unknown, F = T, R = never>\n{\n protected _resolve!: PromiseResolver<T>;\n protected _reject!: PromiseRejecter<E>;\n\n protected _promise: Promise<F | R>;\n\n public constructor(onFulfilled?: FulfilledHandler<T, F> | null, onRejected?: RejectedHandler<E, R> | null)\n {\n let _resolve: PromiseResolver<T>;\n let _reject: PromiseRejecter<E>;\n\n this._promise = new Promise<T>((resolve, reject) =>\n {\n _resolve = resolve as PromiseResolver<T>;\n _reject = reject as PromiseRejecter<E>;\n\n }).then(onFulfilled, onRejected);\n\n this._resolve = _resolve!;\n this._reject = _reject!;\n }\n\n public get resolve(): PromiseResolver<T>\n {\n return this._resolve;\n }\n public get reject(): PromiseRejecter<E>\n {\n return this._reject;\n }\n\n public then<N = F | R, H = R>(\n onFulfilled?: FulfilledHandler<F | R, N> | null,\n onRejected?: RejectedHandler<R, H> | null): Promise<N | H>\n {\n return this._promise.then(onFulfilled, onRejected);\n }\n public catch<H = R>(onRejected?: RejectedHandler<R, H> | null): Promise<F | R | H>\n {\n return this._promise.catch(onRejected);\n }\n public finally(onFinally?: (() => void) | null): Promise<F | R>\n {\n return this._promise.finally(onFinally);\n }\n\n public watch(promise: Promise<T>): this\n {\n promise.then(this.resolve, this.reject);\n\n return this;\n }\n\n public get [Symbol.toStringTag]()\n {\n return \"DeferredPromise\";\n }\n}\n","export default class Exception extends Error\n{\n public static FromUnknown(error: unknown): Exception\n {\n if (error instanceof Exception)\n {\n return error;\n }\n if (error instanceof Error)\n {\n const exc = new Exception(error.message);\n\n exc.stack = error.stack;\n exc.name = error.name;\n\n return exc;\n }\n\n return new Exception(`${error}`);\n }\n\n public constructor(message: string, cause?: unknown, name = \"Exception\")\n {\n super(message);\n\n this.cause = cause;\n this.name = name;\n\n if (cause)\n {\n if (cause instanceof Error)\n {\n this.stack += `\\n\\nCaused by ${cause.stack}`;\n }\n else\n {\n this.stack += `\\n\\nCaused by ${cause}`;\n }\n }\n }\n}\n","/* eslint-disable no-trailing-spaces */\n\n/**\n * A wrapper around the `Storage` API to store and retrieve JSON values.\n *\n * It allows to handle either the `sessionStorage` or the `localStorage`\n * storage at the same time, depending on the required use case.\n */\nexport default class JsonStorage\n{\n protected _preferPersistence: boolean;\n\n protected _volatile: Storage;\n protected _persistent: Storage;\n\n public constructor(preferPersistence = true)\n {\n this._preferPersistence = preferPersistence;\n\n this._volatile = window.sessionStorage;\n this._persistent = window.localStorage;\n }\n\n protected _get<T>(storage: Storage, propertyName: string): T | undefined;\n protected _get<T>(storage: Storage, propertyName: string, defaultValue: T): T;\n protected _get<T>(storage: Storage, propertyName: string, defaultValue?: T): T | undefined;\n protected _get<T>(storage: Storage, propertyName: string, defaultValue?: T): T | undefined\n {\n const propertyValue = storage.getItem(propertyName);\n if (propertyValue)\n {\n try\n {\n return JSON.parse(propertyValue);\n }\n catch (error)\n {\n // eslint-disable-next-line no-console\n console.warn(\n `The \"${propertyValue}\" value for \"${propertyName}\"` +\n \" property cannot be parsed. Clearing the storage...\");\n\n storage.removeItem(propertyName);\n }\n }\n\n return defaultValue;\n }\n protected _set<T>(storage: Storage, propertyName: string, newValue?: T): void\n {\n const encodedValue = JSON.stringify(newValue);\n if (encodedValue)\n {\n storage.setItem(propertyName, encodedValue);\n }\n else\n {\n storage.removeItem(propertyName);\n }\n }\n\n /**\n * Retrieves the value with the specified name from the corresponding storage.\n *\n * @param propertyName The name of the property to retrieve.\n * @param defaultValue The default value to return if the property does not exist.\n * @param persistent Whether to use the persistent `localStorage` or the volatile `sessionStorage`.\n *\n * @returns The value of the property or the default value if the property does not exist.\n */\n public get<T>(propertyName: string, defaultValue: undefined, persistent?: boolean): T | undefined;\n public get<T>(propertyName: string, defaultValue: T, persistent?: boolean): T ;\n public get<T>(propertyName: string, defaultValue?: T, persistent?: boolean): T | undefined;\n public get<T>(propertyName: string, defaultValue?: T, persistent = this._preferPersistence): T | undefined\n {\n const storage = persistent ? this._persistent : this._volatile;\n\n return this._get<T>(storage, propertyName, defaultValue);\n }\n /**\n * Retrieves the value with the specified name from the volatile `sessionStorage`.\n *\n * @param propertyName The name of the property to retrieve.\n * @param defaultValue The default value to return if the property does not exist.\n *\n * @returns The value of the property or the default value if the property does not exist.\n */\n public recall<T>(propertyName: string): T | undefined;\n public recall<T>(propertyName: string, defaultValue: T): T;\n public recall<T>(propertyName: string, defaultValue?: T): T | undefined;\n public recall<T>(propertyName: string, defaultValue?: T): T | undefined\n {\n return this._get<T>(this._volatile, propertyName, defaultValue);\n }\n /**\n * Retrieves the value with the specified name looking first in the\n * volatile `sessionStorage` and then in the persistent `localStorage`.\n *\n * @param propertyName The name of the property to retrieve.\n * @param defaultValue The default value to return if the property does not exist.\n *\n * @returns The value of the property or the default value if the property does not exist.\n */\n public retrieve<T>(propertyName: string): T | undefined;\n public retrieve<T>(propertyName: string, defaultValue: T): T;\n public retrieve<T>(propertyName: string, defaultValue?: T): T | undefined;\n public retrieve<T>(propertyName: string, defaultValue?: T): T | undefined\n {\n return this.recall<T>(propertyName) ?? this.read<T>(propertyName, defaultValue);\n }\n /**\n * Retrieves the value with the specified name from the persistent `localStorage`.\n *\n * @param propertyName The name of the property to retrieve.\n * @param defaultValue The default value to return if the property does not exist.\n *\n * @returns The value of the property or the default value if the property does not exist.\n */\n public read<T>(propertyName: string): T | undefined;\n public read<T>(propertyName: string, defaultValue: T): T;\n public read<T>(propertyName: string, defaultValue?: T): T | undefined;\n public read<T>(propertyName: string, defaultValue?: T): T | undefined\n {\n return this._get<T>(this._persistent, propertyName, defaultValue);\n }\n\n /**\n * Checks whether the property with the specified name exists in the corresponding storage.\n *\n * @param propertyName The name of the property to check.\n * @param persistent Whether to use the persistent `localStorage` or the volatile `sessionStorage`.\n *\n * @returns `true` if the property exists, `false` otherwise.\n */\n public has(propertyName: string, persistent?: boolean): boolean\n {\n const storage = persistent ? this._persistent : this._volatile;\n\n return storage.getItem(propertyName) !== null;\n }\n /**\n * Checks whether the property with the specified name exists in the volatile `sessionStorage`.\n *\n * @param propertyName The name of the property to check.\n *\n * @returns `true` if the property exists, `false` otherwise.\n */\n public knows(propertyName: string): boolean\n {\n return this._volatile.getItem(propertyName) !== null;\n }\n /**\n * Checks whether the property with the specified name exists looking first in the\n * volatile `sessionStorage` and then in the persistent `localStorage`.\n *\n * @param propertyName The name of the property to check.\n *\n * @returns `true` if the property exists, `false` otherwise.\n */\n public find(propertyName: string): boolean\n {\n return this.knows(propertyName) ?? this.exists(propertyName);\n }\n /**\n * Checks whether the property with the specified name exists in the persistent `localStorage`.\n *\n * @param propertyName The name of the property to check.\n *\n * @returns `true` if the property exists, `false` otherwise.\n */\n public exists(propertyName: string): boolean\n {\n return this._persistent.getItem(propertyName) !== null;\n }\n\n /**\n * Sets the value with the specified name in the corresponding storage.\n * If the value is `undefined`, the property is removed from the storage.\n *\n * @param propertyName The name of the property to set.\n * @param newValue The new value to set.\n * @param persistent Whether to use the persistent `localStorage` or the volatile `sessionStorage`.\n */\n public set<T>(propertyName: string, newValue?: T, persistent = this._preferPersistence): void\n {\n const storage = persistent ? this._persistent : this._volatile;\n\n this._set<T>(storage, propertyName, newValue);\n }\n /**\n * Sets the value with the specified name in the volatile `sessionStorage`.\n * If the value is `undefined`, the property is removed from the storage.\n *\n * @param propertyName The name of the property to set.\n * @param newValue The new value to set.\n */\n public remember<T>(propertyName: string, newValue?: T): void\n {\n this._set<T>(this._volatile, propertyName, newValue);\n }\n /**\n * Sets the value with the specified name in the persistent `localStorage`.\n * If the value is `undefined`, the property is removed from the storage.\n *\n * @param propertyName The name of the property to set.\n * @param newValue The new value to set.\n */\n public write<T>(propertyName: string, newValue?: T): void\n {\n this._set<T>(this._persistent, propertyName, newValue);\n }\n\n /**\n * Removes the value with the specified name from the volatile `sessionStorage`.\n *\n * @param propertyName The name of the property to remove.\n */\n public forget(propertyName: string): void\n {\n this._volatile.removeItem(propertyName);\n }\n /**\n * Removes the value with the specified name from the persistent `localStorage`.\n *\n * @param propertyName The name of the property to remove.\n */\n public erase(propertyName: string): void\n {\n this._persistent.removeItem(propertyName);\n }\n /**\n * Removes the value with the specified name from all the storages.\n *\n * @param propertyName The name of the property to remove.\n */\n public clear(propertyName: string): void\n {\n this._volatile.removeItem(propertyName);\n this._persistent.removeItem(propertyName);\n }\n}\n","import type { GeneratorFunction } from \"../types.js\";\n\nexport default class SmartIterator<T, R = void, N = undefined> implements Iterator<T, R, N>\n{\n protected _iterator: Iterator<T, R, N>;\n\n public return?: (value?: R) => IteratorResult<T, R>;\n public throw?: (error?: unknown) => IteratorResult<T, R>;\n\n public constructor(iterable: Iterable<T>);\n public constructor(iterator: Iterator<T, R, N>);\n public constructor(generatorFn: GeneratorFunction<T, R, N>);\n public constructor(iterable: Iterable<T> | Iterator<T, R, N> | GeneratorFunction<T, R, N>)\n {\n if (iterable instanceof Function)\n {\n this._iterator = iterable();\n }\n else if (Symbol.iterator in iterable)\n {\n this._iterator = iterable[Symbol.iterator]() as Iterator<T, R, N>;\n }\n else\n {\n this._iterator = iterable;\n }\n\n if (this._iterator.return) { this.return = (value?: R) => this._iterator.return!(value); }\n if (this._iterator.throw) { this.throw = (error?: unknown) => this._iterator.throw!(error); }\n }\n\n public filter(callback: (value: T, index: number) => boolean): SmartIterator<T, R, N>\n {\n let index = 0;\n const iterator = this._iterator;\n\n return new SmartIterator<T, R, N>({\n *[Symbol.iterator]()\n {\n while (true)\n {\n const result = iterator.next();\n if (result.done) { return result.value; }\n\n if (callback(result.value, index))\n {\n yield result.value;\n }\n\n index += 1;\n }\n }\n });\n }\n public map<V>(callback: (value: T, index: number) => V): SmartIterator<V, R>\n {\n let index = 0;\n const iterator = this._iterator;\n\n return new SmartIterator<V, R>({\n *[Symbol.iterator]()\n {\n while (true)\n {\n const result = iterator.next();\n if (result.done) { return result.value; }\n\n yield callback(result.value, index);\n\n index += 1;\n }\n }\n });\n }\n public reduce<U>(callback: (accumulator: U, value: T, index: number) => U, initialValue: U): U\n {\n let index = 0;\n let accumulator = initialValue;\n\n // eslint-disable-next-line no-constant-condition\n while (true)\n {\n const result = this._iterator.next();\n if (result.done) { return accumulator; }\n\n accumulator = callback(accumulator, result.value, index);\n\n index += 1;\n }\n }\n\n public forEach(callback: (value: T, index: number) => void): void\n {\n let index = 0;\n\n // eslint-disable-next-line no-constant-condition\n while (true)\n {\n const result = this._iterator.next();\n if (result.done) { return; }\n\n callback(result.value, index);\n\n index += 1;\n }\n }\n\n public next(...values: N extends undefined ? [] : [N]): IteratorResult<T, R>\n {\n return this._iterator.next(...values);\n }\n\n public toArray(): T[]\n {\n return [...this];\n }\n\n public [Symbol.iterator](): SmartIterator<T, R, N> { return this; }\n}\n","import Exception from \"./exception.js\";\n\nexport default class Subscribers<P extends unknown[] = [], R = void, T extends (...args: P) => R = (...args: P) => R>\n{\n protected _subscribers: T[];\n\n public constructor()\n {\n this._subscribers = [];\n }\n\n public add(subscriber: T): void\n {\n this._subscribers.push(subscriber);\n }\n public remove(subscriber: T): void\n {\n const index = this._subscribers.indexOf(subscriber);\n if (index < 0)\n {\n throw new Exception(\"Unable to remove the requested subscriber. It was not found.\");\n }\n\n this._subscribers.splice(index, 1);\n }\n\n public call(...args: P): R[]\n {\n return this._subscribers\n .slice()\n .map((subscriber) => subscriber(...args));\n }\n}\n","export async function delay(milliseconds: number): Promise<void>\n{\n return new Promise<void>((resolve, reject) => setTimeout(resolve, milliseconds));\n}\n\nexport async function nextAnimationFrame(): Promise<void>\n{\n return new Promise<void>((resolve, reject) => requestAnimationFrame(() => resolve()));\n}\n","import { SmartIterator } from \"../models/index.js\";\n\nexport enum DateUnit\n{\n Second = 1000,\n Minute = 60 * Second,\n Hour = 60 * Minute,\n Day = 24 * Hour,\n Week = 7 * Day,\n Month = 30 * Day,\n Year = 365 * Day\n}\n\nexport function dateDifference(start: Date, end: Date, unit = DateUnit.Day): number\n{\n return Math.floor((end.getTime() - start.getTime()) / unit);\n}\n\nexport function dateRange(start: Date, end: Date, offset = DateUnit.Day): SmartIterator<Date>\n{\n return new SmartIterator<Date>(function* ()\n {\n const endTime = end.getTime();\n\n let unixTime: number = start.getTime();\n while (unixTime < endTime)\n {\n yield new Date(unixTime);\n\n unixTime += offset;\n }\n });\n}\n\nexport function dateRound(date: Date, unit = DateUnit.Day): Date\n{\n return new Date(Math.floor(date.getTime() / unit) * unit);\n}\n","export async function loadScript(scriptUrl: string, scriptType = \"text/javascript\"): Promise<void>\n{\n return new Promise<void>((resolve, reject) =>\n {\n const script = document.createElement(\"script\");\n\n script.async = true;\n script.defer = true;\n script.src = scriptUrl;\n script.type = scriptType;\n\n script.onload = () => resolve();\n script.onerror = () => reject();\n\n document.body.appendChild(script);\n });\n}\n","import { SmartIterator } from \"../models/index.js\";\n\nexport function count<T>(elements: Iterable<T>): number\n{\n if (Array.isArray(elements)) { return elements.length; }\n\n let _count = 0;\n for (const _ of elements) { _count += 1; }\n\n return _count;\n}\n\nexport function range(end: number): SmartIterator<number>;\nexport function range(start: number, end: number): SmartIterator<number>;\nexport function range(start: number, end: number, step: number): SmartIterator<number>;\nexport function range(start: number, end?: number, step = 1): SmartIterator<number>\n{\n return new SmartIterator<number>(function* ()\n {\n if (end === undefined)\n {\n end = start;\n start = 0;\n }\n\n if (start > end) { step = step ?? -1; }\n\n for (let index = start; index < end; index += step) { yield index; }\n });\n}\n\nexport function shuffle<T>(iterable: Iterable<T>): T[]\n{\n const array = [...iterable];\n\n for (let index = array.length - 1; index > 0; index -= 1)\n {\n const jndex = Math.floor(Math.random() * (index + 1));\n\n [array[index], array[jndex]] = [array[jndex], array[index]];\n }\n\n return array;\n}\n\nexport function unique<T>(elements: Iterable<T>): SmartIterator<T>\n{\n return new SmartIterator<T>(function* ()\n {\n const seen = new Set<T>();\n\n for (const element of elements)\n {\n if (seen.has(element)) { continue; }\n\n seen.add(element);\n\n yield element;\n }\n });\n}\n\nexport function zip<T, U>(first: Iterable<T>, second: Iterable<U>): SmartIterator<[T, U]>\n{\n return new SmartIterator<[T, U]>(function* ()\n {\n const firstIterator = first[Symbol.iterator]();\n const secondIterator = second[Symbol.iterator]();\n\n while (true)\n {\n const firstResult = firstIterator.next();\n const secondResult = secondIterator.next();\n\n if ((firstResult.done) || (secondResult.done)) { break; }\n\n yield [firstResult.value, secondResult.value];\n }\n });\n}\n","import { zip } from \"./iterator.js\";\n\nexport function average<T extends number>(values: Iterable<T>): number;\nexport function average<T extends number>(values: Iterable<T>, weights: Iterable<number>): number;\nexport function average<T extends number>(values: Iterable<T>, weights?: Iterable<number>): number\n{\n if (weights === undefined)\n {\n let _sum = 0;\n let _count = 0;\n\n for (const value of values)\n {\n _sum += value;\n _count += 1;\n }\n\n return _sum / _count;\n }\n\n let _sum = 0;\n let _count = 0;\n\n for (const [value, weight] of zip(values, weights))\n {\n _sum += value * weight;\n _count += weight;\n }\n\n return _sum / _count;\n}\n\nexport function hash(value: string): number\n{\n let hashedValue = 0;\n for (let i = 0; i < value.length; i++)\n {\n const char = value.charCodeAt(i);\n hashedValue = ((hashedValue << 5) - hashedValue) + char;\n hashedValue |= 0;\n }\n\n return hashedValue;\n}\n\nexport function random(): number;\nexport function random(max: number): number;\nexport function random(min: number, max: number): number;\nexport function random(min: number, max: number, isDecimal: boolean): number;\nexport function random(min: number, max: number, digits: number): number;\nexport function random(min: number = 1, max?: number, decimals?: boolean | number): number\n{\n if (max === undefined)\n {\n max = min;\n min = 0;\n }\n\n if (min === max)\n {\n return min;\n }\n\n let rounder: (value: number) => number;\n\n if (decimals === true)\n {\n rounder = (value) => value;\n }\n else if (decimals === undefined)\n {\n if (Math.abs(max - min) <= 1)\n {\n rounder = (value) => value;\n }\n else\n {\n rounder = Math.floor;\n }\n }\n else if (decimals === false)\n {\n rounder = Math.floor;\n }\n else\n {\n const digits = 10 ** decimals;\n\n rounder = (value) => Math.floor(value * digits) / digits;\n }\n\n return rounder(Math.random() * (max - min) + min);\n}\n\nexport function sum<T extends number>(values: Iterable<T>): number\n{\n let _sum = 0;\n for (const value of values) { _sum += value; }\n\n return _sum;\n}\n","export function capitalize(value: string): string\n{\n return `${value.charAt(0).toUpperCase()}${value.slice(1)}`;\n}\n","export const VERSION = \"1.2.0-rc.2\";\n\nexport { DeferredPromise, Exception, JsonStorage, SmartIterator, Subscribers } from \"./models/index.js\";\nexport {\n average,\n capitalize,\n count,\n delay,\n dateDifference,\n dateRange,\n dateRound,\n DateUnit,\n hash,\n loadScript,\n nextAnimationFrame,\n random,\n range,\n shuffle,\n sum,\n unique,\n zip\n\n} from \"./utils/index.js\";\n\nexport type {\n Constructor,\n FulfilledHandler,\n MaybePromise,\n PromiseExecutor,\n PromiseRejecter,\n PromiseResolver,\n RejectedHandler\n\n} from \"./types.js\";\n"],"names":["DeferredPromise","onFulfilled","onRejected","__publicField","_resolve","_reject","resolve","reject","onFinally","promise","Exception","error","exc","message","cause","name","JsonStorage","preferPersistence","storage","propertyName","defaultValue","propertyValue","newValue","encodedValue","persistent","SmartIterator","iterable","value","callback","index","iterator","result","initialValue","accumulator","values","Subscribers","subscriber","args","delay","milliseconds","nextAnimationFrame","DateUnit","dateDifference","start","end","unit","dateRange","offset","endTime","unixTime","dateRound","date","loadScript","scriptUrl","scriptType","script","count","elements","_count","_","range","step","shuffle","array","jndex","unique","seen","element","zip","first","second","firstIterator","secondIterator","firstResult","secondResult","average","weights","_sum","weight","hash","hashedValue","i","char","random","min","max","decimals","rounder","digits","sum","capitalize","VERSION"],"mappings":";;;AAEA,MAAqBA,EACrB;AAAA,EAMW,YAAYC,GAA6CC,GAChE;AANU,IAAAC,EAAA;AACA,IAAAA,EAAA;AAEA,IAAAA,EAAA;AAIF,QAAAC,GACAC;AAEJ,SAAK,WAAW,IAAI,QAAW,CAACC,GAASC,MACzC;AACe,MAAAH,IAAAE,GACDD,IAAAE;AAAA,IAEb,CAAA,EAAE,KAAKN,GAAaC,CAAU,GAE/B,KAAK,WAAWE,GAChB,KAAK,UAAUC;AAAA,EACnB;AAAA,EAEA,IAAW,UACX;AACI,WAAO,KAAK;AAAA,EAChB;AAAA,EACA,IAAW,SACX;AACI,WAAO,KAAK;AAAA,EAChB;AAAA,EAEO,KACHJ,GACAC,GACJ;AACI,WAAO,KAAK,SAAS,KAAKD,GAAaC,CAAU;AAAA,EACrD;AAAA,EACO,MAAaA,GACpB;AACW,WAAA,KAAK,SAAS,MAAMA,CAAU;AAAA,EACzC;AAAA,EACO,QAAQM,GACf;AACW,WAAA,KAAK,SAAS,QAAQA,CAAS;AAAA,EAC1C;AAAA,EAEO,MAAMC,GACb;AACI,WAAAA,EAAQ,KAAK,KAAK,SAAS,KAAK,MAAM,GAE/B;AAAA,EACX;AAAA,EAEA,KAAY,OAAO,WAAW,IAC9B;AACW,WAAA;AAAA,EACX;AACJ;AC5DA,MAAqBC,UAAkB,MACvC;AAAA,EACI,OAAc,YAAYC,GAC1B;AACI,QAAIA,aAAiBD;AAEV,aAAAC;AAEX,QAAIA,aAAiB,OACrB;AACI,YAAMC,IAAM,IAAIF,EAAUC,EAAM,OAAO;AAEvC,aAAAC,EAAI,QAAQD,EAAM,OAClBC,EAAI,OAAOD,EAAM,MAEVC;AAAA,IACX;AAEA,WAAO,IAAIF,EAAU,GAAGC,C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AkD;AACX;ACpGO,SAASa,EAAW/D,GAC3B;AACW,SAAA,GAAGA,EAAM,OAAO,CAAC,EAAE,aAAa,GAAGA,EAAM,MAAM,CAAC,CAAC;AAC5D;ACHO,MAAMgE,IAAU;"}
|
package/dist/core.umd.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(s,u){typeof exports=="object"&&typeof module<"u"?u(exports):typeof define=="function"&&define.amd?define(["exports"],u):(s=typeof globalThis<"u"?globalThis:s||self,u(s.Core={}))})(this,function(s){"use strict";var E=Object.defineProperty;var $=(s,u,c)=>u in s?E(s,u,{enumerable:!0,configurable:!0,writable:!0,value:c}):s[u]=c;var a=(s,u,c)=>($(s,typeof u!="symbol"?u+"":u,c),c);class u{constructor(e,t){a(this,"_resolve");a(this,"_reject");a(this,"_promise");let i,n;this._promise=new Promise((o,h)=>{i=o,n=h}).then(e,t),this._resolve=i,this._reject=n}get resolve(){return this._resolve}get reject(){return this._reject}then(e,t){return this._promise.then(e,t)}catch(e){return this._promise.catch(e)}finally(e){return this._promise.finally(e)}watch(e){return e.then(this.resolve,this.reject),this}get[Symbol.toStringTag](){return"DeferredPromise"}}class c extends Error{static FromUnknown(e){if(e instanceof c)return e;if(e instanceof Error){const t=new c(e.message);return t.stack=e.stack,t.name=e.name,t}return new c(`${e}`)}constructor(e,t,i="Exception"){super(e),this.cause=t,this.name=i,t&&(t instanceof Error?this.stack+=`
|
|
2
2
|
|
|
3
3
|
Caused by ${t.stack}`:this.stack+=`
|
|
4
4
|
|
|
5
|
-
Caused by ${t}`)}}class
|
|
5
|
+
Caused by ${t}`)}}class _{constructor(e=!0){a(this,"_preferPersistence");a(this,"_volatile");a(this,"_persistent");this._preferPersistence=e,this._volatile=window.sessionStorage,this._persistent=window.localStorage}_get(e,t,i){const n=e.getItem(t);if(n)try{return JSON.parse(n)}catch{console.warn(`The "${n}" value for "${t}" property cannot be parsed. Clearing the storage...`),e.removeItem(t)}return i}_set(e,t,i){const n=JSON.stringify(i);n?e.setItem(t,n):e.removeItem(t)}get(e,t,i=this._preferPersistence){const n=i?this._persistent:this._volatile;return this._get(n,e,t)}recall(e,t){return this._get(this._volatile,e,t)}retrieve(e,t){return this.recall(e)??this.read(e,t)}read(e,t){return this._get(this._persistent,e,t)}has(e,t){return(t?this._persistent:this._volatile).getItem(e)!==null}knows(e){return this._volatile.getItem(e)!==null}find(e){return this.knows(e)??this.exists(e)}exists(e){return this._persistent.getItem(e)!==null}set(e,t,i=this._preferPersistence){const n=i?this._persistent:this._volatile;this._set(n,e,t)}remember(e,t){this._set(this._volatile,e,t)}write(e,t){this._set(this._persistent,e,t)}forget(e){this._volatile.removeItem(e)}erase(e){this._persistent.removeItem(e)}clear(e){this._volatile.removeItem(e),this._persistent.removeItem(e)}}class l{constructor(e){a(this,"_iterator");a(this,"return");a(this,"throw");e instanceof Function?this._iterator=e():Symbol.iterator in e?this._iterator=e[Symbol.iterator]():this._iterator=e,this._iterator.return&&(this.return=t=>this._iterator.return(t)),this._iterator.throw&&(this.throw=t=>this._iterator.throw(t))}filter(e){let t=0;const i=this._iterator;return new l({*[Symbol.iterator](){for(;;){const n=i.next();if(n.done)return n.value;e(n.value,t)&&(yield n.value),t+=1}}})}map(e){let t=0;const i=this._iterator;return new l({*[Symbol.iterator](){for(;;){const n=i.next();if(n.done)return n.value;yield e(n.value,t),t+=1}}})}reduce(e,t){let i=0,n=t;for(;;){const o=this._iterator.next();if(o.done)return n;n=e(n,o.value,i),i+=1}}forEach(e){let t=0;for(;;){const i=this._iterator.next();if(i.done)return;e(i.value,t),t+=1}}next(...e){return this._iterator.next(...e)}toArray(){return[...this]}[Symbol.iterator](){return this}}class m{constructor(){a(this,"_subscribers");this._subscribers=[]}add(e){this._subscribers.push(e)}remove(e){const t=this._subscribers.indexOf(e);if(t<0)throw new c("Unable to remove the requested subscriber. It was not found.");this._subscribers.splice(t,1)}call(...e){return this._subscribers.slice().map(t=>t(...e))}}async function v(r){return new Promise((e,t)=>setTimeout(e,r))}async function g(){return new Promise((r,e)=>requestAnimationFrame(()=>r()))}var f=(r=>(r[r.Second=1e3]="Second",r[r.Minute=6e4]="Minute",r[r.Hour=36e5]="Hour",r[r.Day=864e5]="Day",r[r.Week=6048e5]="Week",r[r.Month=2592e6]="Month",r[r.Year=31536e6]="Year",r))(f||{});function w(r,e,t=864e5){return Math.floor((e.getTime()-r.getTime())/t)}function y(r,e,t=864e5){return new l(function*(){const i=e.getTime();let n=r.getTime();for(;n<i;)yield new Date(n),n+=t})}function b(r,e=864e5){return new Date(Math.floor(r.getTime()/e)*e)}async function S(r,e="text/javascript"){return new Promise((t,i)=>{const n=document.createElement("script");n.async=!0,n.defer=!0,n.src=r,n.type=e,n.onload=()=>t(),n.onerror=()=>i(),document.body.appendChild(n)})}function I(r){if(Array.isArray(r))return r.length;let e=0;for(const t of r)e+=1;return e}function p(r,e,t=1){return new l(function*(){e===void 0&&(e=r,r=0),r>e&&(t=t??-1);for(let i=r;i<e;i+=t)yield i})}function M(r){const e=[...r];for(let t=e.length-1;t>0;t-=1){const i=Math.floor(Math.random()*(t+1));[e[t],e[i]]=[e[i],e[t]]}return e}function T(r){return new l(function*(){const e=new Set;for(const t of r)e.has(t)||(e.add(t),yield t)})}function d(r,e){return new l(function*(){const t=r[Symbol.iterator](),i=e[Symbol.iterator]();for(;;){const n=t.next(),o=i.next();if(n.done||o.done)break;yield[n.value,o.value]}})}function j(r,e){if(e===void 0){let n=0,o=0;for(const h of r)n+=h,o+=1;return n/o}let t=0,i=0;for(const[n,o]of d(r,e))t+=n*o,i+=o;return t/i}function P(r){let e=0;for(let t=0;t<r.length;t++){const i=r.charCodeAt(t);e=(e<<5)-e+i,e|=0}return e}function k(r=1,e,t){if(e===void 0&&(e=r,r=0),r===e)return r;let i;if(t===!0)i=n=>n;else if(t===void 0)Math.abs(e-r)<=1?i=n=>n:i=Math.floor;else if(t===!1)i=Math.floor;else{const n=10**t;i=o=>Math.floor(o*n)/n}return i(Math.random()*(e-r)+r)}function A(r){let e=0;for(const t of r)e+=t;return e}function R(r){return`${r.charAt(0).toUpperCase()}${r.slice(1)}`}const C="1.2.0-rc.2";s.DateUnit=f,s.DeferredPromise=u,s.Exception=c,s.JsonStorage=_,s.SmartIterator=l,s.Subscribers=m,s.VERSION=C,s.average=j,s.capitalize=R,s.count=I,s.dateDifference=w,s.dateRange=y,s.dateRound=b,s.delay=v,s.hash=P,s.loadScript=S,s.nextAnimationFrame=g,s.random=k,s.range=p,s.shuffle=M,s.sum=A,s.unique=T,s.zip=d,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})});
|
|
6
6
|
//# sourceMappingURL=core.umd.cjs.map
|
package/dist/core.umd.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.umd.cjs","sources":["../src/models/deferred-promise.ts","../src/models/exception.ts","../src/models/json-storage.ts","../src/models/subscribers.ts","../src/utils/async.ts","../src/utils/date.ts","../src/utils/dom.ts","../src/utils/iterator.ts","../src/utils/math.ts","../src/utils/string.ts","../src/index.ts"],"sourcesContent":["import type { PromiseResolver, PromiseRejecter, FulfilledHandler, RejectedHandler } from \"../types.js\";\n\nexport default class DeferredPromise<T = void, E = unknown, F = T, R = never>\n{\n protected _resolve!: PromiseResolver<T>;\n protected _reject!: PromiseRejecter<E>;\n\n protected _promise: Promise<F | R>;\n\n public constructor(onFulfilled?: FulfilledHandler<T, F> | null, onRejected?: RejectedHandler<E, R> | null)\n {\n let _resolve: PromiseResolver<T>;\n let _reject: PromiseRejecter<E>;\n\n this._promise = new Promise<T>((resolve, reject) =>\n {\n _resolve = resolve as PromiseResolver<T>;\n _reject = reject as PromiseRejecter<E>;\n\n }).then(onFulfilled, onRejected);\n\n this._resolve = _resolve!;\n this._reject = _reject!;\n }\n\n public get resolve(): PromiseResolver<T>\n {\n return this._resolve;\n }\n public get reject(): PromiseRejecter<E>\n {\n return this._reject;\n }\n\n public then<N = F | R, H = R>(\n onFulfilled?: FulfilledHandler<F | R, N> | null,\n onRejected?: RejectedHandler<R, H> | null): Promise<N | H>\n {\n return this._promise.then(onFulfilled, onRejected);\n }\n public catch<H = R>(onRejected?: RejectedHandler<R, H> | null): Promise<F | R | H>\n {\n return this._promise.catch(onRejected);\n }\n public finally(onFinally?: (() => void) | null): Promise<F | R>\n {\n return this._promise.finally(onFinally);\n }\n\n public watch(promise: Promise<T>): this\n {\n promise.then(this.resolve, this.reject);\n\n return this;\n }\n\n public get [Symbol.toStringTag]()\n {\n return \"DeferredPromise\";\n }\n}\n","export default class Exception extends Error\n{\n public static FromUnknown(error: unknown): Exception\n {\n if (error instanceof Exception)\n {\n return error;\n }\n if (error instanceof Error)\n {\n const exc = new Exception(error.message);\n\n exc.stack = error.stack;\n exc.name = error.name;\n\n return exc;\n }\n\n return new Exception(`${error}`);\n }\n\n public constructor(message: string, cause?: unknown, name = \"Exception\")\n {\n super(message);\n\n this.cause = cause;\n this.name = name;\n\n if (cause)\n {\n if (cause instanceof Error)\n {\n this.stack += `\\n\\nCaused by ${cause.stack}`;\n }\n else\n {\n this.stack += `\\n\\nCaused by ${cause}`;\n }\n }\n }\n}\n","/* eslint-disable no-trailing-spaces */\n\n/**\n * A wrapper around the `Storage` API to store and retrieve JSON values.\n *\n * It allows to handle either the `sessionStorage` or the `localStorage`\n * storage at the same time, depending on the required use case.\n */\nexport default class JsonStorage\n{\n protected _preferPersistence: boolean;\n\n protected _volatile: Storage;\n protected _persistent: Storage;\n\n public constructor(preferPersistence = true)\n {\n this._preferPersistence = preferPersistence;\n\n this._volatile = window.sessionStorage;\n this._persistent = window.localStorage;\n }\n\n protected _get<T>(storage: Storage, propertyName: string): T | undefined;\n protected _get<T>(storage: Storage, propertyName: string, defaultValue: T): T;\n protected _get<T>(storage: Storage, propertyName: string, defaultValue?: T): T | undefined;\n protected _get<T>(storage: Storage, propertyName: string, defaultValue?: T): T | undefined\n {\n const propertyValue = storage.getItem(propertyName);\n if (propertyValue)\n {\n try\n {\n return JSON.parse(propertyValue);\n }\n catch (error)\n {\n // eslint-disable-next-line no-console\n console.warn(\n `The \"${propertyValue}\" value for \"${propertyName}\"` +\n \" property cannot be parsed. Clearing the storage...\");\n\n storage.removeItem(propertyName);\n }\n }\n\n return defaultValue;\n }\n protected _set<T>(storage: Storage, propertyName: string, newValue?: T): void\n {\n const encodedValue = JSON.stringify(newValue);\n if (encodedValue)\n {\n storage.setItem(propertyName, encodedValue);\n }\n else\n {\n storage.removeItem(propertyName);\n }\n }\n\n /**\n * Retrieves the value with the specified name from the corresponding storage.\n *\n * @param propertyName The name of the property to retrieve.\n * @param defaultValue The default value to return if the property does not exist.\n * @param persistent Whether to use the persistent `localStorage` or the volatile `sessionStorage`.\n *\n * @returns The value of the property or the default value if the property does not exist.\n */\n public get<T>(propertyName: string, defaultValue: undefined, persistent?: boolean): T | undefined;\n public get<T>(propertyName: string, defaultValue: T, persistent?: boolean): T ;\n public get<T>(propertyName: string, defaultValue?: T, persistent?: boolean): T | undefined;\n public get<T>(propertyName: string, defaultValue?: T, persistent = this._preferPersistence): T | undefined\n {\n const storage = persistent ? this._persistent : this._volatile;\n\n return this._get<T>(storage, propertyName, defaultValue);\n }\n /**\n * Retrieves the value with the specified name from the volatile `sessionStorage`.\n *\n * @param propertyName The name of the property to retrieve.\n * @param defaultValue The default value to return if the property does not exist.\n *\n * @returns The value of the property or the default value if the property does not exist.\n */\n public recall<T>(propertyName: string): T | undefined;\n public recall<T>(propertyName: string, defaultValue: T): T;\n public recall<T>(propertyName: string, defaultValue?: T): T | undefined;\n public recall<T>(propertyName: string, defaultValue?: T): T | undefined\n {\n return this._get<T>(this._volatile, propertyName, defaultValue);\n }\n /**\n * Retrieves the value with the specified name looking first in the\n * volatile `sessionStorage` and then in the persistent `localStorage`.\n *\n * @param propertyName The name of the property to retrieve.\n * @param defaultValue The default value to return if the property does not exist.\n *\n * @returns The value of the property or the default value if the property does not exist.\n */\n public retrieve<T>(propertyName: string): T | undefined;\n public retrieve<T>(propertyName: string, defaultValue: T): T;\n public retrieve<T>(propertyName: string, defaultValue?: T): T | undefined;\n public retrieve<T>(propertyName: string, defaultValue?: T): T | undefined\n {\n return this.recall<T>(propertyName) ?? this.read<T>(propertyName, defaultValue);\n }\n /**\n * Retrieves the value with the specified name from the persistent `localStorage`.\n *\n * @param propertyName The name of the property to retrieve.\n * @param defaultValue The default value to return if the property does not exist.\n *\n * @returns The value of the property or the default value if the property does not exist.\n */\n public read<T>(propertyName: string): T | undefined;\n public read<T>(propertyName: string, defaultValue: T): T;\n public read<T>(propertyName: string, defaultValue?: T): T | undefined;\n public read<T>(propertyName: string, defaultValue?: T): T | undefined\n {\n return this._get<T>(this._persistent, propertyName, defaultValue);\n }\n\n /**\n * Checks whether the property with the specified name exists in the corresponding storage.\n *\n * @param propertyName The name of the property to check.\n * @param persistent Whether to use the persistent `localStorage` or the volatile `sessionStorage`.\n *\n * @returns `true` if the property exists, `false` otherwise.\n */\n public has(propertyName: string, persistent?: boolean): boolean\n {\n const storage = persistent ? this._persistent : this._volatile;\n\n return storage.getItem(propertyName) !== null;\n }\n /**\n * Checks whether the property with the specified name exists in the volatile `sessionStorage`.\n *\n * @param propertyName The name of the property to check.\n *\n * @returns `true` if the property exists, `false` otherwise.\n */\n public knows(propertyName: string): boolean\n {\n return this._volatile.getItem(propertyName) !== null;\n }\n /**\n * Checks whether the property with the specified name exists looking first in the\n * volatile `sessionStorage` and then in the persistent `localStorage`.\n *\n * @param propertyName The name of the property to check.\n *\n * @returns `true` if the property exists, `false` otherwise.\n */\n public find(propertyName: string): boolean\n {\n return this.knows(propertyName) ?? this.exists(propertyName);\n }\n /**\n * Checks whether the property with the specified name exists in the persistent `localStorage`.\n *\n * @param propertyName The name of the property to check.\n *\n * @returns `true` if the property exists, `false` otherwise.\n */\n public exists(propertyName: string): boolean\n {\n return this._persistent.getItem(propertyName) !== null;\n }\n\n /**\n * Sets the value with the specified name in the corresponding storage.\n * If the value is `undefined`, the property is removed from the storage.\n *\n * @param propertyName The name of the property to set.\n * @param newValue The new value to set.\n * @param persistent Whether to use the persistent `localStorage` or the volatile `sessionStorage`.\n */\n public set<T>(propertyName: string, newValue?: T, persistent = this._preferPersistence): void\n {\n const storage = persistent ? this._persistent : this._volatile;\n\n this._set<T>(storage, propertyName, newValue);\n }\n /**\n * Sets the value with the specified name in the volatile `sessionStorage`.\n * If the value is `undefined`, the property is removed from the storage.\n *\n * @param propertyName The name of the property to set.\n * @param newValue The new value to set.\n */\n public remember<T>(propertyName: string, newValue?: T): void\n {\n this._set<T>(this._volatile, propertyName, newValue);\n }\n /**\n * Sets the value with the specified name in the persistent `localStorage`.\n * If the value is `undefined`, the property is removed from the storage.\n *\n * @param propertyName The name of the property to set.\n * @param newValue The new value to set.\n */\n public write<T>(propertyName: string, newValue?: T): void\n {\n this._set<T>(this._persistent, propertyName, newValue);\n }\n\n /**\n * Removes the value with the specified name from the volatile `sessionStorage`.\n *\n * @param propertyName The name of the property to remove.\n */\n public forget(propertyName: string): void\n {\n this._volatile.removeItem(propertyName);\n }\n /**\n * Removes the value with the specified name from the persistent `localStorage`.\n *\n * @param propertyName The name of the property to remove.\n */\n public erase(propertyName: string): void\n {\n this._persistent.removeItem(propertyName);\n }\n /**\n * Removes the value with the specified name from all the storages.\n *\n * @param propertyName The name of the property to remove.\n */\n public clear(propertyName: string): void\n {\n this._volatile.removeItem(propertyName);\n this._persistent.removeItem(propertyName);\n }\n}\n","import Exception from \"./exception.js\";\n\nexport default class Subscribers<P extends unknown[] = [], R = void, T extends (...args: P) => R = (...args: P) => R>\n{\n protected _subscribers: T[];\n\n public constructor()\n {\n this._subscribers = [];\n }\n\n public add(subscriber: T): void\n {\n this._subscribers.push(subscriber);\n }\n public remove(subscriber: T): void\n {\n const index = this._subscribers.indexOf(subscriber);\n if (index < 0)\n {\n throw new Exception(\"Unable to remove the requested subscriber. It was not found.\");\n }\n\n this._subscribers.splice(index, 1);\n }\n\n public call(...args: P): R[]\n {\n return this._subscribers\n .slice()\n .map((subscriber) => subscriber(...args));\n }\n}\n","export async function delay(milliseconds: number): Promise<void>\n{\n return new Promise<void>((resolve, reject) => setTimeout(resolve, milliseconds));\n}\n\nexport async function nextAnimationFrame(): Promise<void>\n{\n return new Promise<void>((resolve, reject) => requestAnimationFrame(() => resolve()));\n}\n","export enum DateUnit\n{\n Second = 1000,\n Minute = 60 * Second,\n Hour = 60 * Minute,\n Day = 24 * Hour,\n Week = 7 * Day,\n Month = 30 * Day,\n Year = 365 * Day\n}\n\nexport function dateDifference(start: Date, end: Date, unit = DateUnit.Day)\n{\n return Math.floor((end.getTime() - start.getTime()) / unit);\n}\n\nexport function* dateRange(start: Date, end: Date, offset = DateUnit.Day)\n{\n const endTime = end.getTime();\n\n let unixTime: number = start.getTime();\n while (unixTime < endTime)\n {\n yield new Date(unixTime);\n\n unixTime += offset;\n }\n}\n\nexport function dateRound(date: Date, unit = DateUnit.Day)\n{\n return new Date(Math.floor(date.getTime() / unit) * unit);\n}\n","export async function loadScript(scriptUrl: string, scriptType = \"text/javascript\"): Promise<void>\n{\n return new Promise<void>((resolve, reject) =>\n {\n const script = document.createElement(\"script\");\n\n script.async = true;\n script.defer = true;\n script.src = scriptUrl;\n script.type = scriptType;\n\n script.onload = () => resolve();\n script.onerror = () => reject();\n\n document.body.appendChild(script);\n });\n}\n","export function count<T>(elements: Iterable<T>): number\n{\n if (Array.isArray(elements)) { return elements.length; }\n\n let _count = 0;\n for (const _ of elements) { _count += 1; }\n\n return _count;\n}\n\nexport function range(end: number): Generator<number, void>;\nexport function range(start: number, end: number): Generator<number, void>;\nexport function range(start: number, end: number, step: number): Generator<number, void>;\nexport function* range(start: number, end?: number, step = 1): Generator<number, void>\n{\n if (end === undefined)\n {\n end = start;\n start = 0;\n }\n\n if (start > end) { step = step ?? -1; }\n\n for (let index = start; index < end; index += step) { yield index; }\n}\n\nexport function shuffle<T>(iterable: Iterable<T>): T[]\n{\n const array = [...iterable];\n\n for (let index = array.length - 1; index > 0; index -= 1)\n {\n const jndex = Math.floor(Math.random() * (index + 1));\n\n [array[index], array[jndex]] = [array[jndex], array[index]];\n }\n\n return array;\n}\n\nexport function unique<T>(elements: Iterable<T>): T[]\n{\n return [...new Set(elements)];\n}\n\nexport function* zip<T, U>(first: Iterable<T>, second: Iterable<U>): Generator<[T, U], void>\n{\n const firstIterator = first[Symbol.iterator]();\n const secondIterator = second[Symbol.iterator]();\n\n while (true)\n {\n const firstResult = firstIterator.next();\n const secondResult = secondIterator.next();\n\n if ((firstResult.done) || (secondResult.done)) { break; }\n\n yield [firstResult.value, secondResult.value];\n }\n}\n","import { zip } from \"./iterator.js\";\n\nexport function average<T extends number>(values: Iterable<T>): number;\nexport function average<T extends number>(values: Iterable<T>, weights: Iterable<number>): number;\nexport function average<T extends number>(values: Iterable<T>, weights?: Iterable<number>): number\n{\n if (weights === undefined)\n {\n let _sum = 0;\n let _count = 0;\n\n for (const value of values)\n {\n _sum += value;\n _count += 1;\n }\n\n return _sum / _count;\n }\n\n let _sum = 0;\n let _count = 0;\n\n for (const [value, weight] of zip(values, weights))\n {\n _sum += value * weight;\n _count += weight;\n }\n\n return _sum / _count;\n}\n\nexport function hash(value: string): number\n{\n let hashedValue = 0;\n for (let i = 0; i < value.length; i++)\n {\n const char = value.charCodeAt(i);\n hashedValue = ((hashedValue << 5) - hashedValue) + char;\n hashedValue |= 0;\n }\n\n return hashedValue;\n}\n\nexport function random(): number;\nexport function random(max: number): number;\nexport function random(min: number, max: number): number;\nexport function random(min: number, max: number, isDecimal: boolean): number;\nexport function random(min: number, max: number, digits: number): number;\nexport function random(min: number = 1, max?: number, decimals?: boolean | number): number\n{\n if (max === undefined)\n {\n max = min;\n min = 0;\n }\n\n if (min === max)\n {\n return min;\n }\n\n let rounder: (value: number) => number;\n\n if (decimals === true)\n {\n rounder = (value) => value;\n }\n else if (decimals === undefined)\n {\n if (Math.abs(max - min) <= 1)\n {\n rounder = (value) => value;\n }\n else\n {\n rounder = Math.floor;\n }\n }\n else if (decimals === false)\n {\n rounder = Math.floor;\n }\n else\n {\n const digits = 10 ** decimals;\n\n rounder = (value) => Math.floor(value * digits) / digits;\n }\n\n return rounder(Math.random() * (max - min) + min);\n}\n\nexport function sum<T extends number>(values: Iterable<T>): number\n{\n let _sum = 0;\n for (const value of values) { _sum += value; }\n\n return _sum;\n}\n","export function capitalize(value: string): string\n{\n return `${value.charAt(0).toUpperCase()}${value.slice(1)}`;\n}\n","export const VERSION = \"1.1.8\";\n\nexport { DeferredPromise, Exception, JsonStorage, Subscribers } from \"./models/index.js\";\nexport {\n average,\n capitalize,\n count,\n delay,\n dateDifference,\n dateRange,\n dateRound,\n DateUnit,\n hash,\n loadScript,\n nextAnimationFrame,\n random,\n range,\n shuffle,\n sum,\n unique,\n zip\n\n} from \"./utils/index.js\";\n\nexport type {\n Constructor,\n FulfilledHandler,\n MaybePromise,\n PromiseExecutor,\n PromiseRejecter,\n PromiseResolver,\n RejectedHandler\n\n} from \"./types.js\";\n"],"names":["DeferredPromise","onFulfilled","onRejected","__publicField","_resolve","_reject","resolve","reject","onFinally","promise","Exception","error","exc","message","cause","name","JsonStorage","preferPersistence","storage","propertyName","defaultValue","propertyValue","newValue","encodedValue","persistent","Subscribers","subscriber","index","args","delay","milliseconds","nextAnimationFrame","DateUnit","dateDifference","start","end","unit","dateRange","offset","endTime","unixTime","dateRound","date","loadScript","scriptUrl","scriptType","script","count","elements","_count","_","range","step","shuffle","iterable","array","jndex","unique","zip","first","second","firstIterator","secondIterator","firstResult","secondResult","average","values","weights","_sum","value","weight","hash","hashedValue","i","char","random","min","max","decimals","rounder","digits","sum","capitalize","VERSION"],"mappings":"oYAEA,MAAqBA,CACrB,CAMW,YAAYC,EAA6CC,EAChE,CANUC,EAAA,iBACAA,EAAA,gBAEAA,EAAA,iBAIF,IAAAC,EACAC,EAEJ,KAAK,SAAW,IAAI,QAAW,CAACC,EAASC,IACzC,CACeH,EAAAE,EACDD,EAAAE,CAEb,CAAA,EAAE,KAAKN,EAAaC,CAAU,EAE/B,KAAK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G,GAAK,EAEvBG,EAAWV,GAAUA,EAIrBU,EAAU,KAAK,cAGdD,IAAa,GAElBC,EAAU,KAAK,UAGnB,CACI,MAAMC,EAAS,IAAMF,EAErBC,EAAWV,GAAU,KAAK,MAAMA,EAAQW,CAAM,EAAIA,CACtD,CAEA,OAAOD,EAAQ,KAAK,OAAA,GAAYF,EAAMD,GAAOA,CAAG,CACpD,CAEO,SAASK,EAAsBf,EACtC,CACI,IAAIE,EAAO,EACX,UAAWC,KAASH,EAAkBE,GAAAC,EAE/B,OAAAD,CACX,CCpGO,SAASc,EAAWb,EAC3B,CACW,MAAA,GAAGA,EAAM,OAAO,CAAC,EAAE,aAAa,GAAGA,EAAM,MAAM,CAAC,CAAC,EAC5D,CCHO,MAAMc,EAAU"}
|
|
1
|
+
{"version":3,"file":"core.umd.cjs","sources":["../src/models/deferred-promise.ts","../src/models/exception.ts","../src/models/json-storage.ts","../src/models/smart-iterator.ts","../src/models/subscribers.ts","../src/utils/async.ts","../src/utils/date.ts","../src/utils/dom.ts","../src/utils/iterator.ts","../src/utils/math.ts","../src/utils/string.ts","../src/index.ts"],"sourcesContent":["import type { PromiseResolver, PromiseRejecter, FulfilledHandler, RejectedHandler } from \"../types.js\";\n\nexport default class DeferredPromise<T = void, E = unknown, F = T, R = never>\n{\n protected _resolve!: PromiseResolver<T>;\n protected _reject!: PromiseRejecter<E>;\n\n protected _promise: Promise<F | R>;\n\n public constructor(onFulfilled?: FulfilledHandler<T, F> | null, onRejected?: RejectedHandler<E, R> | null)\n {\n let _resolve: PromiseResolver<T>;\n let _reject: PromiseRejecter<E>;\n\n this._promise = new Promise<T>((resolve, reject) =>\n {\n _resolve = resolve as PromiseResolver<T>;\n _reject = reject as PromiseRejecter<E>;\n\n }).then(onFulfilled, onRejected);\n\n this._resolve = _resolve!;\n this._reject = _reject!;\n }\n\n public get resolve(): PromiseResolver<T>\n {\n return this._resolve;\n }\n public get reject(): PromiseRejecter<E>\n {\n return this._reject;\n }\n\n public then<N = F | R, H = R>(\n onFulfilled?: FulfilledHandler<F | R, N> | null,\n onRejected?: RejectedHandler<R, H> | null): Promise<N | H>\n {\n return this._promise.then(onFulfilled, onRejected);\n }\n public catch<H = R>(onRejected?: RejectedHandler<R, H> | null): Promise<F | R | H>\n {\n return this._promise.catch(onRejected);\n }\n public finally(onFinally?: (() => void) | null): Promise<F | R>\n {\n return this._promise.finally(onFinally);\n }\n\n public watch(promise: Promise<T>): this\n {\n promise.then(this.resolve, this.reject);\n\n return this;\n }\n\n public get [Symbol.toStringTag]()\n {\n return \"DeferredPromise\";\n }\n}\n","export default class Exception extends Error\n{\n public static FromUnknown(error: unknown): Exception\n {\n if (error instanceof Exception)\n {\n return error;\n }\n if (error instanceof Error)\n {\n const exc = new Exception(error.message);\n\n exc.stack = error.stack;\n exc.name = error.name;\n\n return exc;\n }\n\n return new Exception(`${error}`);\n }\n\n public constructor(message: string, cause?: unknown, name = \"Exception\")\n {\n super(message);\n\n this.cause = cause;\n this.name = name;\n\n if (cause)\n {\n if (cause instanceof Error)\n {\n this.stack += `\\n\\nCaused by ${cause.stack}`;\n }\n else\n {\n this.stack += `\\n\\nCaused by ${cause}`;\n }\n }\n }\n}\n","/* eslint-disable no-trailing-spaces */\n\n/**\n * A wrapper around the `Storage` API to store and retrieve JSON values.\n *\n * It allows to handle either the `sessionStorage` or the `localStorage`\n * storage at the same time, depending on the required use case.\n */\nexport default class JsonStorage\n{\n protected _preferPersistence: boolean;\n\n protected _volatile: Storage;\n protected _persistent: Storage;\n\n public constructor(preferPersistence = true)\n {\n this._preferPersistence = preferPersistence;\n\n this._volatile = window.sessionStorage;\n this._persistent = window.localStorage;\n }\n\n protected _get<T>(storage: Storage, propertyName: string): T | undefined;\n protected _get<T>(storage: Storage, propertyName: string, defaultValue: T): T;\n protected _get<T>(storage: Storage, propertyName: string, defaultValue?: T): T | undefined;\n protected _get<T>(storage: Storage, propertyName: string, defaultValue?: T): T | undefined\n {\n const propertyValue = storage.getItem(propertyName);\n if (propertyValue)\n {\n try\n {\n return JSON.parse(propertyValue);\n }\n catch (error)\n {\n // eslint-disable-next-line no-console\n console.warn(\n `The \"${propertyValue}\" value for \"${propertyName}\"` +\n \" property cannot be parsed. Clearing the storage...\");\n\n storage.removeItem(propertyName);\n }\n }\n\n return defaultValue;\n }\n protected _set<T>(storage: Storage, propertyName: string, newValue?: T): void\n {\n const encodedValue = JSON.stringify(newValue);\n if (encodedValue)\n {\n storage.setItem(propertyName, encodedValue);\n }\n else\n {\n storage.removeItem(propertyName);\n }\n }\n\n /**\n * Retrieves the value with the specified name from the corresponding storage.\n *\n * @param propertyName The name of the property to retrieve.\n * @param defaultValue The default value to return if the property does not exist.\n * @param persistent Whether to use the persistent `localStorage` or the volatile `sessionStorage`.\n *\n * @returns The value of the property or the default value if the property does not exist.\n */\n public get<T>(propertyName: string, defaultValue: undefined, persistent?: boolean): T | undefined;\n public get<T>(propertyName: string, defaultValue: T, persistent?: boolean): T ;\n public get<T>(propertyName: string, defaultValue?: T, persistent?: boolean): T | undefined;\n public get<T>(propertyName: string, defaultValue?: T, persistent = this._preferPersistence): T | undefined\n {\n const storage = persistent ? this._persistent : this._volatile;\n\n return this._get<T>(storage, propertyName, defaultValue);\n }\n /**\n * Retrieves the value with the specified name from the volatile `sessionStorage`.\n *\n * @param propertyName The name of the property to retrieve.\n * @param defaultValue The default value to return if the property does not exist.\n *\n * @returns The value of the property or the default value if the property does not exist.\n */\n public recall<T>(propertyName: string): T | undefined;\n public recall<T>(propertyName: string, defaultValue: T): T;\n public recall<T>(propertyName: string, defaultValue?: T): T | undefined;\n public recall<T>(propertyName: string, defaultValue?: T): T | undefined\n {\n return this._get<T>(this._volatile, propertyName, defaultValue);\n }\n /**\n * Retrieves the value with the specified name looking first in the\n * volatile `sessionStorage` and then in the persistent `localStorage`.\n *\n * @param propertyName The name of the property to retrieve.\n * @param defaultValue The default value to return if the property does not exist.\n *\n * @returns The value of the property or the default value if the property does not exist.\n */\n public retrieve<T>(propertyName: string): T | undefined;\n public retrieve<T>(propertyName: string, defaultValue: T): T;\n public retrieve<T>(propertyName: string, defaultValue?: T): T | undefined;\n public retrieve<T>(propertyName: string, defaultValue?: T): T | undefined\n {\n return this.recall<T>(propertyName) ?? this.read<T>(propertyName, defaultValue);\n }\n /**\n * Retrieves the value with the specified name from the persistent `localStorage`.\n *\n * @param propertyName The name of the property to retrieve.\n * @param defaultValue The default value to return if the property does not exist.\n *\n * @returns The value of the property or the default value if the property does not exist.\n */\n public read<T>(propertyName: string): T | undefined;\n public read<T>(propertyName: string, defaultValue: T): T;\n public read<T>(propertyName: string, defaultValue?: T): T | undefined;\n public read<T>(propertyName: string, defaultValue?: T): T | undefined\n {\n return this._get<T>(this._persistent, propertyName, defaultValue);\n }\n\n /**\n * Checks whether the property with the specified name exists in the corresponding storage.\n *\n * @param propertyName The name of the property to check.\n * @param persistent Whether to use the persistent `localStorage` or the volatile `sessionStorage`.\n *\n * @returns `true` if the property exists, `false` otherwise.\n */\n public has(propertyName: string, persistent?: boolean): boolean\n {\n const storage = persistent ? this._persistent : this._volatile;\n\n return storage.getItem(propertyName) !== null;\n }\n /**\n * Checks whether the property with the specified name exists in the volatile `sessionStorage`.\n *\n * @param propertyName The name of the property to check.\n *\n * @returns `true` if the property exists, `false` otherwise.\n */\n public knows(propertyName: string): boolean\n {\n return this._volatile.getItem(propertyName) !== null;\n }\n /**\n * Checks whether the property with the specified name exists looking first in the\n * volatile `sessionStorage` and then in the persistent `localStorage`.\n *\n * @param propertyName The name of the property to check.\n *\n * @returns `true` if the property exists, `false` otherwise.\n */\n public find(propertyName: string): boolean\n {\n return this.knows(propertyName) ?? this.exists(propertyName);\n }\n /**\n * Checks whether the property with the specified name exists in the persistent `localStorage`.\n *\n * @param propertyName The name of the property to check.\n *\n * @returns `true` if the property exists, `false` otherwise.\n */\n public exists(propertyName: string): boolean\n {\n return this._persistent.getItem(propertyName) !== null;\n }\n\n /**\n * Sets the value with the specified name in the corresponding storage.\n * If the value is `undefined`, the property is removed from the storage.\n *\n * @param propertyName The name of the property to set.\n * @param newValue The new value to set.\n * @param persistent Whether to use the persistent `localStorage` or the volatile `sessionStorage`.\n */\n public set<T>(propertyName: string, newValue?: T, persistent = this._preferPersistence): void\n {\n const storage = persistent ? this._persistent : this._volatile;\n\n this._set<T>(storage, propertyName, newValue);\n }\n /**\n * Sets the value with the specified name in the volatile `sessionStorage`.\n * If the value is `undefined`, the property is removed from the storage.\n *\n * @param propertyName The name of the property to set.\n * @param newValue The new value to set.\n */\n public remember<T>(propertyName: string, newValue?: T): void\n {\n this._set<T>(this._volatile, propertyName, newValue);\n }\n /**\n * Sets the value with the specified name in the persistent `localStorage`.\n * If the value is `undefined`, the property is removed from the storage.\n *\n * @param propertyName The name of the property to set.\n * @param newValue The new value to set.\n */\n public write<T>(propertyName: string, newValue?: T): void\n {\n this._set<T>(this._persistent, propertyName, newValue);\n }\n\n /**\n * Removes the value with the specified name from the volatile `sessionStorage`.\n *\n * @param propertyName The name of the property to remove.\n */\n public forget(propertyName: string): void\n {\n this._volatile.removeItem(propertyName);\n }\n /**\n * Removes the value with the specified name from the persistent `localStorage`.\n *\n * @param propertyName The name of the property to remove.\n */\n public erase(propertyName: string): void\n {\n this._persistent.removeItem(propertyName);\n }\n /**\n * Removes the value with the specified name from all the storages.\n *\n * @param propertyName The name of the property to remove.\n */\n public clear(propertyName: string): void\n {\n this._volatile.removeItem(propertyName);\n this._persistent.removeItem(propertyName);\n }\n}\n","import type { GeneratorFunction } from \"../types.js\";\n\nexport default class SmartIterator<T, R = void, N = undefined> implements Iterator<T, R, N>\n{\n protected _iterator: Iterator<T, R, N>;\n\n public return?: (value?: R) => IteratorResult<T, R>;\n public throw?: (error?: unknown) => IteratorResult<T, R>;\n\n public constructor(iterable: Iterable<T>);\n public constructor(iterator: Iterator<T, R, N>);\n public constructor(generatorFn: GeneratorFunction<T, R, N>);\n public constructor(iterable: Iterable<T> | Iterator<T, R, N> | GeneratorFunction<T, R, N>)\n {\n if (iterable instanceof Function)\n {\n this._iterator = iterable();\n }\n else if (Symbol.iterator in iterable)\n {\n this._iterator = iterable[Symbol.iterator]() as Iterator<T, R, N>;\n }\n else\n {\n this._iterator = iterable;\n }\n\n if (this._iterator.return) { this.return = (value?: R) => this._iterator.return!(value); }\n if (this._iterator.throw) { this.throw = (error?: unknown) => this._iterator.throw!(error); }\n }\n\n public filter(callback: (value: T, index: number) => boolean): SmartIterator<T, R, N>\n {\n let index = 0;\n const iterator = this._iterator;\n\n return new SmartIterator<T, R, N>({\n *[Symbol.iterator]()\n {\n while (true)\n {\n const result = iterator.next();\n if (result.done) { return result.value; }\n\n if (callback(result.value, index))\n {\n yield result.value;\n }\n\n index += 1;\n }\n }\n });\n }\n public map<V>(callback: (value: T, index: number) => V): SmartIterator<V, R>\n {\n let index = 0;\n const iterator = this._iterator;\n\n return new SmartIterator<V, R>({\n *[Symbol.iterator]()\n {\n while (true)\n {\n const result = iterator.next();\n if (result.done) { return result.value; }\n\n yield callback(result.value, index);\n\n index += 1;\n }\n }\n });\n }\n public reduce<U>(callback: (accumulator: U, value: T, index: number) => U, initialValue: U): U\n {\n let index = 0;\n let accumulator = initialValue;\n\n // eslint-disable-next-line no-constant-condition\n while (true)\n {\n const result = this._iterator.next();\n if (result.done) { return accumulator; }\n\n accumulator = callback(accumulator, result.value, index);\n\n index += 1;\n }\n }\n\n public forEach(callback: (value: T, index: number) => void): void\n {\n let index = 0;\n\n // eslint-disable-next-line no-constant-condition\n while (true)\n {\n const result = this._iterator.next();\n if (result.done) { return; }\n\n callback(result.value, index);\n\n index += 1;\n }\n }\n\n public next(...values: N extends undefined ? [] : [N]): IteratorResult<T, R>\n {\n return this._iterator.next(...values);\n }\n\n public toArray(): T[]\n {\n return [...this];\n }\n\n public [Symbol.iterator](): SmartIterator<T, R, N> { return this; }\n}\n","import Exception from \"./exception.js\";\n\nexport default class Subscribers<P extends unknown[] = [], R = void, T extends (...args: P) => R = (...args: P) => R>\n{\n protected _subscribers: T[];\n\n public constructor()\n {\n this._subscribers = [];\n }\n\n public add(subscriber: T): void\n {\n this._subscribers.push(subscriber);\n }\n public remove(subscriber: T): void\n {\n const index = this._subscribers.indexOf(subscriber);\n if (index < 0)\n {\n throw new Exception(\"Unable to remove the requested subscriber. It was not found.\");\n }\n\n this._subscribers.splice(index, 1);\n }\n\n public call(...args: P): R[]\n {\n return this._subscribers\n .slice()\n .map((subscriber) => subscriber(...args));\n }\n}\n","export async function delay(milliseconds: number): Promise<void>\n{\n return new Promise<void>((resolve, reject) => setTimeout(resolve, milliseconds));\n}\n\nexport async function nextAnimationFrame(): Promise<void>\n{\n return new Promise<void>((resolve, reject) => requestAnimationFrame(() => resolve()));\n}\n","import { SmartIterator } from \"../models/index.js\";\n\nexport enum DateUnit\n{\n Second = 1000,\n Minute = 60 * Second,\n Hour = 60 * Minute,\n Day = 24 * Hour,\n Week = 7 * Day,\n Month = 30 * Day,\n Year = 365 * Day\n}\n\nexport function dateDifference(start: Date, end: Date, unit = DateUnit.Day): number\n{\n return Math.floor((end.getTime() - start.getTime()) / unit);\n}\n\nexport function dateRange(start: Date, end: Date, offset = DateUnit.Day): SmartIterator<Date>\n{\n return new SmartIterator<Date>(function* ()\n {\n const endTime = end.getTime();\n\n let unixTime: number = start.getTime();\n while (unixTime < endTime)\n {\n yield new Date(unixTime);\n\n unixTime += offset;\n }\n });\n}\n\nexport function dateRound(date: Date, unit = DateUnit.Day): Date\n{\n return new Date(Math.floor(date.getTime() / unit) * unit);\n}\n","export async function loadScript(scriptUrl: string, scriptType = \"text/javascript\"): Promise<void>\n{\n return new Promise<void>((resolve, reject) =>\n {\n const script = document.createElement(\"script\");\n\n script.async = true;\n script.defer = true;\n script.src = scriptUrl;\n script.type = scriptType;\n\n script.onload = () => resolve();\n script.onerror = () => reject();\n\n document.body.appendChild(script);\n });\n}\n","import { SmartIterator } from \"../models/index.js\";\n\nexport function count<T>(elements: Iterable<T>): number\n{\n if (Array.isArray(elements)) { return elements.length; }\n\n let _count = 0;\n for (const _ of elements) { _count += 1; }\n\n return _count;\n}\n\nexport function range(end: number): SmartIterator<number>;\nexport function range(start: number, end: number): SmartIterator<number>;\nexport function range(start: number, end: number, step: number): SmartIterator<number>;\nexport function range(start: number, end?: number, step = 1): SmartIterator<number>\n{\n return new SmartIterator<number>(function* ()\n {\n if (end === undefined)\n {\n end = start;\n start = 0;\n }\n\n if (start > end) { step = step ?? -1; }\n\n for (let index = start; index < end; index += step) { yield index; }\n });\n}\n\nexport function shuffle<T>(iterable: Iterable<T>): T[]\n{\n const array = [...iterable];\n\n for (let index = array.length - 1; index > 0; index -= 1)\n {\n const jndex = Math.floor(Math.random() * (index + 1));\n\n [array[index], array[jndex]] = [array[jndex], array[index]];\n }\n\n return array;\n}\n\nexport function unique<T>(elements: Iterable<T>): SmartIterator<T>\n{\n return new SmartIterator<T>(function* ()\n {\n const seen = new Set<T>();\n\n for (const element of elements)\n {\n if (seen.has(element)) { continue; }\n\n seen.add(element);\n\n yield element;\n }\n });\n}\n\nexport function zip<T, U>(first: Iterable<T>, second: Iterable<U>): SmartIterator<[T, U]>\n{\n return new SmartIterator<[T, U]>(function* ()\n {\n const firstIterator = first[Symbol.iterator]();\n const secondIterator = second[Symbol.iterator]();\n\n while (true)\n {\n const firstResult = firstIterator.next();\n const secondResult = secondIterator.next();\n\n if ((firstResult.done) || (secondResult.done)) { break; }\n\n yield [firstResult.value, secondResult.value];\n }\n });\n}\n","import { zip } from \"./iterator.js\";\n\nexport function average<T extends number>(values: Iterable<T>): number;\nexport function average<T extends number>(values: Iterable<T>, weights: Iterable<number>): number;\nexport function average<T extends number>(values: Iterable<T>, weights?: Iterable<number>): number\n{\n if (weights === undefined)\n {\n let _sum = 0;\n let _count = 0;\n\n for (const value of values)\n {\n _sum += value;\n _count += 1;\n }\n\n return _sum / _count;\n }\n\n let _sum = 0;\n let _count = 0;\n\n for (const [value, weight] of zip(values, weights))\n {\n _sum += value * weight;\n _count += weight;\n }\n\n return _sum / _count;\n}\n\nexport function hash(value: string): number\n{\n let hashedValue = 0;\n for (let i = 0; i < value.length; i++)\n {\n const char = value.charCodeAt(i);\n hashedValue = ((hashedValue << 5) - hashedValue) + char;\n hashedValue |= 0;\n }\n\n return hashedValue;\n}\n\nexport function random(): number;\nexport function random(max: number): number;\nexport function random(min: number, max: number): number;\nexport function random(min: number, max: number, isDecimal: boolean): number;\nexport function random(min: number, max: number, digits: number): number;\nexport function random(min: number = 1, max?: number, decimals?: boolean | number): number\n{\n if (max === undefined)\n {\n max = min;\n min = 0;\n }\n\n if (min === max)\n {\n return min;\n }\n\n let rounder: (value: number) => number;\n\n if (decimals === true)\n {\n rounder = (value) => value;\n }\n else if (decimals === undefined)\n {\n if (Math.abs(max - min) <= 1)\n {\n rounder = (value) => value;\n }\n else\n {\n rounder = Math.floor;\n }\n }\n else if (decimals === false)\n {\n rounder = Math.floor;\n }\n else\n {\n const digits = 10 ** decimals;\n\n rounder = (value) => Math.floor(value * digits) / digits;\n }\n\n return rounder(Math.random() * (max - min) + min);\n}\n\nexport function sum<T extends number>(values: Iterable<T>): number\n{\n let _sum = 0;\n for (const value of values) { _sum += value; }\n\n return _sum;\n}\n","export function capitalize(value: string): string\n{\n return `${value.charAt(0).toUpperCase()}${value.slice(1)}`;\n}\n","export const VERSION = \"1.2.0-rc.2\";\n\nexport { DeferredPromise, Exception, JsonStorage, SmartIterator, Subscribers } from \"./models/index.js\";\nexport {\n average,\n capitalize,\n count,\n delay,\n dateDifference,\n dateRange,\n dateRound,\n DateUnit,\n hash,\n loadScript,\n nextAnimationFrame,\n random,\n range,\n shuffle,\n sum,\n unique,\n zip\n\n} from \"./utils/index.js\";\n\nexport type {\n Constructor,\n FulfilledHandler,\n MaybePromise,\n PromiseExecutor,\n PromiseRejecter,\n PromiseResolver,\n RejectedHandler\n\n} from \"./types.js\";\n"],"names":["DeferredPromise","onFulfilled","onRejected","__publicField","_resolve","_reject","resolve","reject","onFinally","promise","Exception","error","exc","message","cause","name","JsonStorage","preferPersistence","storage","propertyName","defaultValue","propertyValue","newValue","encodedValue","persistent","SmartIterator","iterable","value","callback","index","iterator","result","initialValue","accumulator","values","Subscribers","subscriber","args","delay","milliseconds","nextAnimationFrame","DateUnit","dateDifference","start","end","unit","dateRange","offset","endTime","unixTime","dateRound","date","loadScript","scriptUrl","scriptType","script","count","elements","_count","_","range","step","shuffle","array","jndex","unique","seen","element","zip","first","second","firstIterator","secondIterator","firstResult","secondResult","average","weights","_sum","weight","hash","hashedValue","i","char","random","min","max","decimals","rounder","digits","sum","capitalize","VERSION"],"mappings":"oYAEA,MAAqBA,CACrB,CAMW,YAAYC,EAA6CC,EAChE,CANUC,EAAA,iBACAA,EAAA,gBAEAA,EAAA,iBAIF,IAAAC,EACAC,EAEJ,KAAK,SAAW,IAAI,QAAW,CAACC,EAASC,IACzC,CACeH,EAAAE,EACDD,EAAAE,CAEb,CAAA,EAAE,KAAKN,EAAaC,CAAU,EAE/B,KAAK,SAAWE,EAChB,KAAK,QAAUC,CACnB,CAEA,IAAW,SACX,CACI,OAAO,KAAK,QAChB,CACA,IAAW,QACX,CACI,OAAO,KAAK,OAChB,CAEO,KACHJ,EACAC,EACJ,CACI,OAAO,KAAK,SAAS,KAAKD,EAAaC,CAAU,CACrD,CACO,MAAaA,EACpB,CACW,OAAA,KAAK,SAAS,MAAMA,CAAU,CACzC,CACO,QAAQM,EACf,CACW,OAAA,KAAK,SAAS,QAAQA,CAAS,CAC1C,CAEO,MAAMC,EACb,CACI,OAAAA,EAAQ,KAAK,KAAK,QAAS,KAAK,MAAM,EAE/B,IACX,CAEA,IAAY,OAAO,WAAW,GAC9B,CACW,MAAA,iBACX,CACJ,CC5DA,MAAqBC,UAAkB,KACvC,CACI,OAAc,YAAYC,EAC1B,CACI,GAAIA,aAAiBD,EAEV,OAAAC,EAEX,GAAIA,aAAiB,MACrB,CACI,MAAMC,EAAM,IAAIF,EAAUC,EAAM,OAAO,EAEvC,OAAAC,EAAI,MAAQD,EAAM,MAClBC,EAAI,KAAOD,EAA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ACtD,CAEA,OAAOD,EAAQ,KAAK,OAAA,GAAYF,EAAMD,GAAOA,CAAG,CACpD,CAEO,SAASK,EAAsBvD,EACtC,CACI,IAAI2C,EAAO,EACX,UAAWlD,KAASO,EAAkB2C,GAAAlD,EAE/B,OAAAkD,CACX,CCpGO,SAASa,EAAW/D,EAC3B,CACW,MAAA,GAAGA,EAAM,OAAO,CAAC,EAAE,aAAa,GAAGA,EAAM,MAAM,CAAC,CAAC,EAC5D,CCHO,MAAMgE,EAAU"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@byloth/core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0-rc.2",
|
|
4
4
|
"description": "An unopinionated collection of useful functions and classes that I use widely in all my projects. 🔧",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Core",
|
|
@@ -56,11 +56,11 @@
|
|
|
56
56
|
"ci": "yarn install --frozen-lockfile"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
|
-
"@byloth/eslint-config-typescript": "^2.6.
|
|
60
|
-
"@typescript-eslint/eslint-plugin": "^6.
|
|
61
|
-
"@typescript-eslint/parser": "^6.
|
|
62
|
-
"eslint": "^8.
|
|
59
|
+
"@byloth/eslint-config-typescript": "^2.6.8",
|
|
60
|
+
"@typescript-eslint/eslint-plugin": "^6.15.0",
|
|
61
|
+
"@typescript-eslint/parser": "^6.15.0",
|
|
62
|
+
"eslint": "^8.56.0",
|
|
63
63
|
"typescript": "^5.3.3",
|
|
64
|
-
"vite": "^5.0.
|
|
64
|
+
"vite": "^5.0.10"
|
|
65
65
|
}
|
|
66
66
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export const VERSION = "1.
|
|
1
|
+
export const VERSION = "1.2.0-rc.2";
|
|
2
2
|
|
|
3
|
-
export { DeferredPromise, Exception, JsonStorage, Subscribers } from "./models/index.js";
|
|
3
|
+
export { DeferredPromise, Exception, JsonStorage, SmartIterator, Subscribers } from "./models/index.js";
|
|
4
4
|
export {
|
|
5
5
|
average,
|
|
6
6
|
capitalize,
|
package/src/models/index.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import DeferredPromise from "./deferred-promise.js";
|
|
2
2
|
import Exception from "./exception.js";
|
|
3
3
|
import JsonStorage from "./json-storage.js";
|
|
4
|
+
import SmartIterator from "./smart-iterator.js";
|
|
4
5
|
import Subscribers from "./subscribers.js";
|
|
5
6
|
|
|
6
|
-
export { DeferredPromise, Exception, JsonStorage, Subscribers };
|
|
7
|
+
export { DeferredPromise, Exception, JsonStorage, SmartIterator, Subscribers };
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import type { GeneratorFunction } from "../types.js";
|
|
2
|
+
|
|
3
|
+
export default class SmartIterator<T, R = void, N = undefined> implements Iterator<T, R, N>
|
|
4
|
+
{
|
|
5
|
+
protected _iterator: Iterator<T, R, N>;
|
|
6
|
+
|
|
7
|
+
public return?: (value?: R) => IteratorResult<T, R>;
|
|
8
|
+
public throw?: (error?: unknown) => IteratorResult<T, R>;
|
|
9
|
+
|
|
10
|
+
public constructor(iterable: Iterable<T>);
|
|
11
|
+
public constructor(iterator: Iterator<T, R, N>);
|
|
12
|
+
public constructor(generatorFn: GeneratorFunction<T, R, N>);
|
|
13
|
+
public constructor(iterable: Iterable<T> | Iterator<T, R, N> | GeneratorFunction<T, R, N>)
|
|
14
|
+
{
|
|
15
|
+
if (iterable instanceof Function)
|
|
16
|
+
{
|
|
17
|
+
this._iterator = iterable();
|
|
18
|
+
}
|
|
19
|
+
else if (Symbol.iterator in iterable)
|
|
20
|
+
{
|
|
21
|
+
this._iterator = iterable[Symbol.iterator]() as Iterator<T, R, N>;
|
|
22
|
+
}
|
|
23
|
+
else
|
|
24
|
+
{
|
|
25
|
+
this._iterator = iterable;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (this._iterator.return) { this.return = (value?: R) => this._iterator.return!(value); }
|
|
29
|
+
if (this._iterator.throw) { this.throw = (error?: unknown) => this._iterator.throw!(error); }
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
public filter(callback: (value: T, index: number) => boolean): SmartIterator<T, R, N>
|
|
33
|
+
{
|
|
34
|
+
let index = 0;
|
|
35
|
+
const iterator = this._iterator;
|
|
36
|
+
|
|
37
|
+
return new SmartIterator<T, R, N>({
|
|
38
|
+
*[Symbol.iterator]()
|
|
39
|
+
{
|
|
40
|
+
while (true)
|
|
41
|
+
{
|
|
42
|
+
const result = iterator.next();
|
|
43
|
+
if (result.done) { return result.value; }
|
|
44
|
+
|
|
45
|
+
if (callback(result.value, index))
|
|
46
|
+
{
|
|
47
|
+
yield result.value;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
index += 1;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
public map<V>(callback: (value: T, index: number) => V): SmartIterator<V, R>
|
|
56
|
+
{
|
|
57
|
+
let index = 0;
|
|
58
|
+
const iterator = this._iterator;
|
|
59
|
+
|
|
60
|
+
return new SmartIterator<V, R>({
|
|
61
|
+
*[Symbol.iterator]()
|
|
62
|
+
{
|
|
63
|
+
while (true)
|
|
64
|
+
{
|
|
65
|
+
const result = iterator.next();
|
|
66
|
+
if (result.done) { return result.value; }
|
|
67
|
+
|
|
68
|
+
yield callback(result.value, index);
|
|
69
|
+
|
|
70
|
+
index += 1;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
public reduce<U>(callback: (accumulator: U, value: T, index: number) => U, initialValue: U): U
|
|
76
|
+
{
|
|
77
|
+
let index = 0;
|
|
78
|
+
let accumulator = initialValue;
|
|
79
|
+
|
|
80
|
+
// eslint-disable-next-line no-constant-condition
|
|
81
|
+
while (true)
|
|
82
|
+
{
|
|
83
|
+
const result = this._iterator.next();
|
|
84
|
+
if (result.done) { return accumulator; }
|
|
85
|
+
|
|
86
|
+
accumulator = callback(accumulator, result.value, index);
|
|
87
|
+
|
|
88
|
+
index += 1;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
public forEach(callback: (value: T, index: number) => void): void
|
|
93
|
+
{
|
|
94
|
+
let index = 0;
|
|
95
|
+
|
|
96
|
+
// eslint-disable-next-line no-constant-condition
|
|
97
|
+
while (true)
|
|
98
|
+
{
|
|
99
|
+
const result = this._iterator.next();
|
|
100
|
+
if (result.done) { return; }
|
|
101
|
+
|
|
102
|
+
callback(result.value, index);
|
|
103
|
+
|
|
104
|
+
index += 1;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
public next(...values: N extends undefined ? [] : [N]): IteratorResult<T, R>
|
|
109
|
+
{
|
|
110
|
+
return this._iterator.next(...values);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
public toArray(): T[]
|
|
114
|
+
{
|
|
115
|
+
return [...this];
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
public [Symbol.iterator](): SmartIterator<T, R, N> { return this; }
|
|
119
|
+
}
|
package/src/types.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
export type Constructor<T extends object, P extends
|
|
1
|
+
export type Constructor<T extends object, P extends unknown[] = []> = new (...args: P) => T;
|
|
2
|
+
export type GeneratorFunction<T, R = void, N = undefined> = () => Generator<T, R, N>;
|
|
3
|
+
|
|
2
4
|
export type MaybePromise<T> = T | PromiseLike<T>;
|
|
3
5
|
|
|
4
6
|
export type FulfilledHandler<T = void, R = T> = (value: T) => MaybePromise<R>;
|
package/src/utils/date.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { SmartIterator } from "../models/index.js";
|
|
2
|
+
|
|
1
3
|
export enum DateUnit
|
|
2
4
|
{
|
|
3
5
|
Second = 1000,
|
|
@@ -9,25 +11,28 @@ export enum DateUnit
|
|
|
9
11
|
Year = 365 * Day
|
|
10
12
|
}
|
|
11
13
|
|
|
12
|
-
export function dateDifference(start: Date, end: Date, unit = DateUnit.Day)
|
|
14
|
+
export function dateDifference(start: Date, end: Date, unit = DateUnit.Day): number
|
|
13
15
|
{
|
|
14
16
|
return Math.floor((end.getTime() - start.getTime()) / unit);
|
|
15
17
|
}
|
|
16
18
|
|
|
17
|
-
export function
|
|
19
|
+
export function dateRange(start: Date, end: Date, offset = DateUnit.Day): SmartIterator<Date>
|
|
18
20
|
{
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
let unixTime: number = start.getTime();
|
|
22
|
-
while (unixTime < endTime)
|
|
21
|
+
return new SmartIterator<Date>(function* ()
|
|
23
22
|
{
|
|
24
|
-
|
|
23
|
+
const endTime = end.getTime();
|
|
24
|
+
|
|
25
|
+
let unixTime: number = start.getTime();
|
|
26
|
+
while (unixTime < endTime)
|
|
27
|
+
{
|
|
28
|
+
yield new Date(unixTime);
|
|
25
29
|
|
|
26
|
-
|
|
27
|
-
|
|
30
|
+
unixTime += offset;
|
|
31
|
+
}
|
|
32
|
+
});
|
|
28
33
|
}
|
|
29
34
|
|
|
30
|
-
export function dateRound(date: Date, unit = DateUnit.Day)
|
|
35
|
+
export function dateRound(date: Date, unit = DateUnit.Day): Date
|
|
31
36
|
{
|
|
32
37
|
return new Date(Math.floor(date.getTime() / unit) * unit);
|
|
33
38
|
}
|
package/src/utils/iterator.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { SmartIterator } from "../models/index.js";
|
|
2
|
+
|
|
1
3
|
export function count<T>(elements: Iterable<T>): number
|
|
2
4
|
{
|
|
3
5
|
if (Array.isArray(elements)) { return elements.length; }
|
|
@@ -8,20 +10,23 @@ export function count<T>(elements: Iterable<T>): number
|
|
|
8
10
|
return _count;
|
|
9
11
|
}
|
|
10
12
|
|
|
11
|
-
export function range(end: number):
|
|
12
|
-
export function range(start: number, end: number):
|
|
13
|
-
export function range(start: number, end: number, step: number):
|
|
14
|
-
export function
|
|
13
|
+
export function range(end: number): SmartIterator<number>;
|
|
14
|
+
export function range(start: number, end: number): SmartIterator<number>;
|
|
15
|
+
export function range(start: number, end: number, step: number): SmartIterator<number>;
|
|
16
|
+
export function range(start: number, end?: number, step = 1): SmartIterator<number>
|
|
15
17
|
{
|
|
16
|
-
|
|
18
|
+
return new SmartIterator<number>(function* ()
|
|
17
19
|
{
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
|
|
20
|
+
if (end === undefined)
|
|
21
|
+
{
|
|
22
|
+
end = start;
|
|
23
|
+
start = 0;
|
|
24
|
+
}
|
|
21
25
|
|
|
22
|
-
|
|
26
|
+
if (start > end) { step = step ?? -1; }
|
|
23
27
|
|
|
24
|
-
|
|
28
|
+
for (let index = start; index < end; index += step) { yield index; }
|
|
29
|
+
});
|
|
25
30
|
}
|
|
26
31
|
|
|
27
32
|
export function shuffle<T>(iterable: Iterable<T>): T[]
|
|
@@ -38,23 +43,38 @@ export function shuffle<T>(iterable: Iterable<T>): T[]
|
|
|
38
43
|
return array;
|
|
39
44
|
}
|
|
40
45
|
|
|
41
|
-
export function unique<T>(elements: Iterable<T>): T
|
|
46
|
+
export function unique<T>(elements: Iterable<T>): SmartIterator<T>
|
|
42
47
|
{
|
|
43
|
-
return
|
|
48
|
+
return new SmartIterator<T>(function* ()
|
|
49
|
+
{
|
|
50
|
+
const seen = new Set<T>();
|
|
51
|
+
|
|
52
|
+
for (const element of elements)
|
|
53
|
+
{
|
|
54
|
+
if (seen.has(element)) { continue; }
|
|
55
|
+
|
|
56
|
+
seen.add(element);
|
|
57
|
+
|
|
58
|
+
yield element;
|
|
59
|
+
}
|
|
60
|
+
});
|
|
44
61
|
}
|
|
45
62
|
|
|
46
|
-
export function
|
|
63
|
+
export function zip<T, U>(first: Iterable<T>, second: Iterable<U>): SmartIterator<[T, U]>
|
|
47
64
|
{
|
|
48
|
-
|
|
49
|
-
const secondIterator = second[Symbol.iterator]();
|
|
50
|
-
|
|
51
|
-
while (true)
|
|
65
|
+
return new SmartIterator<[T, U]>(function* ()
|
|
52
66
|
{
|
|
53
|
-
const
|
|
54
|
-
const
|
|
67
|
+
const firstIterator = first[Symbol.iterator]();
|
|
68
|
+
const secondIterator = second[Symbol.iterator]();
|
|
55
69
|
|
|
56
|
-
|
|
70
|
+
while (true)
|
|
71
|
+
{
|
|
72
|
+
const firstResult = firstIterator.next();
|
|
73
|
+
const secondResult = secondIterator.next();
|
|
57
74
|
|
|
58
|
-
|
|
59
|
-
|
|
75
|
+
if ((firstResult.done) || (secondResult.done)) { break; }
|
|
76
|
+
|
|
77
|
+
yield [firstResult.value, secondResult.value];
|
|
78
|
+
}
|
|
79
|
+
});
|
|
60
80
|
}
|