@naturalcycles/js-lib 14.277.0 → 15.0.1
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 +5 -8
- 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 +18 -30
- 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 +2 -2
- 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 +3 -3
- 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
|
@@ -1,15 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports._randomInt = _randomInt;
|
|
4
|
-
exports._randomArrayItem = _randomArrayItem;
|
|
5
|
-
exports._runLessOften = _runLessOften;
|
|
6
|
-
exports._isBetween = _isBetween;
|
|
7
|
-
exports._clamp = _clamp;
|
|
8
|
-
exports._sortNumbers = _sortNumbers;
|
|
9
|
-
exports._toFixed = _toFixed;
|
|
10
|
-
exports._toPrecision = _toPrecision;
|
|
11
|
-
exports._round = _round;
|
|
12
|
-
function _randomInt(minIncl, maxIncl) {
|
|
1
|
+
export function _randomInt(minIncl, maxIncl) {
|
|
13
2
|
return Math.floor(Math.random() * (maxIncl - minIncl + 1) + minIncl);
|
|
14
3
|
}
|
|
15
4
|
/**
|
|
@@ -17,7 +6,7 @@ function _randomInt(minIncl, maxIncl) {
|
|
|
17
6
|
* Should be used on non-empty arrays! (otherwise will return undefined,
|
|
18
7
|
* which is not reflected in the output type)
|
|
19
8
|
*/
|
|
20
|
-
function _randomArrayItem(array) {
|
|
9
|
+
export function _randomArrayItem(array) {
|
|
21
10
|
return array[_randomInt(0, array.length - 1)];
|
|
22
11
|
}
|
|
23
12
|
/**
|
|
@@ -29,7 +18,7 @@ function _randomArrayItem(array) {
|
|
|
29
18
|
* // this code will run only 10% of the time
|
|
30
19
|
* }
|
|
31
20
|
*/
|
|
32
|
-
function _runLessOften(percent) {
|
|
21
|
+
export function _runLessOften(percent) {
|
|
33
22
|
return Math.random() * 100 < percent;
|
|
34
23
|
}
|
|
35
24
|
// todo: _.random to support floats
|
|
@@ -43,7 +32,7 @@ function _runLessOften(percent) {
|
|
|
43
32
|
* Also works with strings:
|
|
44
33
|
* _isBetween('2020-01-03', '2020-01-01', '2020-01-05') // true
|
|
45
34
|
*/
|
|
46
|
-
function _isBetween(x, min, max, incl = '[)') {
|
|
35
|
+
export function _isBetween(x, min, max, incl = '[)') {
|
|
47
36
|
if (incl === '[)') {
|
|
48
37
|
return x >= min && x < max;
|
|
49
38
|
}
|
|
@@ -55,7 +44,7 @@ function _isBetween(x, min, max, incl = '[)') {
|
|
|
55
44
|
}
|
|
56
45
|
return x > min && x < max;
|
|
57
46
|
}
|
|
58
|
-
function _clamp(x, minIncl, maxIncl) {
|
|
47
|
+
export function _clamp(x, minIncl, maxIncl) {
|
|
59
48
|
// eslint-disable-next-line unicorn/prefer-math-min-max
|
|
60
49
|
return x <= minIncl ? minIncl : x >= maxIncl ? maxIncl : x;
|
|
61
50
|
}
|
|
@@ -68,7 +57,7 @@ function _clamp(x, minIncl, maxIncl) {
|
|
|
68
57
|
* _sortNumbers([1, 3, 2])
|
|
69
58
|
* // [1, 2, 3]
|
|
70
59
|
*/
|
|
71
|
-
function _sortNumbers(numbers, mutate = false, dir = 'asc') {
|
|
60
|
+
export function _sortNumbers(numbers, mutate = false, dir = 'asc') {
|
|
72
61
|
const mod = dir === 'desc' ? -1 : 1;
|
|
73
62
|
return (mutate ? numbers : [...numbers]).sort((a, b) => (a - b) * mod);
|
|
74
63
|
}
|
|
@@ -83,7 +72,7 @@ function _sortNumbers(numbers, mutate = false, dir = 'asc') {
|
|
|
83
72
|
* _toFixed(1.10, 2)
|
|
84
73
|
* // 1.1
|
|
85
74
|
*/
|
|
86
|
-
function _toFixed(n, fractionDigits) {
|
|
75
|
+
export function _toFixed(n, fractionDigits) {
|
|
87
76
|
return Number(n.toFixed(fractionDigits));
|
|
88
77
|
}
|
|
89
78
|
/**
|
|
@@ -97,7 +86,7 @@ function _toFixed(n, fractionDigits) {
|
|
|
97
86
|
* _toPrecision(1634.56, 2)
|
|
98
87
|
* // 1600
|
|
99
88
|
*/
|
|
100
|
-
function _toPrecision(n, precision) {
|
|
89
|
+
export function _toPrecision(n, precision) {
|
|
101
90
|
return Number(n.toPrecision(precision));
|
|
102
91
|
}
|
|
103
92
|
/**
|
|
@@ -111,7 +100,7 @@ function _toPrecision(n, precision) {
|
|
|
111
100
|
* _round(1634.5678, 0.1) // 1634.6
|
|
112
101
|
* _round(1634.5678, 0.01) // 1634.57
|
|
113
102
|
*/
|
|
114
|
-
function _round(n, precisionUnit) {
|
|
103
|
+
export function _round(n, precisionUnit) {
|
|
115
104
|
if (precisionUnit >= 1) {
|
|
116
105
|
return Math.round(n / precisionUnit) * precisionUnit;
|
|
117
106
|
}
|
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
// Heavily inspired by https://github.com/epoberezkin/fast-deep-equal
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports._deepEquals = _deepEquals;
|
|
5
|
-
exports._deepJsonEquals = _deepJsonEquals;
|
|
6
|
-
exports._jsonEquals = _jsonEquals;
|
|
7
2
|
/**
|
|
8
3
|
Returns true if a and b are deeply equal.
|
|
9
4
|
|
|
@@ -44,7 +39,7 @@ exports._jsonEquals = _jsonEquals;
|
|
|
44
39
|
|
|
45
40
|
TLDR: _deepEquals should be useful in most of the cases, start there.
|
|
46
41
|
*/
|
|
47
|
-
function _deepEquals(a, b) {
|
|
42
|
+
export function _deepEquals(a, b) {
|
|
48
43
|
if (a === b)
|
|
49
44
|
return true;
|
|
50
45
|
if (Number.isNaN(a)) {
|
|
@@ -108,7 +103,7 @@ function _deepEquals(a, b) {
|
|
|
108
103
|
|
|
109
104
|
See _deepEquals docs for more details and comparison.
|
|
110
105
|
*/
|
|
111
|
-
function _deepJsonEquals(a, b) {
|
|
106
|
+
export function _deepJsonEquals(a, b) {
|
|
112
107
|
if (a === b)
|
|
113
108
|
return true;
|
|
114
109
|
if (Number.isNaN(a)) {
|
|
@@ -170,6 +165,6 @@ function _deepJsonEquals(a, b) {
|
|
|
170
165
|
* Simplest "deep equals" implementation, but also the slowest,
|
|
171
166
|
* and not robust, in the sense that it depends on the order of object keys.
|
|
172
167
|
*/
|
|
173
|
-
function _jsonEquals(a, b) {
|
|
168
|
+
export function _jsonEquals(a, b) {
|
|
174
169
|
return JSON.stringify(a) === JSON.stringify(b);
|
|
175
170
|
}
|
package/dist/object/map2.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Map2 = void 0;
|
|
4
1
|
/**
|
|
5
2
|
* Like Map, but serializes to JSON as an object.
|
|
6
3
|
*
|
|
@@ -8,7 +5,7 @@ exports.Map2 = void 0;
|
|
|
8
5
|
*
|
|
9
6
|
* @experimental
|
|
10
7
|
*/
|
|
11
|
-
class Map2 extends Map {
|
|
8
|
+
export class Map2 extends Map {
|
|
12
9
|
/**
|
|
13
10
|
* Convenience way to create Map2 from object.
|
|
14
11
|
*/
|
|
@@ -22,4 +19,3 @@ class Map2 extends Map {
|
|
|
22
19
|
return Object.fromEntries(this);
|
|
23
20
|
}
|
|
24
21
|
}
|
|
25
|
-
exports.Map2 = Map2;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { AnyObject, KeyValueTuple, ObjectMapper, ObjectPredicate, Reviver, ValueOf } from '../types';
|
|
2
|
-
import { SKIP } from '../types';
|
|
1
|
+
import type { AnyObject, KeyValueTuple, ObjectMapper, ObjectPredicate, Reviver, ValueOf } from '../types.js';
|
|
2
|
+
import { SKIP } from '../types.js';
|
|
3
3
|
/**
|
|
4
4
|
* Returns clone of `obj` with only `props` preserved.
|
|
5
5
|
* Opposite of Omit.
|
|
@@ -1,40 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports._pick = _pick;
|
|
4
|
-
exports._pickWithUndefined = _pickWithUndefined;
|
|
5
|
-
exports._omit = _omit;
|
|
6
|
-
exports._omitWithUndefined = _omitWithUndefined;
|
|
7
|
-
exports._mask = _mask;
|
|
8
|
-
exports._filterFalsyValues = _filterFalsyValues;
|
|
9
|
-
exports._filterNullishValues = _filterNullishValues;
|
|
10
|
-
exports._filterUndefinedValues = _filterUndefinedValues;
|
|
11
|
-
exports._filterEmptyArrays = _filterEmptyArrays;
|
|
12
|
-
exports._filterObject = _filterObject;
|
|
13
|
-
exports._mapValues = _mapValues;
|
|
14
|
-
exports._mapKeys = _mapKeys;
|
|
15
|
-
exports._mapObject = _mapObject;
|
|
16
|
-
exports._findKeyByValue = _findKeyByValue;
|
|
17
|
-
exports._objectNullValuesToUndefined = _objectNullValuesToUndefined;
|
|
18
|
-
exports._deepCopy = _deepCopy;
|
|
19
|
-
exports._undefinedIfEmpty = _undefinedIfEmpty;
|
|
20
|
-
exports._filterEmptyValues = _filterEmptyValues;
|
|
21
|
-
exports._merge = _merge;
|
|
22
|
-
exports._deepTrim = _deepTrim;
|
|
23
|
-
exports._unset = _unset;
|
|
24
|
-
exports._invert = _invert;
|
|
25
|
-
exports._invertMap = _invertMap;
|
|
26
|
-
exports._get = _get;
|
|
27
|
-
exports._set = _set;
|
|
28
|
-
exports._has = _has;
|
|
29
|
-
exports._deepFreeze = _deepFreeze;
|
|
30
|
-
exports._objectAssignExact = _objectAssignExact;
|
|
31
|
-
const is_util_1 = require("../is.util");
|
|
32
|
-
const types_1 = require("../types");
|
|
1
|
+
import { _isEmpty, _isObject } from '../is.util.js';
|
|
2
|
+
import { _objectEntries, SKIP } from '../types.js';
|
|
33
3
|
/**
|
|
34
4
|
* Returns clone of `obj` with only `props` preserved.
|
|
35
5
|
* Opposite of Omit.
|
|
36
6
|
*/
|
|
37
|
-
function _pick(obj, props, mutate = false) {
|
|
7
|
+
export function _pick(obj, props, mutate = false) {
|
|
38
8
|
if (mutate) {
|
|
39
9
|
// Start as original object (mutable), DELETE properties that are not whitelisted
|
|
40
10
|
for (const k of Object.keys(obj)) {
|
|
@@ -55,7 +25,7 @@ function _pick(obj, props, mutate = false) {
|
|
|
55
25
|
* Sets all properties of an object except passed ones to `undefined`.
|
|
56
26
|
* This is a more performant alternative to `_pick` that does picking/deleting.
|
|
57
27
|
*/
|
|
58
|
-
function _pickWithUndefined(obj, props, mutate = false) {
|
|
28
|
+
export function _pickWithUndefined(obj, props, mutate = false) {
|
|
59
29
|
const r = mutate ? obj : { ...obj };
|
|
60
30
|
for (const k of Object.keys(r)) {
|
|
61
31
|
if (!props.includes(k)) {
|
|
@@ -68,7 +38,7 @@ function _pickWithUndefined(obj, props, mutate = false) {
|
|
|
68
38
|
* Returns clone of `obj` with `props` omitted.
|
|
69
39
|
* Opposite of Pick.
|
|
70
40
|
*/
|
|
71
|
-
function _omit(obj, props, mutate = false) {
|
|
41
|
+
export function _omit(obj, props, mutate = false) {
|
|
72
42
|
if (mutate) {
|
|
73
43
|
for (const k of props) {
|
|
74
44
|
delete obj[k];
|
|
@@ -86,7 +56,7 @@ function _omit(obj, props, mutate = false) {
|
|
|
86
56
|
* Sets all passed properties of an object to `undefined`.
|
|
87
57
|
* This is a more performant alternative to `_omit` that does picking/deleting.
|
|
88
58
|
*/
|
|
89
|
-
function _omitWithUndefined(obj, props, mutate = false) {
|
|
59
|
+
export function _omitWithUndefined(obj, props, mutate = false) {
|
|
90
60
|
const r = mutate ? obj : { ...obj };
|
|
91
61
|
for (const k of props) {
|
|
92
62
|
r[k] = undefined;
|
|
@@ -101,7 +71,7 @@ function _omitWithUndefined(obj, props, mutate = false) {
|
|
|
101
71
|
* 'account.updated',
|
|
102
72
|
* ])
|
|
103
73
|
*/
|
|
104
|
-
function _mask(obj, props, mutate = false) {
|
|
74
|
+
export function _mask(obj, props, mutate = false) {
|
|
105
75
|
const r = mutate ? obj : _deepCopy(obj);
|
|
106
76
|
for (const k of props) {
|
|
107
77
|
_unset(r, k);
|
|
@@ -111,32 +81,32 @@ function _mask(obj, props, mutate = false) {
|
|
|
111
81
|
/**
|
|
112
82
|
* Removes "falsy" values from the object.
|
|
113
83
|
*/
|
|
114
|
-
function _filterFalsyValues(obj, mutate = false) {
|
|
84
|
+
export function _filterFalsyValues(obj, mutate = false) {
|
|
115
85
|
return _filterObject(obj, (_k, v) => !!v, mutate);
|
|
116
86
|
}
|
|
117
87
|
/**
|
|
118
88
|
* Removes values from the object that are `null` or `undefined`.
|
|
119
89
|
*/
|
|
120
|
-
function _filterNullishValues(obj, mutate = false) {
|
|
90
|
+
export function _filterNullishValues(obj, mutate = false) {
|
|
121
91
|
return _filterObject(obj, (_k, v) => v !== undefined && v !== null, mutate);
|
|
122
92
|
}
|
|
123
93
|
/**
|
|
124
94
|
* Removes values from the object that are `undefined`.
|
|
125
95
|
* Only `undefined` values are removed. `null` values are kept!
|
|
126
96
|
*/
|
|
127
|
-
function _filterUndefinedValues(obj, mutate = false) {
|
|
97
|
+
export function _filterUndefinedValues(obj, mutate = false) {
|
|
128
98
|
return _filterObject(obj, (_k, v) => v !== undefined, mutate);
|
|
129
99
|
}
|
|
130
|
-
function _filterEmptyArrays(obj, mutate = false) {
|
|
100
|
+
export function _filterEmptyArrays(obj, mutate = false) {
|
|
131
101
|
return _filterObject(obj, (_k, v) => !Array.isArray(v) || v.length > 0, mutate);
|
|
132
102
|
}
|
|
133
103
|
/**
|
|
134
104
|
* Returns clone of `obj` without properties that does not pass `predicate`.
|
|
135
105
|
* Allows filtering by both key and value.
|
|
136
106
|
*/
|
|
137
|
-
function _filterObject(obj, predicate, mutate = false) {
|
|
107
|
+
export function _filterObject(obj, predicate, mutate = false) {
|
|
138
108
|
if (mutate) {
|
|
139
|
-
for (const [k, v] of
|
|
109
|
+
for (const [k, v] of _objectEntries(obj)) {
|
|
140
110
|
if (!predicate(k, v, obj)) {
|
|
141
111
|
delete obj[k];
|
|
142
112
|
}
|
|
@@ -144,7 +114,7 @@ function _filterObject(obj, predicate, mutate = false) {
|
|
|
144
114
|
return obj;
|
|
145
115
|
}
|
|
146
116
|
const r = {};
|
|
147
|
-
for (const [k, v] of
|
|
117
|
+
for (const [k, v] of _objectEntries(obj)) {
|
|
148
118
|
if (predicate(k, v, obj)) {
|
|
149
119
|
r[k] = v;
|
|
150
120
|
}
|
|
@@ -162,7 +132,7 @@ function _filterObject(obj, predicate, mutate = false) {
|
|
|
162
132
|
*
|
|
163
133
|
* To skip some key-value pairs - use _mapObject instead.
|
|
164
134
|
*/
|
|
165
|
-
function _mapValues(obj, mapper, mutate = false) {
|
|
135
|
+
export function _mapValues(obj, mapper, mutate = false) {
|
|
166
136
|
const map = mutate ? obj : {};
|
|
167
137
|
for (const [k, v] of Object.entries(obj)) {
|
|
168
138
|
map[k] = mapper(k, v, obj);
|
|
@@ -177,7 +147,7 @@ function _mapValues(obj, mapper, mutate = false) {
|
|
|
177
147
|
*
|
|
178
148
|
* To skip some key-value pairs - use _mapObject instead.
|
|
179
149
|
*/
|
|
180
|
-
function _mapKeys(obj, mapper) {
|
|
150
|
+
export function _mapKeys(obj, mapper) {
|
|
181
151
|
const map = {};
|
|
182
152
|
for (const [k, v] of Object.entries(obj)) {
|
|
183
153
|
map[mapper(k, v, obj)] = v;
|
|
@@ -200,40 +170,40 @@ function _mapKeys(obj, mapper) {
|
|
|
200
170
|
*
|
|
201
171
|
* Non-string keys are passed via String(...)
|
|
202
172
|
*/
|
|
203
|
-
function _mapObject(obj, mapper) {
|
|
173
|
+
export function _mapObject(obj, mapper) {
|
|
204
174
|
const map = {};
|
|
205
175
|
for (const [k, v] of Object.entries(obj)) {
|
|
206
176
|
const r = mapper(k, v, obj);
|
|
207
|
-
if (r ===
|
|
177
|
+
if (r === SKIP)
|
|
208
178
|
continue;
|
|
209
179
|
map[r[0]] = r[1];
|
|
210
180
|
}
|
|
211
181
|
return map;
|
|
212
182
|
}
|
|
213
|
-
function _findKeyByValue(obj, v) {
|
|
183
|
+
export function _findKeyByValue(obj, v) {
|
|
214
184
|
return Object.entries(obj).find(([_, value]) => value === v)?.[0];
|
|
215
185
|
}
|
|
216
|
-
function _objectNullValuesToUndefined(obj, mutate = false) {
|
|
186
|
+
export function _objectNullValuesToUndefined(obj, mutate = false) {
|
|
217
187
|
return _mapValues(obj, (_k, v) => (v === null ? undefined : v), mutate);
|
|
218
188
|
}
|
|
219
189
|
/**
|
|
220
190
|
* Deep copy object (by json parse/stringify, since it has unbeatable performance+simplicity combo).
|
|
221
191
|
*/
|
|
222
|
-
function _deepCopy(o, reviver) {
|
|
192
|
+
export function _deepCopy(o, reviver) {
|
|
223
193
|
return JSON.parse(JSON.stringify(o), reviver);
|
|
224
194
|
}
|
|
225
195
|
/**
|
|
226
196
|
* Returns `undefined` if it's empty (according to `_isEmpty()` specification),
|
|
227
197
|
* otherwise returns the original object.
|
|
228
198
|
*/
|
|
229
|
-
function _undefinedIfEmpty(obj) {
|
|
230
|
-
return
|
|
199
|
+
export function _undefinedIfEmpty(obj) {
|
|
200
|
+
return _isEmpty(obj) ? undefined : obj;
|
|
231
201
|
}
|
|
232
202
|
/**
|
|
233
203
|
* Filters the object by removing all key-value pairs where Value is Empty (according to _isEmpty() specification).
|
|
234
204
|
*/
|
|
235
|
-
function _filterEmptyValues(obj, mutate = false) {
|
|
236
|
-
return _filterObject(obj, (_k, v) => !
|
|
205
|
+
export function _filterEmptyValues(obj, mutate = false) {
|
|
206
|
+
return _filterObject(obj, (_k, v) => !_isEmpty(v), mutate);
|
|
237
207
|
}
|
|
238
208
|
/**
|
|
239
209
|
* Recursively merges own and inherited enumerable properties of source
|
|
@@ -266,12 +236,12 @@ function _filterEmptyValues(obj, mutate = false) {
|
|
|
266
236
|
*
|
|
267
237
|
* Based on: https://gist.github.com/Salakar/1d7137de9cb8b704e48a
|
|
268
238
|
*/
|
|
269
|
-
function _merge(target, ...sources) {
|
|
239
|
+
export function _merge(target, ...sources) {
|
|
270
240
|
sources.forEach(source => {
|
|
271
|
-
if (!
|
|
241
|
+
if (!_isObject(source))
|
|
272
242
|
return;
|
|
273
243
|
Object.keys(source).forEach(key => {
|
|
274
|
-
if (
|
|
244
|
+
if (_isObject(source[key])) {
|
|
275
245
|
;
|
|
276
246
|
target[key] ||= {};
|
|
277
247
|
_merge(target[key], source[key]);
|
|
@@ -289,7 +259,7 @@ function _merge(target, ...sources) {
|
|
|
289
259
|
* Doesn't touch object KEYS.
|
|
290
260
|
* Mutates.
|
|
291
261
|
*/
|
|
292
|
-
function _deepTrim(o) {
|
|
262
|
+
export function _deepTrim(o) {
|
|
293
263
|
if (!o)
|
|
294
264
|
return o;
|
|
295
265
|
if (typeof o === 'string') {
|
|
@@ -304,8 +274,8 @@ function _deepTrim(o) {
|
|
|
304
274
|
}
|
|
305
275
|
// from: https://github.com/jonschlinkert/unset-value
|
|
306
276
|
// mutates obj
|
|
307
|
-
function _unset(obj, prop) {
|
|
308
|
-
if (!
|
|
277
|
+
export function _unset(obj, prop) {
|
|
278
|
+
if (!_isObject(obj)) {
|
|
309
279
|
return;
|
|
310
280
|
}
|
|
311
281
|
if (obj.hasOwnProperty(prop)) {
|
|
@@ -317,22 +287,22 @@ function _unset(obj, prop) {
|
|
|
317
287
|
while (segs.length && segs[segs.length - 1].endsWith('\\')) {
|
|
318
288
|
last = segs.pop().slice(0, -1) + '.' + last;
|
|
319
289
|
}
|
|
320
|
-
while (segs.length &&
|
|
290
|
+
while (segs.length && _isObject(obj)) {
|
|
321
291
|
const k = segs.shift();
|
|
322
292
|
obj = obj[k];
|
|
323
293
|
}
|
|
324
|
-
if (!
|
|
294
|
+
if (!_isObject(obj))
|
|
325
295
|
return;
|
|
326
296
|
delete obj[last];
|
|
327
297
|
}
|
|
328
|
-
function _invert(o) {
|
|
298
|
+
export function _invert(o) {
|
|
329
299
|
const inv = {};
|
|
330
300
|
Object.keys(o).forEach(k => {
|
|
331
301
|
inv[o[k]] = k;
|
|
332
302
|
});
|
|
333
303
|
return inv;
|
|
334
304
|
}
|
|
335
|
-
function _invertMap(m) {
|
|
305
|
+
export function _invertMap(m) {
|
|
336
306
|
const inv = new Map();
|
|
337
307
|
m.forEach((v, k) => inv.set(v, k));
|
|
338
308
|
return inv;
|
|
@@ -347,7 +317,7 @@ function _invertMap(m) {
|
|
|
347
317
|
* _get(obj, 'c[cc]') // 'cc'
|
|
348
318
|
* _get(obj, 'unknown.path') // undefined
|
|
349
319
|
*/
|
|
350
|
-
function _get(obj = {}, path = '') {
|
|
320
|
+
export function _get(obj = {}, path = '') {
|
|
351
321
|
return (path
|
|
352
322
|
.replaceAll(/\[([^\]]+)]/g, '.$1')
|
|
353
323
|
.split('.')
|
|
@@ -365,7 +335,7 @@ function _get(obj = {}, path = '') {
|
|
|
365
335
|
*
|
|
366
336
|
* Based on: https://stackoverflow.com/a/54733755/4919972
|
|
367
337
|
*/
|
|
368
|
-
function _set(obj, path, value) {
|
|
338
|
+
export function _set(obj, path, value) {
|
|
369
339
|
// biome-ignore lint/style/useConsistentBuiltinInstantiation: ok
|
|
370
340
|
if (!obj || Object(obj) !== obj || !path)
|
|
371
341
|
return obj; // When obj is not an object
|
|
@@ -416,7 +386,7 @@ function _set(obj, path, value) {
|
|
|
416
386
|
* _.has(other, 'a');
|
|
417
387
|
* // => false
|
|
418
388
|
*/
|
|
419
|
-
function _has(obj, path) {
|
|
389
|
+
export function _has(obj, path) {
|
|
420
390
|
const v = _get(obj, path);
|
|
421
391
|
return v !== undefined && v !== null;
|
|
422
392
|
}
|
|
@@ -425,7 +395,7 @@ function _has(obj, path) {
|
|
|
425
395
|
*
|
|
426
396
|
* Based on: https://github.com/substack/deep-freeze/blob/master/index.js
|
|
427
397
|
*/
|
|
428
|
-
function _deepFreeze(o) {
|
|
398
|
+
export function _deepFreeze(o) {
|
|
429
399
|
Object.freeze(o);
|
|
430
400
|
Object.getOwnPropertyNames(o).forEach(prop => {
|
|
431
401
|
if (o.hasOwnProperty(prop) &&
|
|
@@ -453,7 +423,7 @@ function _deepFreeze(o) {
|
|
|
453
423
|
*
|
|
454
424
|
* To make mutation extra clear - function returns void (unlike Object.assign).
|
|
455
425
|
*/
|
|
456
|
-
function _objectAssignExact(target, source) {
|
|
426
|
+
export function _objectAssignExact(target, source) {
|
|
457
427
|
Object.assign(target, source);
|
|
458
428
|
for (const k of Object.keys(target)) {
|
|
459
429
|
if (!(k in source)) {
|
package/dist/object/set2.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Set2 = void 0;
|
|
4
1
|
/**
|
|
5
2
|
* Like Set, but serializes to JSON as an array.
|
|
6
3
|
*
|
|
@@ -8,7 +5,7 @@ exports.Set2 = void 0;
|
|
|
8
5
|
*
|
|
9
6
|
* @experimental
|
|
10
7
|
*/
|
|
11
|
-
class Set2 extends Set {
|
|
8
|
+
export class Set2 extends Set {
|
|
12
9
|
toArray() {
|
|
13
10
|
return [...this];
|
|
14
11
|
}
|
|
@@ -16,4 +13,3 @@ class Set2 extends Set {
|
|
|
16
13
|
return [...this];
|
|
17
14
|
}
|
|
18
15
|
}
|
|
19
|
-
exports.Set2 = Set2;
|
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports._sortObject = _sortObject;
|
|
4
1
|
/**
|
|
5
2
|
* Returns new object with keys sorder in the given order.
|
|
6
3
|
* All keys that are not listed in `keyOrder` go last.
|
|
7
4
|
* Does not mutate original object.
|
|
8
5
|
*/
|
|
9
|
-
function _sortObject(obj, keyOrder) {
|
|
6
|
+
export function _sortObject(obj, keyOrder) {
|
|
10
7
|
const r = {};
|
|
11
8
|
// First, go over ordered keys
|
|
12
9
|
for (const k of keyOrder) {
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports._sortObjectDeep = _sortObjectDeep;
|
|
4
1
|
/**
|
|
5
2
|
* based on: https://github.com/IndigoUnited/js-deep-sort-object
|
|
6
3
|
*/
|
|
7
|
-
function _sortObjectDeep(o) {
|
|
4
|
+
export function _sortObjectDeep(o) {
|
|
8
5
|
// array
|
|
9
6
|
if (Array.isArray(o)) {
|
|
10
7
|
return o.map(_sortObjectDeep);
|
package/dist/polyfill.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.polyfillDispose = polyfillDispose;
|
|
4
|
-
function polyfillDispose() {
|
|
1
|
+
export function polyfillDispose() {
|
|
5
2
|
// @ts-expect-error polyfill
|
|
6
3
|
Symbol.dispose ??= Symbol('Symbol.dispose');
|
|
7
4
|
// @ts-expect-error polyfill
|
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Abortable = void 0;
|
|
4
|
-
exports.abortable = abortable;
|
|
5
1
|
/**
|
|
6
2
|
* Similar to AbortController and AbortSignal.
|
|
7
3
|
* Similar to pDefer and Promise.
|
|
@@ -13,7 +9,7 @@ exports.abortable = abortable;
|
|
|
13
9
|
*
|
|
14
10
|
* @experimental
|
|
15
11
|
*/
|
|
16
|
-
class Abortable {
|
|
12
|
+
export class Abortable {
|
|
17
13
|
onAbort;
|
|
18
14
|
constructor(onAbort) {
|
|
19
15
|
this.onAbort = onAbort;
|
|
@@ -30,8 +26,7 @@ class Abortable {
|
|
|
30
26
|
this.onAbort = undefined;
|
|
31
27
|
}
|
|
32
28
|
}
|
|
33
|
-
exports.Abortable = Abortable;
|
|
34
29
|
// convenience function
|
|
35
|
-
function abortable(onAbort) {
|
|
30
|
+
export function abortable(onAbort) {
|
|
36
31
|
return new Abortable(onAbort);
|
|
37
32
|
}
|
package/dist/promise/pDefer.js
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.pDefer = pDefer;
|
|
4
1
|
/* eslint-disable @typescript-eslint/promise-function-async */
|
|
5
2
|
/**
|
|
6
3
|
* Returns DeferredPromise - a Promise that has .resolve() and .reject() methods.
|
|
7
4
|
*/
|
|
8
|
-
function pDefer() {
|
|
5
|
+
export function pDefer() {
|
|
9
6
|
let resolve;
|
|
10
7
|
let reject;
|
|
11
8
|
const promise = new Promise((_resolve, _reject) => {
|
package/dist/promise/pDelay.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { NumberOfMilliseconds, PromisableFunction } from '../types';
|
|
2
|
-
import type { DeferredPromise } from './pDefer';
|
|
1
|
+
import type { NumberOfMilliseconds, PromisableFunction } from '../types.js';
|
|
2
|
+
import type { DeferredPromise } from './pDefer.js';
|
|
3
3
|
/**
|
|
4
4
|
* Promisified version of setTimeout.
|
|
5
5
|
*
|
package/dist/promise/pDelay.js
CHANGED
|
@@ -1,15 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.pDelay = pDelay;
|
|
4
|
-
exports.pDelayFn = pDelayFn;
|
|
5
|
-
const pDefer_1 = require("./pDefer");
|
|
1
|
+
import { pDefer } from './pDefer.js';
|
|
6
2
|
/**
|
|
7
3
|
* Promisified version of setTimeout.
|
|
8
4
|
*
|
|
9
5
|
* Can return a value.
|
|
10
6
|
* If value is instanceof Error - rejects the Promise instead of resolving.
|
|
11
7
|
*/
|
|
12
|
-
async function pDelay(ms = 0, value) {
|
|
8
|
+
export async function pDelay(ms = 0, value) {
|
|
13
9
|
return await new Promise((resolve, reject) => setTimeout(value instanceof Error ? reject : resolve, ms, value));
|
|
14
10
|
}
|
|
15
11
|
/* eslint-disable @typescript-eslint/promise-function-async */
|
|
@@ -22,8 +18,8 @@ async function pDelay(ms = 0, value) {
|
|
|
22
18
|
*
|
|
23
19
|
* On abort() - clears the Timeout and immediately resolves the Promise with void.
|
|
24
20
|
*/
|
|
25
|
-
function pDelayFn(ms, fn) {
|
|
26
|
-
const p =
|
|
21
|
+
export function pDelayFn(ms, fn) {
|
|
22
|
+
const p = pDefer();
|
|
27
23
|
const timer = setTimeout(async () => {
|
|
28
24
|
try {
|
|
29
25
|
p.resolve(await fn());
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { AsyncPredicate } from '../types';
|
|
1
|
+
import type { AsyncPredicate } from '../types.js';
|
|
2
2
|
export declare function pFilter<T>(iterable: Iterable<T>, filterFn: AsyncPredicate<T>): Promise<T[]>;
|
package/dist/promise/pFilter.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.pFilter = pFilter;
|
|
4
|
-
async function pFilter(iterable, filterFn) {
|
|
1
|
+
export async function pFilter(iterable, filterFn) {
|
|
5
2
|
const items = [...iterable];
|
|
6
3
|
const predicates = await Promise.all(items.map((item, i) => filterFn(item, i)));
|
|
7
4
|
return items.filter((_item, i) => predicates[i]);
|
package/dist/promise/pHang.js
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.pHang = pHang;
|
|
4
1
|
/**
|
|
5
2
|
* Returns Promise that never resolves ("hanging").
|
|
6
3
|
*/
|
|
7
|
-
async function pHang() {
|
|
4
|
+
export async function pHang() {
|
|
8
5
|
return await new Promise(() => void 0);
|
|
9
6
|
}
|
package/dist/promise/pMap.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { AbortableAsyncMapper, CommonLogger } from '
|
|
2
|
-
import { ErrorMode } from '
|
|
1
|
+
import type { AbortableAsyncMapper, CommonLogger } from '../index.js';
|
|
2
|
+
import { ErrorMode } from '../index.js';
|
|
3
3
|
export interface PMapOptions {
|
|
4
4
|
/**
|
|
5
5
|
* Number of concurrently pending promises returned by `mapper`.
|