@naturalcycles/js-lib 14.277.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 +1 -1
- package/dist/types.js +17 -27
- 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 +2 -2
- 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 -66
- 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-esm/nanoid.js
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
// Vendored from https://github.com/ai/nanoid/blob/main/index.browser.js
|
|
2
|
-
// All credit to nanoid authors: https://github.com/ai/nanoid
|
|
3
|
-
// Reason for vendoring: (still) cannot import esm, and Nanoid went ESM-only since 4.0
|
|
4
|
-
/// <reference lib="dom" preserve="true" />
|
|
5
|
-
/* eslint-disable no-bitwise */
|
|
6
|
-
// "0-9a-zA-Z-_", same as base64url alphabet
|
|
7
|
-
const urlAlphabet = 'useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict';
|
|
8
|
-
export function nanoidBrowser(length = 21) {
|
|
9
|
-
let id = '';
|
|
10
|
-
const bytes = globalThis.crypto.getRandomValues(new Uint8Array(length));
|
|
11
|
-
while (length--) {
|
|
12
|
-
// Using the bitwise AND operator to "cap" the value of
|
|
13
|
-
// the random byte from 255 to 63, in that way we can make sure
|
|
14
|
-
// that the value will be a valid index for the "chars" string.
|
|
15
|
-
id += urlAlphabet[bytes[length] & 63];
|
|
16
|
-
}
|
|
17
|
-
return id;
|
|
18
|
-
}
|
|
19
|
-
const defaultRandomFunction = (bytes) => globalThis.crypto.getRandomValues(new Uint8Array(bytes));
|
|
20
|
-
export function nanoidBrowserCustomAlphabet(alphabet, length = 21) {
|
|
21
|
-
return customRandom(alphabet, length, defaultRandomFunction);
|
|
22
|
-
}
|
|
23
|
-
function customRandom(alphabet, defaultSize, getRandom) {
|
|
24
|
-
// First, a bitmask is necessary to generate the ID. The bitmask makes bytes
|
|
25
|
-
// values closer to the alphabet size. The bitmask calculates the closest
|
|
26
|
-
// `2^31 - 1` number, which exceeds the alphabet size.
|
|
27
|
-
// For example, the bitmask for the alphabet size 30 is 31 (00011111).
|
|
28
|
-
// `Math.clz32` is not used, because it is not available in browsers.
|
|
29
|
-
const mask = (2 << Math.log2(alphabet.length - 1)) - 1;
|
|
30
|
-
// Though, the bitmask solution is not perfect since the bytes exceeding
|
|
31
|
-
// the alphabet size are refused. Therefore, to reliably generate the ID,
|
|
32
|
-
// the random bytes redundancy has to be satisfied.
|
|
33
|
-
// Note: every hardware random generator call is performance expensive,
|
|
34
|
-
// because the system call for entropy collection takes a lot of time.
|
|
35
|
-
// So, to avoid additional system calls, extra bytes are requested in advance.
|
|
36
|
-
// Next, a step determines how many random bytes to generate.
|
|
37
|
-
// The number of random bytes gets decided upon the ID size, mask,
|
|
38
|
-
// alphabet size, and magic number 1.6 (using 1.6 peaks at performance
|
|
39
|
-
// according to benchmarks).
|
|
40
|
-
// `-~f => Math.ceil(f)` if f is a float
|
|
41
|
-
// `-~i => i + 1` if i is an integer
|
|
42
|
-
const step = -~((1.6 * mask * defaultSize) / alphabet.length);
|
|
43
|
-
return (size = defaultSize) => {
|
|
44
|
-
let id = '';
|
|
45
|
-
while (true) {
|
|
46
|
-
const bytes = getRandom(step);
|
|
47
|
-
// A compact alternative for `for (var i = 0; i < step; i++)`.
|
|
48
|
-
let j = step;
|
|
49
|
-
while (j--) {
|
|
50
|
-
// Adding `|| ''` refuses a random byte that exceeds the alphabet size.
|
|
51
|
-
id += alphabet[bytes[j] & mask] || '';
|
|
52
|
-
if (id.length === size)
|
|
53
|
-
return id;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-bitwise */
|
|
2
|
-
/**
|
|
3
|
-
* Returns a "deterministic Math.random() function"
|
|
4
|
-
*
|
|
5
|
-
* Based on: https://gist.github.com/mathiasbynens/5670917
|
|
6
|
-
*/
|
|
7
|
-
export function _createDeterministicRandom(seed = 0x2f6e2b1) {
|
|
8
|
-
return () => {
|
|
9
|
-
// Robert Jenkins’ 32 bit integer hash function
|
|
10
|
-
seed = (seed + 0x7ed55d16 + (seed << 12)) & 0xffffffff;
|
|
11
|
-
seed = (seed ^ 0xc761c23c ^ (seed >>> 19)) & 0xffffffff;
|
|
12
|
-
seed = (seed + 0x165667b1 + (seed << 5)) & 0xffffffff;
|
|
13
|
-
seed = ((seed + 0xd3a2646c) ^ (seed << 9)) & 0xffffffff;
|
|
14
|
-
seed = (seed + 0xfd7046c5 + (seed << 3)) & 0xffffffff;
|
|
15
|
-
seed = (seed ^ 0xb55a4f09 ^ (seed >>> 16)) & 0xffffffff;
|
|
16
|
-
return (seed & 0xfffffff) / 0x10000000;
|
|
17
|
-
};
|
|
18
|
-
}
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
export function _randomInt(minIncl, maxIncl) {
|
|
2
|
-
return Math.floor(Math.random() * (maxIncl - minIncl + 1) + minIncl);
|
|
3
|
-
}
|
|
4
|
-
/**
|
|
5
|
-
* Returns random item from an array.
|
|
6
|
-
* Should be used on non-empty arrays! (otherwise will return undefined,
|
|
7
|
-
* which is not reflected in the output type)
|
|
8
|
-
*/
|
|
9
|
-
export function _randomArrayItem(array) {
|
|
10
|
-
return array[_randomInt(0, array.length - 1)];
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Convenience function to "throttle" some code - run it less often.
|
|
14
|
-
*
|
|
15
|
-
* @example
|
|
16
|
-
*
|
|
17
|
-
* if (_runLessOften(10)) {
|
|
18
|
-
* // this code will run only 10% of the time
|
|
19
|
-
* }
|
|
20
|
-
*/
|
|
21
|
-
export function _runLessOften(percent) {
|
|
22
|
-
return Math.random() * 100 < percent;
|
|
23
|
-
}
|
|
24
|
-
// todo: _.random to support floats
|
|
25
|
-
/**
|
|
26
|
-
* _isBetween(-10, 1, 5) // false
|
|
27
|
-
* _isBetween(1, 1, 5) // true
|
|
28
|
-
* _isBetween(3, 1, 5) // true
|
|
29
|
-
* _isBetween(5, 1, 5) // false
|
|
30
|
-
* _isBetween(7, 1, 5) // false
|
|
31
|
-
*
|
|
32
|
-
* Also works with strings:
|
|
33
|
-
* _isBetween('2020-01-03', '2020-01-01', '2020-01-05') // true
|
|
34
|
-
*/
|
|
35
|
-
export function _isBetween(x, min, max, incl = '[)') {
|
|
36
|
-
if (incl === '[)') {
|
|
37
|
-
return x >= min && x < max;
|
|
38
|
-
}
|
|
39
|
-
if (incl === '[]') {
|
|
40
|
-
return x >= min && x <= max;
|
|
41
|
-
}
|
|
42
|
-
if (incl === '(]') {
|
|
43
|
-
return x > min && x <= max;
|
|
44
|
-
}
|
|
45
|
-
return x > min && x < max;
|
|
46
|
-
}
|
|
47
|
-
export function _clamp(x, minIncl, maxIncl) {
|
|
48
|
-
// eslint-disable-next-line unicorn/prefer-math-min-max
|
|
49
|
-
return x <= minIncl ? minIncl : x >= maxIncl ? maxIncl : x;
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* This function exists, because in JS you cannot just .sort() numbers,
|
|
53
|
-
* as .sort() function first maps everything to String.
|
|
54
|
-
*
|
|
55
|
-
* @example
|
|
56
|
-
*
|
|
57
|
-
* _sortNumbers([1, 3, 2])
|
|
58
|
-
* // [1, 2, 3]
|
|
59
|
-
*/
|
|
60
|
-
export function _sortNumbers(numbers, mutate = false, dir = 'asc') {
|
|
61
|
-
const mod = dir === 'desc' ? -1 : 1;
|
|
62
|
-
return (mutate ? numbers : [...numbers]).sort((a, b) => (a - b) * mod);
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Same as .toFixed(), but conveniently casts the output to Number.
|
|
66
|
-
*
|
|
67
|
-
* @example
|
|
68
|
-
*
|
|
69
|
-
* _toFixed(1.2345, 2)
|
|
70
|
-
* // 1.23
|
|
71
|
-
*
|
|
72
|
-
* _toFixed(1.10, 2)
|
|
73
|
-
* // 1.1
|
|
74
|
-
*/
|
|
75
|
-
export function _toFixed(n, fractionDigits) {
|
|
76
|
-
return Number(n.toFixed(fractionDigits));
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Same as .toPrecision(), but conveniently casts the output to Number.
|
|
80
|
-
*
|
|
81
|
-
* @example
|
|
82
|
-
*
|
|
83
|
-
* _toPrecision(1634.56, 1)
|
|
84
|
-
* // 2000
|
|
85
|
-
*
|
|
86
|
-
* _toPrecision(1634.56, 2)
|
|
87
|
-
* // 1600
|
|
88
|
-
*/
|
|
89
|
-
export function _toPrecision(n, precision) {
|
|
90
|
-
return Number(n.toPrecision(precision));
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* @example
|
|
94
|
-
*
|
|
95
|
-
* _round(1634, 1000) // 2000
|
|
96
|
-
* _round(1634, 500) // 1500
|
|
97
|
-
* _round(1634, 100) // 1600
|
|
98
|
-
* _round(1634, 10) // 1630
|
|
99
|
-
* _round(1634, 1) // 1634
|
|
100
|
-
* _round(1634.5678, 0.1) // 1634.6
|
|
101
|
-
* _round(1634.5678, 0.01) // 1634.57
|
|
102
|
-
*/
|
|
103
|
-
export function _round(n, precisionUnit) {
|
|
104
|
-
if (precisionUnit >= 1) {
|
|
105
|
-
return Math.round(n / precisionUnit) * precisionUnit;
|
|
106
|
-
}
|
|
107
|
-
const v = Math.floor(n) + Math.round((n % 1) / precisionUnit) * precisionUnit;
|
|
108
|
-
return Number(v.toFixed(String(precisionUnit).length - 2)); // '0.
|
|
109
|
-
}
|
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
// Heavily inspired by https://github.com/epoberezkin/fast-deep-equal
|
|
2
|
-
/**
|
|
3
|
-
Returns true if a and b are deeply equal.
|
|
4
|
-
|
|
5
|
-
Equality is checked recursively, with the following rules/caveats:
|
|
6
|
-
- Primitive values are checked with ===
|
|
7
|
-
- NaN === NaN
|
|
8
|
-
- Array length should be the same, and every value should be equal
|
|
9
|
-
- Sets are checked similarly to arrays (but order doesn't matter in Sets)
|
|
10
|
-
- Objects and Maps are checked that all values match. Undefined values are treated the same as absent key (important!)
|
|
11
|
-
- Order of object/Map keys doesn't matter, unlike when comparing JSON.stringify(a) === JSON.stringify(b)
|
|
12
|
-
- Regex are compared by their source and flags
|
|
13
|
-
- Functions are compared by their `.toString`
|
|
14
|
-
- Any object that overrides `.toString()` is compared by that (e.g Function)
|
|
15
|
-
- Any object that overrides `.valueOf()` is compared by that (e.g Date)
|
|
16
|
-
|
|
17
|
-
What are the differences between various deep-equality functions?
|
|
18
|
-
There are:
|
|
19
|
-
- _deepEquals
|
|
20
|
-
- _deepJsonEquals
|
|
21
|
-
- _jsonEquals
|
|
22
|
-
|
|
23
|
-
_deepEquals uses "common sense" equality.
|
|
24
|
-
It tries to work "as you would expect it to".
|
|
25
|
-
With the important caveat that undefined values are treated the same as absent key.
|
|
26
|
-
So, _deepEquals should be the first choice.
|
|
27
|
-
It's also the most performant of 3.
|
|
28
|
-
|
|
29
|
-
_deepJsonEquals uses different logic, that's often not what you expect.
|
|
30
|
-
It should be used to compare objects of how they would look after "passing via JSON.stringify",
|
|
31
|
-
for example when you return it over the API to the Frontend,
|
|
32
|
-
or when you pass it to be saved to the Database.
|
|
33
|
-
If some object has custom .toJSON() implementation - it'll invoke that (similar to JSON.stringify).
|
|
34
|
-
For these cases - it can be better than _deepEquals.
|
|
35
|
-
And it's better than _jsonEquals, because it doesn't fail/depend on object key order.
|
|
36
|
-
|
|
37
|
-
_jsonEquals is simply JSON.stringify(a) === JSON.stringify(b).
|
|
38
|
-
It's the simplest implementation, but also the slowest of 3.
|
|
39
|
-
|
|
40
|
-
TLDR: _deepEquals should be useful in most of the cases, start there.
|
|
41
|
-
*/
|
|
42
|
-
export function _deepEquals(a, b) {
|
|
43
|
-
if (a === b)
|
|
44
|
-
return true;
|
|
45
|
-
if (Number.isNaN(a)) {
|
|
46
|
-
return Number.isNaN(b);
|
|
47
|
-
}
|
|
48
|
-
if (a && b && typeof a === 'object' && typeof b === 'object') {
|
|
49
|
-
if (a.constructor !== b.constructor)
|
|
50
|
-
return false;
|
|
51
|
-
if (Array.isArray(a)) {
|
|
52
|
-
const length = a.length;
|
|
53
|
-
if (!Array.isArray(b) || length !== b.length)
|
|
54
|
-
return false;
|
|
55
|
-
for (let i = length; i-- !== 0;) {
|
|
56
|
-
if (!_deepEquals(a[i], b[i]))
|
|
57
|
-
return false;
|
|
58
|
-
}
|
|
59
|
-
return true;
|
|
60
|
-
}
|
|
61
|
-
if (a instanceof Map && b instanceof Map) {
|
|
62
|
-
for (const key of new Set([...a.keys(), ...b.keys()])) {
|
|
63
|
-
if (!_deepEquals(a.get(key), b.get(key)))
|
|
64
|
-
return false;
|
|
65
|
-
}
|
|
66
|
-
return true;
|
|
67
|
-
}
|
|
68
|
-
if (a instanceof Set && b instanceof Set) {
|
|
69
|
-
if (a.size !== b.size)
|
|
70
|
-
return false;
|
|
71
|
-
for (const key of a) {
|
|
72
|
-
if (!b.has(key))
|
|
73
|
-
return false;
|
|
74
|
-
}
|
|
75
|
-
return true;
|
|
76
|
-
}
|
|
77
|
-
if (a.constructor === RegExp) {
|
|
78
|
-
return a.source === b.source && a.flags === b.flags;
|
|
79
|
-
}
|
|
80
|
-
if (a.valueOf !== Object.prototype.valueOf)
|
|
81
|
-
return a.valueOf() === b.valueOf();
|
|
82
|
-
if (a.toString !== Object.prototype.toString)
|
|
83
|
-
return a.toString() === b.toString();
|
|
84
|
-
for (const key of new Set([...Object.keys(a), ...Object.keys(b)])) {
|
|
85
|
-
if (!_deepEquals(a[key], b[key]))
|
|
86
|
-
return false;
|
|
87
|
-
}
|
|
88
|
-
return true;
|
|
89
|
-
}
|
|
90
|
-
return a === b;
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
Returns true if a and b are deeply equal.
|
|
94
|
-
|
|
95
|
-
Equality is checked in the same way as if both arguments are processed via
|
|
96
|
-
JSON.stringify and JSON.parse:
|
|
97
|
-
- undefined values are removed, undefined values in an array are turned into `null`, etc.
|
|
98
|
-
- Any Regex, Map, Set, Function stringifies to {}.
|
|
99
|
-
- Date stringifies to its IsoDateTimeString representation.
|
|
100
|
-
- Any object that implements toJSON is compared by the output of its toJSON().
|
|
101
|
-
- NaN stringifies to null
|
|
102
|
-
- Order of object keys does not matter, unlike when comparing JSON.stringify(a) === JSON.stringify(b)
|
|
103
|
-
|
|
104
|
-
See _deepEquals docs for more details and comparison.
|
|
105
|
-
*/
|
|
106
|
-
export function _deepJsonEquals(a, b) {
|
|
107
|
-
if (a === b)
|
|
108
|
-
return true;
|
|
109
|
-
if (Number.isNaN(a)) {
|
|
110
|
-
;
|
|
111
|
-
a = null;
|
|
112
|
-
}
|
|
113
|
-
else if (typeof a === 'function') {
|
|
114
|
-
;
|
|
115
|
-
a = undefined;
|
|
116
|
-
}
|
|
117
|
-
else if (a && typeof a === 'object') {
|
|
118
|
-
if (a instanceof Date) {
|
|
119
|
-
;
|
|
120
|
-
a = a.valueOf();
|
|
121
|
-
}
|
|
122
|
-
else if ('toJSON' in a) {
|
|
123
|
-
a = a.toJSON();
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
if (Number.isNaN(b)) {
|
|
127
|
-
;
|
|
128
|
-
b = null;
|
|
129
|
-
}
|
|
130
|
-
else if (typeof b === 'function') {
|
|
131
|
-
;
|
|
132
|
-
b = undefined;
|
|
133
|
-
}
|
|
134
|
-
else if (b && typeof b === 'object') {
|
|
135
|
-
if (b instanceof Date) {
|
|
136
|
-
;
|
|
137
|
-
b = b.valueOf();
|
|
138
|
-
}
|
|
139
|
-
else if ('toJSON' in b) {
|
|
140
|
-
b = b.toJSON();
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
if (a && b && typeof a === 'object' && typeof b === 'object') {
|
|
144
|
-
if (Array.isArray(a)) {
|
|
145
|
-
const length = a.length;
|
|
146
|
-
if (!Array.isArray(b) || length !== b.length)
|
|
147
|
-
return false;
|
|
148
|
-
for (let i = length; i-- !== 0;) {
|
|
149
|
-
if (!_deepJsonEquals(a[i], b[i]))
|
|
150
|
-
return false;
|
|
151
|
-
}
|
|
152
|
-
return true;
|
|
153
|
-
}
|
|
154
|
-
for (const key of new Set([...Object.keys(a), ...Object.keys(b)])) {
|
|
155
|
-
if (!_deepJsonEquals(a[key], b[key]))
|
|
156
|
-
return false;
|
|
157
|
-
}
|
|
158
|
-
return true;
|
|
159
|
-
}
|
|
160
|
-
return a === b;
|
|
161
|
-
}
|
|
162
|
-
/**
|
|
163
|
-
* Shortcut for JSON.stringify(a) === JSON.stringify(b)
|
|
164
|
-
*
|
|
165
|
-
* Simplest "deep equals" implementation, but also the slowest,
|
|
166
|
-
* and not robust, in the sense that it depends on the order of object keys.
|
|
167
|
-
*/
|
|
168
|
-
export function _jsonEquals(a, b) {
|
|
169
|
-
return JSON.stringify(a) === JSON.stringify(b);
|
|
170
|
-
}
|
package/dist-esm/object/map2.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Like Map, but serializes to JSON as an object.
|
|
3
|
-
*
|
|
4
|
-
* Fixes the "issue" of stock Map being json-serialized as `{}`.
|
|
5
|
-
*
|
|
6
|
-
* @experimental
|
|
7
|
-
*/
|
|
8
|
-
export class Map2 extends Map {
|
|
9
|
-
/**
|
|
10
|
-
* Convenience way to create Map2 from object.
|
|
11
|
-
*/
|
|
12
|
-
static of(obj) {
|
|
13
|
-
return new Map2(Object.entries(obj));
|
|
14
|
-
}
|
|
15
|
-
toObject() {
|
|
16
|
-
return Object.fromEntries(this);
|
|
17
|
-
}
|
|
18
|
-
toJSON() {
|
|
19
|
-
return Object.fromEntries(this);
|
|
20
|
-
}
|
|
21
|
-
}
|