@naturalcycles/js-lib 14.276.0 → 15.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cfg/frontend/tsconfig.json +3 -3
- package/dist/abort.js +1 -4
- package/dist/array/array.util.d.ts +1 -1
- package/dist/array/array.util.js +47 -88
- package/dist/array/range.d.ts +2 -2
- package/dist/array/range.js +7 -12
- package/dist/bot.js +6 -10
- package/dist/browser/adminService.d.ts +1 -1
- package/dist/browser/adminService.js +10 -14
- package/dist/browser/analytics.util.js +10 -15
- package/dist/browser/i18n/fetchTranslationLoader.d.ts +3 -3
- package/dist/browser/i18n/fetchTranslationLoader.js +1 -5
- package/dist/browser/i18n/translation.service.d.ts +1 -1
- package/dist/browser/i18n/translation.service.js +5 -10
- package/dist/browser/imageFitter.js +1 -5
- package/dist/browser/script.util.js +8 -12
- package/dist/browser/topbar.js +7 -10
- package/dist/datetime/dateInterval.d.ts +2 -2
- package/dist/datetime/dateInterval.js +7 -11
- package/dist/datetime/localDate.d.ts +3 -3
- package/dist/datetime/localDate.js +40 -44
- package/dist/datetime/localTime.d.ts +3 -3
- package/dist/datetime/localTime.js +36 -40
- package/dist/datetime/timeInterval.d.ts +2 -2
- package/dist/datetime/timeInterval.js +6 -10
- package/dist/datetime/wallTime.d.ts +3 -3
- package/dist/datetime/wallTime.js +5 -9
- package/dist/decorators/asyncMemo.decorator.d.ts +3 -3
- package/dist/decorators/asyncMemo.decorator.js +12 -17
- package/dist/decorators/createPromiseDecorator.js +3 -6
- package/dist/decorators/debounce.d.ts +1 -1
- package/dist/decorators/debounce.decorator.d.ts +1 -1
- package/dist/decorators/debounce.decorator.js +5 -9
- package/dist/decorators/debounce.js +2 -6
- package/dist/decorators/decorator.util.d.ts +1 -1
- package/dist/decorators/decorator.util.js +3 -8
- package/dist/decorators/logMethod.decorator.d.ts +1 -1
- package/dist/decorators/logMethod.decorator.js +11 -14
- package/dist/decorators/memo.decorator.d.ts +3 -3
- package/dist/decorators/memo.decorator.js +11 -16
- package/dist/decorators/memo.util.d.ts +2 -2
- package/dist/decorators/memo.util.js +11 -17
- package/dist/decorators/memoFn.d.ts +3 -3
- package/dist/decorators/memoFn.js +3 -6
- package/dist/decorators/memoFnAsync.d.ts +3 -3
- package/dist/decorators/memoFnAsync.js +5 -8
- package/dist/decorators/memoSimple.decorator.d.ts +1 -1
- package/dist/decorators/memoSimple.decorator.js +6 -10
- package/dist/decorators/retry.decorator.d.ts +1 -1
- package/dist/decorators/retry.decorator.js +3 -6
- package/dist/decorators/swarmSafe.decorator.js +3 -7
- package/dist/decorators/timeout.decorator.d.ts +1 -1
- package/dist/decorators/timeout.decorator.js +7 -10
- package/dist/define.d.ts +1 -1
- package/dist/define.js +11 -19
- package/dist/deviceIdService.js +7 -11
- package/dist/enum.util.d.ts +1 -1
- package/dist/enum.util.js +20 -42
- package/dist/env/buildInfo.d.ts +1 -1
- package/dist/env/buildInfo.js +3 -6
- package/dist/env.js +2 -6
- package/dist/error/assert.d.ts +3 -3
- package/dist/error/assert.js +30 -44
- package/dist/error/error.model.d.ts +2 -2
- package/dist/error/error.model.js +1 -2
- package/dist/error/error.util.d.ts +1 -1
- package/dist/error/error.util.js +25 -44
- package/dist/error/errorMode.js +2 -5
- package/dist/error/try.d.ts +2 -2
- package/dist/error/try.js +15 -23
- package/dist/error/tryCatch.d.ts +2 -2
- package/dist/error/tryCatch.js +6 -11
- package/dist/form.util.d.ts +1 -1
- package/dist/form.util.js +2 -6
- package/dist/http/fetcher.d.ts +3 -3
- package/dist/http/fetcher.js +48 -53
- package/dist/http/fetcher.model.d.ts +5 -5
- package/dist/http/fetcher.model.js +1 -2
- package/dist/http/http.model.js +1 -4
- package/dist/index.d.ts +96 -96
- package/dist/index.js +96 -99
- package/dist/is.util.d.ts +2 -2
- package/dist/is.util.js +12 -27
- package/dist/iter/asyncIterable2.d.ts +3 -3
- package/dist/iter/asyncIterable2.js +8 -12
- package/dist/iter/iterable2.d.ts +2 -2
- package/dist/iter/iterable2.js +8 -12
- package/dist/json-schema/from-data/generateJsonSchemaFromData.d.ts +1 -1
- package/dist/json-schema/from-data/generateJsonSchemaFromData.js +4 -7
- package/dist/json-schema/jsonSchema.cnst.d.ts +1 -1
- package/dist/json-schema/jsonSchema.cnst.js +1 -4
- package/dist/json-schema/jsonSchema.model.d.ts +1 -1
- package/dist/json-schema/jsonSchema.model.js +1 -2
- package/dist/json-schema/jsonSchema.util.d.ts +2 -2
- package/dist/json-schema/jsonSchema.util.js +5 -8
- package/dist/json-schema/jsonSchemaBuilder.d.ts +2 -2
- package/dist/json-schema/jsonSchemaBuilder.js +16 -25
- package/dist/json-schema/jsonSchemas.d.ts +2 -2
- package/dist/json-schema/jsonSchemas.js +5 -8
- package/dist/log/commonLogger.js +14 -21
- package/dist/math/accumulatingAverage.js +1 -5
- package/dist/math/math.util.js +11 -19
- package/dist/math/sma.js +1 -5
- package/dist/math/stack.util.js +11 -16
- package/dist/nanoid.js +2 -6
- package/dist/number/createDeterministicRandom.js +1 -4
- package/dist/number/number.util.d.ts +1 -1
- package/dist/number/number.util.js +9 -20
- package/dist/object/deepEquals.js +3 -8
- package/dist/object/map2.js +1 -5
- package/dist/object/object.util.d.ts +2 -2
- package/dist/object/object.util.js +40 -70
- package/dist/object/set2.js +1 -5
- package/dist/object/sortObject.d.ts +1 -1
- package/dist/object/sortObject.js +1 -4
- package/dist/object/sortObjectDeep.js +1 -4
- package/dist/polyfill.js +1 -4
- package/dist/promise/abortable.d.ts +1 -1
- package/dist/promise/abortable.js +2 -7
- package/dist/promise/pDefer.js +1 -4
- package/dist/promise/pDelay.d.ts +2 -2
- package/dist/promise/pDelay.js +4 -8
- package/dist/promise/pFilter.d.ts +1 -1
- package/dist/promise/pFilter.js +1 -4
- package/dist/promise/pHang.js +1 -4
- package/dist/promise/pMap.d.ts +2 -2
- package/dist/promise/pMap.js +17 -20
- package/dist/promise/pProps.js +1 -4
- package/dist/promise/pQueue.d.ts +2 -2
- package/dist/promise/pQueue.js +7 -11
- package/dist/promise/pRetry.d.ts +1 -1
- package/dist/promise/pRetry.js +8 -12
- package/dist/promise/pState.js +1 -4
- package/dist/promise/pTimeout.d.ts +3 -3
- package/dist/promise/pTimeout.js +7 -11
- package/dist/semver.d.ts +1 -1
- package/dist/semver.js +13 -18
- package/dist/string/case.js +9 -14
- package/dist/string/escape.js +2 -6
- package/dist/string/hash.util.d.ts +1 -1
- package/dist/string/hash.util.js +4 -10
- package/dist/string/json.util.d.ts +1 -1
- package/dist/string/json.util.js +5 -10
- package/dist/string/leven.js +1 -4
- package/dist/string/lodash/unicodeWords.js +1 -4
- package/dist/string/lodash/words.js +3 -6
- package/dist/string/pupa.d.ts +1 -1
- package/dist/string/pupa.js +4 -9
- package/dist/string/readingTime.d.ts +1 -1
- package/dist/string/readingTime.js +1 -4
- package/dist/string/regex.js +1 -4
- package/dist/string/safeJsonStringify.d.ts +1 -1
- package/dist/string/safeJsonStringify.js +1 -4
- package/dist/string/slugify.js +1 -4
- package/dist/string/string.util.js +15 -32
- package/dist/string/stringify.d.ts +1 -1
- package/dist/string/stringify.js +10 -14
- package/dist/string/url.util.d.ts +1 -1
- package/dist/string/url.util.js +2 -6
- package/dist/time/time.util.d.ts +1 -1
- package/dist/time/time.util.js +3 -8
- package/dist/typeFest.js +1 -2
- package/dist/types.d.ts +7 -3
- package/dist/types.js +21 -23
- package/dist/unit/size.util.js +5 -12
- package/dist/web.d.ts +1 -1
- package/dist/web.js +1 -5
- package/dist/zod/index.d.ts +2 -2
- package/dist/zod/index.js +4 -10
- package/dist/zod/zod.shared.schemas.js +36 -39
- package/dist/zod/zod.util.js +7 -14
- package/package.json +7 -8
- package/src/array/array.util.ts +3 -3
- package/src/array/range.ts +2 -2
- package/src/bot.ts +1 -1
- package/src/browser/adminService.ts +4 -4
- package/src/browser/analytics.util.ts +1 -1
- package/src/browser/i18n/fetchTranslationLoader.ts +3 -3
- package/src/browser/i18n/translation.service.ts +2 -2
- package/src/browser/script.util.ts +2 -2
- package/src/datetime/dateInterval.ts +3 -3
- package/src/datetime/localDate.ts +5 -5
- package/src/datetime/localTime.ts +6 -6
- package/src/datetime/timeInterval.ts +3 -3
- package/src/datetime/wallTime.ts +4 -4
- package/src/decorators/asyncMemo.decorator.ts +7 -7
- package/src/decorators/createPromiseDecorator.ts +1 -1
- package/src/decorators/debounce.decorator.ts +2 -2
- package/src/decorators/debounce.ts +1 -1
- package/src/decorators/decorator.util.ts +1 -1
- package/src/decorators/logMethod.decorator.ts +4 -4
- package/src/decorators/memo.decorator.ts +7 -7
- package/src/decorators/memo.util.ts +4 -4
- package/src/decorators/memoFn.ts +4 -4
- package/src/decorators/memoFnAsync.ts +5 -5
- package/src/decorators/memoSimple.decorator.ts +4 -4
- package/src/decorators/retry.decorator.ts +2 -2
- package/src/decorators/swarmSafe.decorator.ts +2 -2
- package/src/decorators/timeout.decorator.ts +4 -4
- package/src/define.ts +3 -3
- package/src/deviceIdService.ts +3 -3
- package/src/enum.util.ts +1 -1
- package/src/env/buildInfo.ts +2 -2
- package/src/error/assert.ts +7 -7
- package/src/error/error.model.ts +2 -2
- package/src/error/error.util.ts +5 -5
- package/src/error/try.ts +5 -5
- package/src/error/tryCatch.ts +3 -3
- package/src/form.util.ts +1 -1
- package/src/http/fetcher.model.ts +5 -5
- package/src/http/fetcher.ts +20 -15
- package/src/index.ts +96 -96
- package/src/is.util.ts +2 -2
- package/src/iter/asyncIterable2.ts +3 -3
- package/src/iter/iterable2.ts +2 -2
- package/src/json-schema/from-data/generateJsonSchemaFromData.ts +2 -2
- package/src/json-schema/jsonSchema.cnst.ts +1 -1
- package/src/json-schema/jsonSchema.model.ts +1 -1
- package/src/json-schema/jsonSchema.util.ts +4 -4
- package/src/json-schema/jsonSchemaBuilder.ts +5 -5
- package/src/json-schema/jsonSchemas.ts +2 -2
- package/src/math/math.util.ts +2 -2
- package/src/math/stack.util.ts +1 -1
- package/src/number/number.util.ts +1 -1
- package/src/object/object.util.ts +3 -3
- package/src/object/sortObject.ts +1 -1
- package/src/promise/abortable.ts +1 -1
- package/src/promise/pDelay.ts +3 -3
- package/src/promise/pFilter.ts +1 -1
- package/src/promise/pMap.ts +2 -2
- package/src/promise/pQueue.ts +4 -4
- package/src/promise/pRetry.ts +2 -2
- package/src/promise/pTimeout.ts +4 -4
- package/src/semver.ts +3 -3
- package/src/string/case.ts +2 -2
- package/src/string/hash.util.ts +1 -1
- package/src/string/json.util.ts +2 -2
- package/src/string/lodash/words.ts +1 -1
- package/src/string/pupa.ts +2 -2
- package/src/string/readingTime.ts +1 -1
- package/src/string/safeJsonStringify.ts +1 -1
- package/src/string/stringify.ts +4 -4
- package/src/string/url.util.ts +1 -1
- package/src/time/time.util.ts +1 -1
- package/src/types.ts +15 -3
- package/src/web.ts +1 -1
- package/src/zod/index.ts +2 -2
- package/src/zod/zod.util.ts +1 -1
- package/dist-esm/abort.js +0 -12
- package/dist-esm/array/array.util.js +0 -458
- package/dist-esm/array/range.js +0 -34
- package/dist-esm/bot.js +0 -130
- package/dist-esm/browser/adminService.js +0 -94
- package/dist-esm/browser/analytics.util.js +0 -54
- package/dist-esm/browser/i18n/fetchTranslationLoader.js +0 -13
- package/dist-esm/browser/i18n/translation.service.js +0 -56
- package/dist-esm/browser/imageFitter.js +0 -65
- package/dist-esm/browser/script.util.js +0 -46
- package/dist-esm/browser/topbar.js +0 -135
- package/dist-esm/datetime/dateInterval.js +0 -80
- package/dist-esm/datetime/localDate.js +0 -719
- package/dist-esm/datetime/localTime.js +0 -996
- package/dist-esm/datetime/timeInterval.js +0 -88
- package/dist-esm/datetime/wallTime.js +0 -70
- package/dist-esm/decorators/asyncMemo.decorator.js +0 -111
- package/dist-esm/decorators/createPromiseDecorator.js +0 -82
- package/dist-esm/decorators/debounce.decorator.js +0 -17
- package/dist-esm/decorators/debounce.js +0 -114
- package/dist-esm/decorators/decorator.util.js +0 -31
- package/dist-esm/decorators/logMethod.decorator.js +0 -85
- package/dist-esm/decorators/memo.decorator.js +0 -80
- package/dist-esm/decorators/memo.util.js +0 -97
- package/dist-esm/decorators/memoFn.js +0 -29
- package/dist-esm/decorators/memoFnAsync.js +0 -35
- package/dist-esm/decorators/memoSimple.decorator.js +0 -55
- package/dist-esm/decorators/retry.decorator.js +0 -9
- package/dist-esm/decorators/swarmSafe.decorator.js +0 -38
- package/dist-esm/decorators/timeout.decorator.js +0 -19
- package/dist-esm/define.js +0 -109
- package/dist-esm/deviceIdService.js +0 -105
- package/dist-esm/enum.util.js +0 -157
- package/dist-esm/env/buildInfo.js +0 -19
- package/dist-esm/env.js +0 -19
- package/dist-esm/error/assert.js +0 -122
- package/dist-esm/error/error.model.js +0 -1
- package/dist-esm/error/error.util.js +0 -337
- package/dist-esm/error/errorMode.js +0 -20
- package/dist-esm/error/try.js +0 -105
- package/dist-esm/error/tryCatch.js +0 -41
- package/dist-esm/form.util.js +0 -16
- package/dist-esm/http/fetcher.js +0 -704
- package/dist-esm/http/fetcher.model.js +0 -3
- package/dist-esm/http/http.model.js +0 -1
- package/dist-esm/index.js +0 -96
- package/dist-esm/is.util.js +0 -70
- package/dist-esm/iter/asyncIterable2.js +0 -103
- package/dist-esm/iter/iterable2.js +0 -87
- package/dist-esm/json-schema/from-data/generateJsonSchemaFromData.js +0 -86
- package/dist-esm/json-schema/jsonSchema.cnst.js +0 -38
- package/dist-esm/json-schema/jsonSchema.model.js +0 -1
- package/dist-esm/json-schema/jsonSchema.util.js +0 -27
- package/dist-esm/json-schema/jsonSchemaBuilder.js +0 -352
- package/dist-esm/json-schema/jsonSchemas.js +0 -6
- package/dist-esm/log/commonLogger.js +0 -78
- package/dist-esm/math/accumulatingAverage.js +0 -32
- package/dist-esm/math/math.util.js +0 -85
- package/dist-esm/math/sma.js +0 -43
- package/dist-esm/math/stack.util.js +0 -82
- package/dist-esm/nanoid.js +0 -57
- package/dist-esm/number/createDeterministicRandom.js +0 -18
- package/dist-esm/number/number.util.js +0 -109
- package/dist-esm/object/deepEquals.js +0 -170
- package/dist-esm/object/map2.js +0 -21
- package/dist-esm/object/object.util.js +0 -435
- package/dist-esm/object/set2.js +0 -15
- package/dist-esm/object/sortObject.js +0 -21
- package/dist-esm/object/sortObjectDeep.js +0 -17
- package/dist-esm/polyfill.js +0 -6
- package/dist-esm/promise/abortable.js +0 -31
- package/dist-esm/promise/pDefer.js +0 -17
- package/dist-esm/promise/pDelay.js +0 -37
- package/dist-esm/promise/pFilter.js +0 -5
- package/dist-esm/promise/pHang.js +0 -6
- package/dist-esm/promise/pMap.js +0 -174
- package/dist-esm/promise/pProps.js +0 -20
- package/dist-esm/promise/pQueue.js +0 -101
- package/dist-esm/promise/pRetry.js +0 -64
- package/dist-esm/promise/pState.js +0 -14
- package/dist-esm/promise/pTimeout.js +0 -64
- package/dist-esm/semver.js +0 -149
- package/dist-esm/string/case.js +0 -24
- package/dist-esm/string/escape.js +0 -49
- package/dist-esm/string/hash.util.js +0 -67
- package/dist-esm/string/json.util.js +0 -46
- package/dist-esm/string/leven.js +0 -77
- package/dist-esm/string/lodash/unicodeWords.js +0 -68
- package/dist-esm/string/lodash/words.js +0 -31
- package/dist-esm/string/pupa.js +0 -54
- package/dist-esm/string/readingTime.js +0 -102
- package/dist-esm/string/regex.js +0 -6
- package/dist-esm/string/safeJsonStringify.js +0 -39
- package/dist-esm/string/slugify.js +0 -66
- package/dist-esm/string/string.util.js +0 -99
- package/dist-esm/string/stringify.js +0 -133
- package/dist-esm/string/url.util.js +0 -42
- package/dist-esm/time/time.util.js +0 -61
- package/dist-esm/typeFest.js +0 -2
- package/dist-esm/types.js +0 -59
- package/dist-esm/unit/size.util.js +0 -43
- package/dist-esm/web.js +0 -40
- package/dist-esm/zod/index.js +0 -4
- package/dist-esm/zod/zod.shared.schemas.js +0 -92
- package/dist-esm/zod/zod.util.js +0 -52
package/dist/iter/iterable2.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Iterable2 = void 0;
|
|
4
|
-
const types_1 = require("../types");
|
|
1
|
+
import { END, SKIP } from '../types.js';
|
|
5
2
|
/**
|
|
6
3
|
* Iterable2 is a wrapper around Iterable that implements "Iterator Helpers proposal":
|
|
7
4
|
* https://github.com/tc39/proposal-iterator-helpers
|
|
@@ -10,7 +7,7 @@ const types_1 = require("../types");
|
|
|
10
7
|
*
|
|
11
8
|
* @experimental
|
|
12
9
|
*/
|
|
13
|
-
class Iterable2 {
|
|
10
|
+
export class Iterable2 {
|
|
14
11
|
it;
|
|
15
12
|
constructor(it) {
|
|
16
13
|
this.it = it;
|
|
@@ -30,7 +27,7 @@ class Iterable2 {
|
|
|
30
27
|
forEach(cb) {
|
|
31
28
|
let i = 0;
|
|
32
29
|
for (const v of this.it) {
|
|
33
|
-
if (cb(v, i++) ===
|
|
30
|
+
if (cb(v, i++) === END)
|
|
34
31
|
return;
|
|
35
32
|
}
|
|
36
33
|
}
|
|
@@ -42,7 +39,7 @@ class Iterable2 {
|
|
|
42
39
|
let i = 0;
|
|
43
40
|
for (const v of this.it) {
|
|
44
41
|
const r = cb(v, i++);
|
|
45
|
-
if (r ===
|
|
42
|
+
if (r === END || !r)
|
|
46
43
|
return false;
|
|
47
44
|
}
|
|
48
45
|
return true;
|
|
@@ -51,7 +48,7 @@ class Iterable2 {
|
|
|
51
48
|
let i = 0;
|
|
52
49
|
for (const v of this.it) {
|
|
53
50
|
const r = cb(v, i++);
|
|
54
|
-
if (r ===
|
|
51
|
+
if (r === END)
|
|
55
52
|
return;
|
|
56
53
|
if (r)
|
|
57
54
|
return v;
|
|
@@ -64,7 +61,7 @@ class Iterable2 {
|
|
|
64
61
|
let i = 0;
|
|
65
62
|
for (const v of it) {
|
|
66
63
|
const r = cb(v, i++);
|
|
67
|
-
if (r ===
|
|
64
|
+
if (r === END)
|
|
68
65
|
return;
|
|
69
66
|
if (r)
|
|
70
67
|
yield v;
|
|
@@ -79,9 +76,9 @@ class Iterable2 {
|
|
|
79
76
|
let i = 0;
|
|
80
77
|
for (const v of it) {
|
|
81
78
|
const r = mapper(v, i++);
|
|
82
|
-
if (r ===
|
|
79
|
+
if (r === END)
|
|
83
80
|
return;
|
|
84
|
-
if (r ===
|
|
81
|
+
if (r === SKIP)
|
|
85
82
|
continue;
|
|
86
83
|
yield r;
|
|
87
84
|
}
|
|
@@ -89,4 +86,3 @@ class Iterable2 {
|
|
|
89
86
|
});
|
|
90
87
|
}
|
|
91
88
|
}
|
|
92
|
-
exports.Iterable2 = Iterable2;
|
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateJsonSchemaFromData = generateJsonSchemaFromData;
|
|
4
|
-
const __1 = require("../..");
|
|
1
|
+
import { _stringMapEntries, _uniq } from '../../index.js';
|
|
5
2
|
/**
|
|
6
3
|
* Each row must be an object (current limitation).
|
|
7
4
|
*
|
|
8
5
|
* `additionalProperties` is set to `true`, cause it's safer.
|
|
9
6
|
*/
|
|
10
|
-
function generateJsonSchemaFromData(rows) {
|
|
7
|
+
export function generateJsonSchemaFromData(rows) {
|
|
11
8
|
return objectToJsonSchema(rows);
|
|
12
9
|
}
|
|
13
10
|
function objectToJsonSchema(rows) {
|
|
@@ -24,7 +21,7 @@ function objectToJsonSchema(rows) {
|
|
|
24
21
|
required: [],
|
|
25
22
|
additionalProperties: true,
|
|
26
23
|
};
|
|
27
|
-
|
|
24
|
+
_stringMapEntries(typesByKey).forEach(([key, types]) => {
|
|
28
25
|
const schema = mergeTypes([...types], rows.map(r => r[key]));
|
|
29
26
|
if (!schema)
|
|
30
27
|
return;
|
|
@@ -73,7 +70,7 @@ function mergeTypes(types, samples) {
|
|
|
73
70
|
// possible feature: detect if it's a tuple
|
|
74
71
|
// currently assume no-tuple
|
|
75
72
|
const items = samples.filter(r => Array.isArray(r)).flat(1);
|
|
76
|
-
const itemTypes =
|
|
73
|
+
const itemTypes = _uniq(items.map(i => getTypeOfValue(i)));
|
|
77
74
|
return {
|
|
78
75
|
type: 'array',
|
|
79
76
|
items: mergeTypes(itemTypes, items),
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { JsonSchema, JsonSchemaAny, JsonSchemaNumber, JsonSchemaObject, JsonSchemaString } from './jsonSchema.model';
|
|
1
|
+
import type { JsonSchema, JsonSchemaAny, JsonSchemaNumber, JsonSchemaObject, JsonSchemaString } from './jsonSchema.model.js';
|
|
2
2
|
export declare const JSON_SCHEMA_ORDER: (keyof JsonSchema | keyof JsonSchemaAny | keyof JsonSchemaObject | keyof JsonSchemaString | keyof JsonSchemaNumber)[];
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AnyObject, StringMap } from '../types';
|
|
1
|
+
import type { AnyObject, StringMap } from '../types.js';
|
|
2
2
|
export type JsonSchema<T = unknown> = JsonSchemaAny<T> | JsonSchemaOneOf<T> | JsonSchemaAllOf<T> | JsonSchemaAnyOf<T> | JsonSchemaNot<T> | JsonSchemaRef<T> | JsonSchemaConst<T> | JsonSchemaEnum<T> | JsonSchemaString | JsonSchemaNumber | JsonSchemaBoolean | JsonSchemaNull | JsonSchemaObject | JsonSchemaArray<T> | JsonSchemaTuple<T>;
|
|
3
3
|
export interface JsonSchemaAny<T = unknown> {
|
|
4
4
|
$schema?: string;
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { AnyObject } from '../index';
|
|
2
|
-
import type { JsonSchemaObject } from './jsonSchema.model';
|
|
1
|
+
import type { AnyObject } from '../index.js';
|
|
2
|
+
import type { JsonSchemaObject } from './jsonSchema.model.js';
|
|
3
3
|
/**
|
|
4
4
|
* Merges s2 into s1 (mutates s1) and returns s1.
|
|
5
5
|
* Does not mutate s2.
|
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.mergeJsonSchemaObjects = mergeJsonSchemaObjects;
|
|
4
|
-
const index_1 = require("../index");
|
|
5
|
-
const object_util_1 = require("../object/object.util");
|
|
1
|
+
import { _uniq } from '../index.js';
|
|
2
|
+
import { _filterNullishValues } from '../object/object.util.js';
|
|
6
3
|
/**
|
|
7
4
|
* Merges s2 into s1 (mutates s1) and returns s1.
|
|
8
5
|
* Does not mutate s2.
|
|
9
6
|
* API similar to Object.assign(s1, s2)
|
|
10
7
|
*/
|
|
11
|
-
function mergeJsonSchemaObjects(s1, s2) {
|
|
8
|
+
export function mergeJsonSchemaObjects(s1, s2) {
|
|
12
9
|
// Merge `properties`
|
|
13
10
|
Object.entries(s2.properties).forEach(([k, v]) => {
|
|
14
11
|
;
|
|
@@ -24,7 +21,7 @@ function mergeJsonSchemaObjects(s1, s2) {
|
|
|
24
21
|
s1.maxProperties = s2.maxProperties ?? s1.maxProperties;
|
|
25
22
|
// Merge `required`
|
|
26
23
|
s1.required.push(...s2.required);
|
|
27
|
-
s1.required =
|
|
24
|
+
s1.required = _uniq(s1.required).sort();
|
|
28
25
|
// `additionalProperties` remains the same
|
|
29
|
-
return
|
|
26
|
+
return _filterNullishValues(s1, true);
|
|
30
27
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { AnyObject, BaseDBEntity, JsonSchemaAllOf, JsonSchemaArray, JsonSchemaOneOf, JsonSchemaTuple } from '../index';
|
|
2
|
-
import type { JsonSchema, JsonSchemaAny, JsonSchemaBoolean, JsonSchemaConst, JsonSchemaEnum, JsonSchemaNull, JsonSchemaNumber, JsonSchemaObject, JsonSchemaRef, JsonSchemaString } from './jsonSchema.model';
|
|
1
|
+
import type { AnyObject, BaseDBEntity, JsonSchemaAllOf, JsonSchemaArray, JsonSchemaOneOf, JsonSchemaTuple } from '../index.js';
|
|
2
|
+
import type { JsonSchema, JsonSchemaAny, JsonSchemaBoolean, JsonSchemaConst, JsonSchemaEnum, JsonSchemaNull, JsonSchemaNumber, JsonSchemaObject, JsonSchemaRef, JsonSchemaString } from './jsonSchema.model.js';
|
|
3
3
|
export interface JsonSchemaBuilder<T = unknown> {
|
|
4
4
|
build: () => JsonSchema<T>;
|
|
5
5
|
}
|
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const array_util_1 = require("../array/array.util");
|
|
5
|
-
const index_1 = require("../index");
|
|
6
|
-
const jsonSchema_cnst_1 = require("./jsonSchema.cnst");
|
|
1
|
+
import { _uniq } from '../array/array.util.js';
|
|
2
|
+
import { _deepCopy, _sortObject, mergeJsonSchemaObjects } from '../index.js';
|
|
3
|
+
import { JSON_SCHEMA_ORDER } from './jsonSchema.cnst.js';
|
|
7
4
|
/**
|
|
8
5
|
* Fluent (chainable) API to manually create Json Schemas.
|
|
9
6
|
* Inspired by Joi
|
|
10
7
|
*/
|
|
11
|
-
|
|
8
|
+
export const jsonSchema = {
|
|
12
9
|
any() {
|
|
13
10
|
return new JsonSchemaAnyBuilder({});
|
|
14
11
|
},
|
|
@@ -85,7 +82,7 @@ exports.jsonSchema = {
|
|
|
85
82
|
});
|
|
86
83
|
},
|
|
87
84
|
};
|
|
88
|
-
class JsonSchemaAnyBuilder {
|
|
85
|
+
export class JsonSchemaAnyBuilder {
|
|
89
86
|
schema;
|
|
90
87
|
constructor(schema) {
|
|
91
88
|
this.schema = schema;
|
|
@@ -154,14 +151,13 @@ class JsonSchemaAnyBuilder {
|
|
|
154
151
|
* Same as if it would be JSON.stringified.
|
|
155
152
|
*/
|
|
156
153
|
build() {
|
|
157
|
-
return
|
|
154
|
+
return _sortObject(JSON.parse(JSON.stringify(this.schema)), JSON_SCHEMA_ORDER);
|
|
158
155
|
}
|
|
159
156
|
clone() {
|
|
160
|
-
return new JsonSchemaAnyBuilder(
|
|
157
|
+
return new JsonSchemaAnyBuilder(_deepCopy(this.schema));
|
|
161
158
|
}
|
|
162
159
|
}
|
|
163
|
-
|
|
164
|
-
class JsonSchemaNumberBuilder extends JsonSchemaAnyBuilder {
|
|
160
|
+
export class JsonSchemaNumberBuilder extends JsonSchemaAnyBuilder {
|
|
165
161
|
constructor() {
|
|
166
162
|
super({
|
|
167
163
|
type: 'number',
|
|
@@ -213,8 +209,7 @@ class JsonSchemaNumberBuilder extends JsonSchemaAnyBuilder {
|
|
|
213
209
|
utcOffset = () => this.format('utcOffset');
|
|
214
210
|
utcOffsetHours = () => this.format('utcOffsetHours');
|
|
215
211
|
}
|
|
216
|
-
|
|
217
|
-
class JsonSchemaStringBuilder extends JsonSchemaAnyBuilder {
|
|
212
|
+
export class JsonSchemaStringBuilder extends JsonSchemaAnyBuilder {
|
|
218
213
|
constructor() {
|
|
219
214
|
super({
|
|
220
215
|
type: 'string',
|
|
@@ -257,7 +252,7 @@ class JsonSchemaStringBuilder extends JsonSchemaAnyBuilder {
|
|
|
257
252
|
toUpperCase = (toUpperCase = true) => this.transformModify('toUpperCase', toUpperCase);
|
|
258
253
|
transformModify(t, add) {
|
|
259
254
|
if (add) {
|
|
260
|
-
this.schema.transform =
|
|
255
|
+
this.schema.transform = _uniq([...(this.schema.transform || []), t]);
|
|
261
256
|
}
|
|
262
257
|
else {
|
|
263
258
|
this.schema.transform = this.schema.transform?.filter(s => s !== t);
|
|
@@ -265,8 +260,7 @@ class JsonSchemaStringBuilder extends JsonSchemaAnyBuilder {
|
|
|
265
260
|
return this;
|
|
266
261
|
}
|
|
267
262
|
}
|
|
268
|
-
|
|
269
|
-
class JsonSchemaObjectBuilder extends JsonSchemaAnyBuilder {
|
|
263
|
+
export class JsonSchemaObjectBuilder extends JsonSchemaAnyBuilder {
|
|
270
264
|
constructor() {
|
|
271
265
|
super({
|
|
272
266
|
type: 'object',
|
|
@@ -294,7 +288,7 @@ class JsonSchemaObjectBuilder extends JsonSchemaAnyBuilder {
|
|
|
294
288
|
*/
|
|
295
289
|
required(required) {
|
|
296
290
|
Object.assign(this.schema, { required });
|
|
297
|
-
this.schema.required =
|
|
291
|
+
this.schema.required = _uniq(required).sort();
|
|
298
292
|
return this;
|
|
299
293
|
}
|
|
300
294
|
addRequired(required) {
|
|
@@ -322,13 +316,12 @@ class JsonSchemaObjectBuilder extends JsonSchemaAnyBuilder {
|
|
|
322
316
|
}
|
|
323
317
|
extend(s2) {
|
|
324
318
|
const builder = new JsonSchemaObjectBuilder();
|
|
325
|
-
Object.assign(builder.schema,
|
|
326
|
-
|
|
319
|
+
Object.assign(builder.schema, _deepCopy(this.schema));
|
|
320
|
+
mergeJsonSchemaObjects(builder.schema, s2.schema);
|
|
327
321
|
return builder;
|
|
328
322
|
}
|
|
329
323
|
}
|
|
330
|
-
|
|
331
|
-
class JsonSchemaArrayBuilder extends JsonSchemaAnyBuilder {
|
|
324
|
+
export class JsonSchemaArrayBuilder extends JsonSchemaAnyBuilder {
|
|
332
325
|
constructor(itemsSchema) {
|
|
333
326
|
super({
|
|
334
327
|
type: 'array',
|
|
@@ -348,8 +341,7 @@ class JsonSchemaArrayBuilder extends JsonSchemaAnyBuilder {
|
|
|
348
341
|
return this;
|
|
349
342
|
}
|
|
350
343
|
}
|
|
351
|
-
|
|
352
|
-
class JsonSchemaTupleBuilder extends JsonSchemaAnyBuilder {
|
|
344
|
+
export class JsonSchemaTupleBuilder extends JsonSchemaAnyBuilder {
|
|
353
345
|
constructor(items) {
|
|
354
346
|
super({
|
|
355
347
|
type: 'array',
|
|
@@ -359,4 +351,3 @@ class JsonSchemaTupleBuilder extends JsonSchemaAnyBuilder {
|
|
|
359
351
|
});
|
|
360
352
|
}
|
|
361
353
|
}
|
|
362
|
-
exports.JsonSchemaTupleBuilder = JsonSchemaTupleBuilder;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { BaseDBEntity } from '../types';
|
|
2
|
-
export declare const baseDBEntityJsonSchema: import("./jsonSchemaBuilder").JsonSchemaObjectBuilder<BaseDBEntity>;
|
|
1
|
+
import type { BaseDBEntity } from '../types.js';
|
|
2
|
+
export declare const baseDBEntityJsonSchema: import("./jsonSchemaBuilder.js").JsonSchemaObjectBuilder<BaseDBEntity>;
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
id: jsonSchemaBuilder_1.jsonSchema.string(),
|
|
7
|
-
created: jsonSchemaBuilder_1.jsonSchema.unixTimestamp2000(),
|
|
8
|
-
updated: jsonSchemaBuilder_1.jsonSchema.unixTimestamp2000(),
|
|
1
|
+
import { jsonSchema } from './jsonSchemaBuilder.js';
|
|
2
|
+
export const baseDBEntityJsonSchema = jsonSchema.object({
|
|
3
|
+
id: jsonSchema.string(),
|
|
4
|
+
created: jsonSchema.unixTimestamp2000(),
|
|
5
|
+
updated: jsonSchema.unixTimestamp2000(),
|
|
9
6
|
});
|
package/dist/log/commonLogger.js
CHANGED
|
@@ -1,13 +1,6 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.commonLoggerNoop = exports.commonLogLevelNumber = void 0;
|
|
4
|
-
exports.commonLoggerMinLevel = commonLoggerMinLevel;
|
|
5
|
-
exports.commonLoggerPipe = commonLoggerPipe;
|
|
6
|
-
exports.commonLoggerPrefix = commonLoggerPrefix;
|
|
7
|
-
exports.commonLoggerCreate = commonLoggerCreate;
|
|
8
1
|
// copy-pasted to avoid weird circular dependency
|
|
9
2
|
const _noop = (..._args) => undefined;
|
|
10
|
-
|
|
3
|
+
export const commonLogLevelNumber = {
|
|
11
4
|
log: 10,
|
|
12
5
|
warn: 20,
|
|
13
6
|
error: 30,
|
|
@@ -17,7 +10,7 @@ exports.commonLogLevelNumber = {
|
|
|
17
10
|
*
|
|
18
11
|
* @experimental
|
|
19
12
|
*/
|
|
20
|
-
|
|
13
|
+
export const commonLoggerNoop = {
|
|
21
14
|
log: _noop,
|
|
22
15
|
warn: _noop,
|
|
23
16
|
error: _noop,
|
|
@@ -25,38 +18,38 @@ exports.commonLoggerNoop = {
|
|
|
25
18
|
/**
|
|
26
19
|
* Creates a "child" logger that is "limited" to the specified CommonLogLevel.
|
|
27
20
|
*/
|
|
28
|
-
function commonLoggerMinLevel(logger, minLevel, mutate = false) {
|
|
29
|
-
const level =
|
|
21
|
+
export function commonLoggerMinLevel(logger, minLevel, mutate = false) {
|
|
22
|
+
const level = commonLogLevelNumber[minLevel];
|
|
30
23
|
if (mutate) {
|
|
31
|
-
if (level >
|
|
24
|
+
if (level > commonLogLevelNumber['log']) {
|
|
32
25
|
logger.log = _noop;
|
|
33
|
-
if (level >
|
|
26
|
+
if (level > commonLogLevelNumber['warn']) {
|
|
34
27
|
logger.warn = _noop;
|
|
35
|
-
if (level >
|
|
28
|
+
if (level > commonLogLevelNumber['error']) {
|
|
36
29
|
logger.error = _noop;
|
|
37
30
|
}
|
|
38
31
|
}
|
|
39
32
|
}
|
|
40
33
|
return logger;
|
|
41
34
|
}
|
|
42
|
-
if (level <=
|
|
35
|
+
if (level <= commonLogLevelNumber['log']) {
|
|
43
36
|
// All levels are kept
|
|
44
37
|
return logger;
|
|
45
38
|
}
|
|
46
|
-
if (level >
|
|
39
|
+
if (level > commonLogLevelNumber['error']) {
|
|
47
40
|
// "Log nothing" logger
|
|
48
|
-
return
|
|
41
|
+
return commonLoggerNoop;
|
|
49
42
|
}
|
|
50
43
|
return {
|
|
51
44
|
log: _noop, // otherwise it is "log everything" logger (same logger as input)
|
|
52
|
-
warn: level <=
|
|
45
|
+
warn: level <= commonLogLevelNumber['warn'] ? logger.warn.bind(logger) : _noop,
|
|
53
46
|
error: logger.error.bind(logger), // otherwise it's "log nothing" logger (same as noopLogger)
|
|
54
47
|
};
|
|
55
48
|
}
|
|
56
49
|
/**
|
|
57
50
|
* Creates a "proxy" CommonLogger that pipes log messages to all provided sub-loggers.
|
|
58
51
|
*/
|
|
59
|
-
function commonLoggerPipe(loggers) {
|
|
52
|
+
export function commonLoggerPipe(loggers) {
|
|
60
53
|
return {
|
|
61
54
|
log: (...args) => loggers.forEach(logger => logger.log(...args)),
|
|
62
55
|
warn: (...args) => loggers.forEach(logger => logger.warn(...args)),
|
|
@@ -66,7 +59,7 @@ function commonLoggerPipe(loggers) {
|
|
|
66
59
|
/**
|
|
67
60
|
* Creates a "child" CommonLogger with prefix (one or multiple).
|
|
68
61
|
*/
|
|
69
|
-
function commonLoggerPrefix(logger, ...prefixes) {
|
|
62
|
+
export function commonLoggerPrefix(logger, ...prefixes) {
|
|
70
63
|
return {
|
|
71
64
|
log: (...args) => logger.log(...prefixes, ...args),
|
|
72
65
|
warn: (...args) => logger.warn(...prefixes, ...args),
|
|
@@ -76,7 +69,7 @@ function commonLoggerPrefix(logger, ...prefixes) {
|
|
|
76
69
|
/**
|
|
77
70
|
* Creates a CommonLogger from a single function that takes `level` and `args`.
|
|
78
71
|
*/
|
|
79
|
-
function commonLoggerCreate(fn) {
|
|
72
|
+
export function commonLoggerCreate(fn) {
|
|
80
73
|
return {
|
|
81
74
|
log: (...args) => fn('log', args),
|
|
82
75
|
warn: (...args) => fn('warn', args),
|
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AccumulatingAverage = void 0;
|
|
4
1
|
/**
|
|
5
2
|
* Container that allows to accumulate average of a set of numbers,
|
|
6
3
|
* without the need to store all of them in memory.
|
|
7
4
|
*
|
|
8
5
|
* @experimental
|
|
9
6
|
*/
|
|
10
|
-
class AccumulatingAverage {
|
|
7
|
+
export class AccumulatingAverage {
|
|
11
8
|
total = 0;
|
|
12
9
|
count = 0;
|
|
13
10
|
/**
|
|
@@ -31,4 +28,3 @@ class AccumulatingAverage {
|
|
|
31
28
|
this.count = 0;
|
|
32
29
|
}
|
|
33
30
|
}
|
|
34
|
-
exports.AccumulatingAverage = AccumulatingAverage;
|
package/dist/math/math.util.js
CHANGED
|
@@ -1,13 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports._average = _average;
|
|
4
|
-
exports._averageOrNull = _averageOrNull;
|
|
5
|
-
exports._averageWeighted = _averageWeighted;
|
|
6
|
-
exports._percentile = _percentile;
|
|
7
|
-
exports._percentiles = _percentiles;
|
|
8
|
-
exports._median = _median;
|
|
9
|
-
const assert_1 = require("../error/assert");
|
|
10
|
-
const number_util_1 = require("../number/number.util");
|
|
1
|
+
import { _assert } from '../error/assert.js';
|
|
2
|
+
import { _sortNumbers } from '../number/number.util.js';
|
|
11
3
|
/**
|
|
12
4
|
* @returns Average of the array of numbers
|
|
13
5
|
*
|
|
@@ -16,8 +8,8 @@ const number_util_1 = require("../number/number.util");
|
|
|
16
8
|
* _average([1, 2, 3, 4])
|
|
17
9
|
* // 2.5
|
|
18
10
|
*/
|
|
19
|
-
function _average(values) {
|
|
20
|
-
|
|
11
|
+
export function _average(values) {
|
|
12
|
+
_assert(values.length, '_average is called on empty array');
|
|
21
13
|
let total = 0;
|
|
22
14
|
for (const n of values)
|
|
23
15
|
total += n;
|
|
@@ -26,13 +18,13 @@ function _average(values) {
|
|
|
26
18
|
/**
|
|
27
19
|
* Same as _average, but safely returns null if input array is empty or nullish.
|
|
28
20
|
*/
|
|
29
|
-
function _averageOrNull(values) {
|
|
21
|
+
export function _averageOrNull(values) {
|
|
30
22
|
return values?.length ? _average(values) : null;
|
|
31
23
|
}
|
|
32
24
|
/**
|
|
33
25
|
* valuesArray and weightsArray length is expected to be the same.
|
|
34
26
|
*/
|
|
35
|
-
function _averageWeighted(values, weights) {
|
|
27
|
+
export function _averageWeighted(values, weights) {
|
|
36
28
|
let numerator = 0;
|
|
37
29
|
let denominator = 0;
|
|
38
30
|
// eslint-disable-next-line unicorn/no-for-loop
|
|
@@ -54,8 +46,8 @@ function _averageWeighted(values, weights) {
|
|
|
54
46
|
* _percentile([1, 2, 3], 100)
|
|
55
47
|
* // 3
|
|
56
48
|
*/
|
|
57
|
-
function _percentile(values, pc) {
|
|
58
|
-
const sorted =
|
|
49
|
+
export function _percentile(values, pc) {
|
|
50
|
+
const sorted = _sortNumbers(values);
|
|
59
51
|
// Floating pos in the range of [0; length - 1]
|
|
60
52
|
const pos = ((values.length - 1) * pc) / 100;
|
|
61
53
|
const dec = pos % 1;
|
|
@@ -66,9 +58,9 @@ function _percentile(values, pc) {
|
|
|
66
58
|
/**
|
|
67
59
|
* A tiny bit more efficient function than calling _percentile individually.
|
|
68
60
|
*/
|
|
69
|
-
function _percentiles(values, pcs) {
|
|
61
|
+
export function _percentiles(values, pcs) {
|
|
70
62
|
const r = {};
|
|
71
|
-
const sorted =
|
|
63
|
+
const sorted = _sortNumbers(values);
|
|
72
64
|
for (const pc of pcs) {
|
|
73
65
|
// Floating pos in the range of [0; length - 1]
|
|
74
66
|
const pos = ((values.length - 1) * pc) / 100;
|
|
@@ -88,6 +80,6 @@ function _percentiles(values, pcs) {
|
|
|
88
80
|
* _median([1, 2, 3, 4])
|
|
89
81
|
* // 2.5
|
|
90
82
|
*/
|
|
91
|
-
function _median(values) {
|
|
83
|
+
export function _median(values) {
|
|
92
84
|
return _percentile(values, 50);
|
|
93
85
|
}
|
package/dist/math/sma.js
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SimpleMovingAverage = void 0;
|
|
4
1
|
/**
|
|
5
2
|
* Implements a Simple Moving Average algorithm.
|
|
6
3
|
*/
|
|
7
|
-
class SimpleMovingAverage {
|
|
4
|
+
export class SimpleMovingAverage {
|
|
8
5
|
size;
|
|
9
6
|
data;
|
|
10
7
|
constructor(size, data = []) {
|
|
@@ -46,4 +43,3 @@ class SimpleMovingAverage {
|
|
|
46
43
|
: this.nextIndex + 1;
|
|
47
44
|
}
|
|
48
45
|
}
|
|
49
|
-
exports.SimpleMovingAverage = SimpleMovingAverage;
|
package/dist/math/stack.util.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.NumberStack = exports.Stack = void 0;
|
|
4
|
-
const index_1 = require("../index");
|
|
1
|
+
import { _average, _percentile, _percentiles, _range } from '../index.js';
|
|
5
2
|
/**
|
|
6
3
|
* Implements a "round-robin" Stack ("first-in last-out" aka FILO) with a limited size.
|
|
7
4
|
* Like an array of a fixed size. When it runs out of space - it starts writing on top of itself
|
|
@@ -9,7 +6,7 @@ const index_1 = require("../index");
|
|
|
9
6
|
*
|
|
10
7
|
*
|
|
11
8
|
*/
|
|
12
|
-
class Stack {
|
|
9
|
+
export class Stack {
|
|
13
10
|
size;
|
|
14
11
|
constructor(size) {
|
|
15
12
|
this.size = size;
|
|
@@ -29,7 +26,7 @@ class Stack {
|
|
|
29
26
|
* Fill (overwrite) the whole Stack (all its items) with the passed `item`.
|
|
30
27
|
*/
|
|
31
28
|
fill(item) {
|
|
32
|
-
|
|
29
|
+
_range(this.size).forEach(i => (this.items[i] = item));
|
|
33
30
|
return this;
|
|
34
31
|
}
|
|
35
32
|
/**
|
|
@@ -45,44 +42,42 @@ class Stack {
|
|
|
45
42
|
return [...this.items.slice(this.nextIndex), ...this.items.slice(0, this.nextIndex)];
|
|
46
43
|
}
|
|
47
44
|
}
|
|
48
|
-
exports.Stack = Stack;
|
|
49
45
|
/**
|
|
50
46
|
* Fixed-size FILO stack of Numbers.
|
|
51
47
|
* Has convenience stat methods, e.g percentile, avg, etc.
|
|
52
48
|
*/
|
|
53
|
-
class NumberStack extends Stack {
|
|
49
|
+
export class NumberStack extends Stack {
|
|
54
50
|
avg() {
|
|
55
51
|
// _assert(this.items.length, 'NumberStack.avg cannot be called on empty stack')
|
|
56
|
-
return
|
|
52
|
+
return _average(this.items);
|
|
57
53
|
}
|
|
58
54
|
/**
|
|
59
55
|
* Returns null if Stack is empty.
|
|
60
56
|
*/
|
|
61
57
|
avgOrNull() {
|
|
62
|
-
return this.items.length === 0 ? null :
|
|
58
|
+
return this.items.length === 0 ? null : _average(this.items);
|
|
63
59
|
}
|
|
64
60
|
median() {
|
|
65
|
-
return
|
|
61
|
+
return _percentile(this.items, 50);
|
|
66
62
|
}
|
|
67
63
|
medianOrNull() {
|
|
68
|
-
return this.items.length === 0 ? null :
|
|
64
|
+
return this.items.length === 0 ? null : _percentile(this.items, 50);
|
|
69
65
|
}
|
|
70
66
|
/**
|
|
71
67
|
* `pc` is a number from 0 to 100 inclusive.
|
|
72
68
|
*/
|
|
73
69
|
percentile(pc) {
|
|
74
70
|
// _assert(this.items.length, 'NumberStack.percentile cannot be called on empty stack')
|
|
75
|
-
return
|
|
71
|
+
return _percentile(this.items, pc);
|
|
76
72
|
}
|
|
77
73
|
/**
|
|
78
74
|
* `pc` is a number from 0 to 100 inclusive.
|
|
79
75
|
* Returns null if Stack is empty.
|
|
80
76
|
*/
|
|
81
77
|
percentileOrNull(pc) {
|
|
82
|
-
return this.items.length === 0 ? null :
|
|
78
|
+
return this.items.length === 0 ? null : _percentile(this.items, pc);
|
|
83
79
|
}
|
|
84
80
|
percentiles(pcs) {
|
|
85
|
-
return
|
|
81
|
+
return _percentiles(this.items, pcs);
|
|
86
82
|
}
|
|
87
83
|
}
|
|
88
|
-
exports.NumberStack = NumberStack;
|
package/dist/nanoid.js
CHANGED
|
@@ -1,15 +1,11 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
// Vendored from https://github.com/ai/nanoid/blob/main/index.browser.js
|
|
3
2
|
// All credit to nanoid authors: https://github.com/ai/nanoid
|
|
4
3
|
// Reason for vendoring: (still) cannot import esm, and Nanoid went ESM-only since 4.0
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.nanoidBrowser = nanoidBrowser;
|
|
7
|
-
exports.nanoidBrowserCustomAlphabet = nanoidBrowserCustomAlphabet;
|
|
8
4
|
/// <reference lib="dom" preserve="true" />
|
|
9
5
|
/* eslint-disable no-bitwise */
|
|
10
6
|
// "0-9a-zA-Z-_", same as base64url alphabet
|
|
11
7
|
const urlAlphabet = 'useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict';
|
|
12
|
-
function nanoidBrowser(length = 21) {
|
|
8
|
+
export function nanoidBrowser(length = 21) {
|
|
13
9
|
let id = '';
|
|
14
10
|
const bytes = globalThis.crypto.getRandomValues(new Uint8Array(length));
|
|
15
11
|
while (length--) {
|
|
@@ -21,7 +17,7 @@ function nanoidBrowser(length = 21) {
|
|
|
21
17
|
return id;
|
|
22
18
|
}
|
|
23
19
|
const defaultRandomFunction = (bytes) => globalThis.crypto.getRandomValues(new Uint8Array(bytes));
|
|
24
|
-
function nanoidBrowserCustomAlphabet(alphabet, length = 21) {
|
|
20
|
+
export function nanoidBrowserCustomAlphabet(alphabet, length = 21) {
|
|
25
21
|
return customRandom(alphabet, length, defaultRandomFunction);
|
|
26
22
|
}
|
|
27
23
|
function customRandom(alphabet, defaultSize, getRandom) {
|
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/* eslint-disable no-bitwise */
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports._createDeterministicRandom = _createDeterministicRandom;
|
|
5
2
|
/**
|
|
6
3
|
* Returns a "deterministic Math.random() function"
|
|
7
4
|
*
|
|
8
5
|
* Based on: https://gist.github.com/mathiasbynens/5670917
|
|
9
6
|
*/
|
|
10
|
-
function _createDeterministicRandom(seed = 0x2f6e2b1) {
|
|
7
|
+
export function _createDeterministicRandom(seed = 0x2f6e2b1) {
|
|
11
8
|
return () => {
|
|
12
9
|
// Robert Jenkins’ 32 bit integer hash function
|
|
13
10
|
seed = (seed + 0x7ed55d16 + (seed << 12)) & 0xffffffff;
|