@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/promise/pMap.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.pMap = pMap;
|
|
4
|
-
const __1 = require("..");
|
|
1
|
+
import { END, ErrorMode, SKIP } from '../index.js';
|
|
5
2
|
/**
|
|
6
3
|
* Forked from https://github.com/sindresorhus/p-map
|
|
7
4
|
*
|
|
@@ -36,12 +33,12 @@ const __1 = require("..");
|
|
|
36
33
|
* //=> ['http://ava.li/', 'http://todomvc.com/']
|
|
37
34
|
* })();
|
|
38
35
|
*/
|
|
39
|
-
async function pMap(iterable, mapper, opt = {}) {
|
|
36
|
+
export async function pMap(iterable, mapper, opt = {}) {
|
|
40
37
|
const items = [...iterable];
|
|
41
38
|
const itemsLength = items.length;
|
|
42
39
|
if (itemsLength === 0)
|
|
43
40
|
return []; // short circuit
|
|
44
|
-
const { concurrency = Infinity, errorMode =
|
|
41
|
+
const { concurrency = Infinity, errorMode = ErrorMode.THROW_IMMEDIATELY, logger = console } = opt;
|
|
45
42
|
// Special cases that are able to preserve async stack traces
|
|
46
43
|
// Special case: serial execution
|
|
47
44
|
if (concurrency === 1) {
|
|
@@ -67,7 +64,7 @@ async function pMap(iterable, mapper, opt = {}) {
|
|
|
67
64
|
if (currentIndex > itemsLength) {
|
|
68
65
|
if (resolvingCount === 0) {
|
|
69
66
|
isSettled = true;
|
|
70
|
-
const r = ret.filter(r => r !==
|
|
67
|
+
const r = ret.filter(r => r !== SKIP);
|
|
71
68
|
if (errors.length) {
|
|
72
69
|
reject(new AggregateError(errors, `pMap resulted in ${errors.length} error(s)`));
|
|
73
70
|
}
|
|
@@ -81,20 +78,20 @@ async function pMap(iterable, mapper, opt = {}) {
|
|
|
81
78
|
Promise.resolve(nextItem)
|
|
82
79
|
.then(async (element) => await mapper(element, i))
|
|
83
80
|
.then(value => {
|
|
84
|
-
if (value ===
|
|
81
|
+
if (value === END) {
|
|
85
82
|
isSettled = true;
|
|
86
|
-
return resolve(ret.filter(r => r !==
|
|
83
|
+
return resolve(ret.filter(r => r !== SKIP));
|
|
87
84
|
}
|
|
88
85
|
ret[i] = value;
|
|
89
86
|
resolvingCount--;
|
|
90
87
|
next();
|
|
91
88
|
}, (err) => {
|
|
92
|
-
if (errorMode ===
|
|
89
|
+
if (errorMode === ErrorMode.THROW_IMMEDIATELY) {
|
|
93
90
|
isSettled = true;
|
|
94
91
|
reject(err);
|
|
95
92
|
}
|
|
96
93
|
else {
|
|
97
|
-
if (errorMode ===
|
|
94
|
+
if (errorMode === ErrorMode.THROW_AGGREGATED) {
|
|
98
95
|
errors.push(err);
|
|
99
96
|
}
|
|
100
97
|
else {
|
|
@@ -124,15 +121,15 @@ async function pMap1(items, mapper, errorMode, logger) {
|
|
|
124
121
|
for (const item of items) {
|
|
125
122
|
try {
|
|
126
123
|
const r = await mapper(item, i++);
|
|
127
|
-
if (r ===
|
|
124
|
+
if (r === END)
|
|
128
125
|
break;
|
|
129
|
-
if (r !==
|
|
126
|
+
if (r !== SKIP)
|
|
130
127
|
ret.push(r);
|
|
131
128
|
}
|
|
132
129
|
catch (err) {
|
|
133
|
-
if (errorMode ===
|
|
130
|
+
if (errorMode === ErrorMode.THROW_IMMEDIATELY)
|
|
134
131
|
throw err;
|
|
135
|
-
if (errorMode ===
|
|
132
|
+
if (errorMode === ErrorMode.THROW_AGGREGATED) {
|
|
136
133
|
errors.push(err);
|
|
137
134
|
}
|
|
138
135
|
else {
|
|
@@ -150,19 +147,19 @@ async function pMap1(items, mapper, errorMode, logger) {
|
|
|
150
147
|
pMap with fully concurrent execution, like Promise.all
|
|
151
148
|
*/
|
|
152
149
|
async function pMapAll(items, mapper, errorMode, logger) {
|
|
153
|
-
if (errorMode ===
|
|
154
|
-
return (await Promise.all(items.map((item, i) => mapper(item, i)))).filter(r => r !==
|
|
150
|
+
if (errorMode === ErrorMode.THROW_IMMEDIATELY) {
|
|
151
|
+
return (await Promise.all(items.map((item, i) => mapper(item, i)))).filter(r => r !== SKIP && r !== END);
|
|
155
152
|
}
|
|
156
153
|
const ret = [];
|
|
157
154
|
const errors = [];
|
|
158
155
|
for (const r of await Promise.allSettled(items.map((item, i) => mapper(item, i)))) {
|
|
159
156
|
if (r.status === 'fulfilled') {
|
|
160
|
-
if (r.value ===
|
|
157
|
+
if (r.value === END)
|
|
161
158
|
break;
|
|
162
|
-
if (r.value !==
|
|
159
|
+
if (r.value !== SKIP)
|
|
163
160
|
ret.push(r.value);
|
|
164
161
|
}
|
|
165
|
-
else if (errorMode ===
|
|
162
|
+
else if (errorMode === ErrorMode.THROW_AGGREGATED) {
|
|
166
163
|
errors.push(r.reason);
|
|
167
164
|
}
|
|
168
165
|
else {
|
package/dist/promise/pProps.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.pProps = pProps;
|
|
4
1
|
/**
|
|
5
2
|
* Promise.all for Object instead of Array.
|
|
6
3
|
*
|
|
@@ -15,7 +12,7 @@ exports.pProps = pProps;
|
|
|
15
12
|
* Concurrency implementation via pMap was removed in favor of preserving async
|
|
16
13
|
* stack traces (more important!).
|
|
17
14
|
*/
|
|
18
|
-
async function pProps(input) {
|
|
15
|
+
export async function pProps(input) {
|
|
19
16
|
const keys = Object.keys(input);
|
|
20
17
|
// `as any` here is added to make it compile when `noUncheckedIndexedAccess` is false
|
|
21
18
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
|
package/dist/promise/pQueue.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ErrorMode } from '../error/errorMode';
|
|
2
|
-
import type { CommonLogger } from '../log/commonLogger';
|
|
1
|
+
import { ErrorMode } from '../error/errorMode.js';
|
|
2
|
+
import type { CommonLogger } from '../log/commonLogger.js';
|
|
3
3
|
export interface PQueueCfg {
|
|
4
4
|
concurrency: number;
|
|
5
5
|
/**
|
package/dist/promise/pQueue.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.PQueue = void 0;
|
|
4
|
-
const errorMode_1 = require("../error/errorMode");
|
|
5
|
-
const pDefer_1 = require("./pDefer");
|
|
1
|
+
import { ErrorMode } from '../error/errorMode.js';
|
|
2
|
+
import { pDefer } from './pDefer.js';
|
|
6
3
|
/**
|
|
7
4
|
* Inspired by: https://github.com/sindresorhus/p-queue
|
|
8
5
|
*
|
|
@@ -11,11 +8,11 @@ const pDefer_1 = require("./pDefer");
|
|
|
11
8
|
*
|
|
12
9
|
* API is @experimental
|
|
13
10
|
*/
|
|
14
|
-
class PQueue {
|
|
11
|
+
export class PQueue {
|
|
15
12
|
constructor(cfg) {
|
|
16
13
|
this.cfg = {
|
|
17
14
|
// concurrency: Number.MAX_SAFE_INTEGER,
|
|
18
|
-
errorMode:
|
|
15
|
+
errorMode: ErrorMode.THROW_IMMEDIATELY,
|
|
19
16
|
logger: console,
|
|
20
17
|
debug: false,
|
|
21
18
|
resolveOn: 'finish',
|
|
@@ -43,7 +40,7 @@ class PQueue {
|
|
|
43
40
|
async onIdle() {
|
|
44
41
|
if (this.queue.length === 0 && this.inFlight === 0)
|
|
45
42
|
return;
|
|
46
|
-
const listener =
|
|
43
|
+
const listener = pDefer();
|
|
47
44
|
this.onIdleListeners.push(listener);
|
|
48
45
|
return await listener;
|
|
49
46
|
}
|
|
@@ -55,7 +52,7 @@ class PQueue {
|
|
|
55
52
|
const { concurrency } = this.cfg;
|
|
56
53
|
const resolveOnStart = this.cfg.resolveOn === 'start';
|
|
57
54
|
const fn = fn_;
|
|
58
|
-
fn.defer ||=
|
|
55
|
+
fn.defer ||= pDefer();
|
|
59
56
|
if (this.inFlight < concurrency) {
|
|
60
57
|
// There is room for more jobs. Can start immediately
|
|
61
58
|
this.inFlight++;
|
|
@@ -71,7 +68,7 @@ class PQueue {
|
|
|
71
68
|
this.cfg.logger.error(err);
|
|
72
69
|
if (resolveOnStart)
|
|
73
70
|
return;
|
|
74
|
-
if (this.cfg.errorMode ===
|
|
71
|
+
if (this.cfg.errorMode === ErrorMode.SUPPRESS) {
|
|
75
72
|
fn.defer.resolve(); // resolve with `void`
|
|
76
73
|
}
|
|
77
74
|
else {
|
|
@@ -103,4 +100,3 @@ class PQueue {
|
|
|
103
100
|
return await fn.defer;
|
|
104
101
|
}
|
|
105
102
|
}
|
|
106
|
-
exports.PQueue = PQueue;
|
package/dist/promise/pRetry.d.ts
CHANGED
package/dist/promise/pRetry.js
CHANGED
|
@@ -1,18 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.pRetryFn = pRetryFn;
|
|
4
|
-
exports.pRetry = pRetry;
|
|
5
|
-
const __1 = require("..");
|
|
1
|
+
import { _errorDataAppend, _since, pDelay, pTimeout } from '../index.js';
|
|
6
2
|
/**
|
|
7
3
|
* Returns a Function (!), enhanced with retry capabilities.
|
|
8
4
|
* Implements "Exponential back-off strategy" by multiplying the delay by `delayMultiplier` with each try.
|
|
9
5
|
*/
|
|
10
|
-
function pRetryFn(fn, opt = {}) {
|
|
6
|
+
export function pRetryFn(fn, opt = {}) {
|
|
11
7
|
return async function pRetryFunction(...args) {
|
|
12
8
|
return await pRetry(() => fn.call(this, ...args), opt);
|
|
13
9
|
};
|
|
14
10
|
}
|
|
15
|
-
async function pRetry(fn, opt = {}) {
|
|
11
|
+
export async function pRetry(fn, opt = {}) {
|
|
16
12
|
const { maxAttempts = 4, delay: initialDelay = 1000, delayMultiplier = 2, predicate, logger = console, name, timeout, } = opt;
|
|
17
13
|
const fakeError = timeout ? new Error('TimeoutError') : undefined;
|
|
18
14
|
let { logFirstAttempt = false, logRetries = true, logFailures = true, logSuccess = false } = opt;
|
|
@@ -34,7 +30,7 @@ async function pRetry(fn, opt = {}) {
|
|
|
34
30
|
}
|
|
35
31
|
let result;
|
|
36
32
|
if (timeout) {
|
|
37
|
-
result = await
|
|
33
|
+
result = await pTimeout(async () => await fn(attempt), {
|
|
38
34
|
timeout,
|
|
39
35
|
name: fname,
|
|
40
36
|
errorData: opt.errorData,
|
|
@@ -45,7 +41,7 @@ async function pRetry(fn, opt = {}) {
|
|
|
45
41
|
result = await fn(attempt);
|
|
46
42
|
}
|
|
47
43
|
if (logSuccess) {
|
|
48
|
-
logger.log(`${fname} attempt #${attempt} succeeded in ${
|
|
44
|
+
logger.log(`${fname} attempt #${attempt} succeeded in ${_since(started)}`);
|
|
49
45
|
}
|
|
50
46
|
return result;
|
|
51
47
|
}
|
|
@@ -53,15 +49,15 @@ async function pRetry(fn, opt = {}) {
|
|
|
53
49
|
if (logFailures) {
|
|
54
50
|
// Logger at warn (not error) level, because it's not a fatal error, but a retriable one
|
|
55
51
|
// Fatal one is not logged either, because it's been thrown instead
|
|
56
|
-
logger.warn(`${fname} attempt #${attempt} error in ${
|
|
52
|
+
logger.warn(`${fname} attempt #${attempt} error in ${_since(started)}:`, err);
|
|
57
53
|
}
|
|
58
54
|
if (attempt >= maxAttempts || (predicate && !predicate(err, attempt, maxAttempts))) {
|
|
59
55
|
// Give up
|
|
60
|
-
throw
|
|
56
|
+
throw _errorDataAppend(err, opt.errorData);
|
|
61
57
|
}
|
|
62
58
|
// Retry after delay
|
|
63
59
|
delay *= delayMultiplier;
|
|
64
|
-
await
|
|
60
|
+
await pDelay(delay);
|
|
65
61
|
// back to while(true) loop
|
|
66
62
|
}
|
|
67
63
|
}
|
package/dist/promise/pState.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.pState = pState;
|
|
4
1
|
const UNIQUE_VALUE = Symbol('unique');
|
|
5
2
|
/**
|
|
6
3
|
* Returns the state of the Promise, one of:
|
|
@@ -10,7 +7,7 @@ const UNIQUE_VALUE = Symbol('unique');
|
|
|
10
7
|
*
|
|
11
8
|
* Based on: https://makandracards.com/makandra/46681-javascript-how-to-query-the-state-of-a-native-promise
|
|
12
9
|
*/
|
|
13
|
-
async function pState(p) {
|
|
10
|
+
export async function pState(p) {
|
|
14
11
|
return await Promise.race([p, Promise.resolve(UNIQUE_VALUE)]).then(v => {
|
|
15
12
|
return v === UNIQUE_VALUE ? 'pending' : 'resolved';
|
|
16
13
|
}, () => 'rejected');
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { ErrorData } from '../error/error.model';
|
|
2
|
-
import { TimeoutError } from '../error/error.util';
|
|
3
|
-
import type { AnyAsyncFunction, NumberOfMilliseconds } from '../types';
|
|
1
|
+
import type { ErrorData } from '../error/error.model.js';
|
|
2
|
+
import { TimeoutError } from '../error/error.util.js';
|
|
3
|
+
import type { AnyAsyncFunction, NumberOfMilliseconds } from '../types.js';
|
|
4
4
|
export interface PTimeoutOptions {
|
|
5
5
|
/**
|
|
6
6
|
* Timeout in milliseconds.
|
package/dist/promise/pTimeout.js
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.pTimeoutFn = pTimeoutFn;
|
|
4
|
-
exports.pTimeout = pTimeout;
|
|
5
|
-
const error_util_1 = require("../error/error.util");
|
|
6
|
-
const types_1 = require("../types");
|
|
1
|
+
import { _errorDataAppend, TimeoutError } from '../error/error.util.js';
|
|
2
|
+
import { _typeCast } from '../types.js';
|
|
7
3
|
/**
|
|
8
4
|
* Decorates a Function with a timeout.
|
|
9
5
|
* Returns a decorated Function.
|
|
@@ -11,7 +7,7 @@ const types_1 = require("../types");
|
|
|
11
7
|
* Throws an Error if the Function is not resolved in a certain time.
|
|
12
8
|
* If the Function rejects - passes this rejection further.
|
|
13
9
|
*/
|
|
14
|
-
function pTimeoutFn(fn, opt) {
|
|
10
|
+
export function pTimeoutFn(fn, opt) {
|
|
15
11
|
opt.name ||= fn.name;
|
|
16
12
|
if (!opt.timeout) {
|
|
17
13
|
return fn;
|
|
@@ -26,7 +22,7 @@ function pTimeoutFn(fn, opt) {
|
|
|
26
22
|
* Throws an Error if the Function is not resolved in a certain time.
|
|
27
23
|
* If the Function rejects - passes this rejection further.
|
|
28
24
|
*/
|
|
29
|
-
async function pTimeout(fn, opt) {
|
|
25
|
+
export async function pTimeout(fn, opt) {
|
|
30
26
|
if (!opt.timeout) {
|
|
31
27
|
// short-circuit to direct execution if 0 timeout is passed
|
|
32
28
|
return await fn();
|
|
@@ -37,7 +33,7 @@ async function pTimeout(fn, opt) {
|
|
|
37
33
|
return await new Promise(async (resolve, reject) => {
|
|
38
34
|
// Prepare the timeout timer
|
|
39
35
|
const timer = setTimeout(() => {
|
|
40
|
-
const err = new
|
|
36
|
+
const err = new TimeoutError(`"${name}" timed out after ${timeout} ms`, opt.errorData);
|
|
41
37
|
// keep original stack
|
|
42
38
|
err.stack = fakeError.stack.replace('Error: TimeoutError', 'TimeoutError: ' + err.message);
|
|
43
39
|
if (onTimeout) {
|
|
@@ -45,10 +41,10 @@ async function pTimeout(fn, opt) {
|
|
|
45
41
|
resolve(onTimeout(err));
|
|
46
42
|
}
|
|
47
43
|
catch (err) {
|
|
48
|
-
|
|
44
|
+
_typeCast(err);
|
|
49
45
|
// keep original stack
|
|
50
46
|
err.stack = fakeError.stack.replace('Error: TimeoutError', err.name + ': ' + err.message);
|
|
51
|
-
reject(
|
|
47
|
+
reject(_errorDataAppend(err, opt.errorData));
|
|
52
48
|
}
|
|
53
49
|
return;
|
|
54
50
|
}
|
package/dist/semver.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { SortDirection } from './types';
|
|
1
|
+
import type { SortDirection } from './types.js';
|
|
2
2
|
export type SemverInput = string | Semver;
|
|
3
3
|
export type SemverInputNullable = SemverInput | null | undefined;
|
|
4
4
|
export type SemverTokens = [major: number, minor: number, patch: number];
|
package/dist/semver.js
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.semver2 = exports.Semver = void 0;
|
|
4
|
-
exports._quickSemverCompare = _quickSemverCompare;
|
|
5
|
-
const range_1 = require("./array/range");
|
|
6
|
-
const assert_1 = require("./error/assert");
|
|
1
|
+
import { _range } from './array/range.js';
|
|
2
|
+
import { _assert } from './error/assert.js';
|
|
7
3
|
/**
|
|
8
4
|
* Simple Semver implementation.
|
|
9
5
|
*
|
|
@@ -20,7 +16,7 @@ const assert_1 = require("./error/assert");
|
|
|
20
16
|
*
|
|
21
17
|
* @experimental
|
|
22
18
|
*/
|
|
23
|
-
class Semver {
|
|
19
|
+
export class Semver {
|
|
24
20
|
tokens;
|
|
25
21
|
constructor(tokens) {
|
|
26
22
|
this.tokens = tokens;
|
|
@@ -45,7 +41,7 @@ class Semver {
|
|
|
45
41
|
* returns -1 if this < other
|
|
46
42
|
*/
|
|
47
43
|
compare(other) {
|
|
48
|
-
const { tokens } =
|
|
44
|
+
const { tokens } = semver2.fromInput(other);
|
|
49
45
|
for (let i = 0; i < 3; i++) {
|
|
50
46
|
if (this.tokens[i] < tokens[i])
|
|
51
47
|
return -1;
|
|
@@ -59,11 +55,10 @@ class Semver {
|
|
|
59
55
|
return this.tokens.join('.');
|
|
60
56
|
}
|
|
61
57
|
}
|
|
62
|
-
exports.Semver = Semver;
|
|
63
58
|
class SemverFactory {
|
|
64
59
|
fromInput(input) {
|
|
65
60
|
const s = this.fromInputOrUndefined(input);
|
|
66
|
-
|
|
61
|
+
_assert(s, `Cannot parse "${input}" into Semver`, {
|
|
67
62
|
input,
|
|
68
63
|
});
|
|
69
64
|
return s;
|
|
@@ -74,7 +69,7 @@ class SemverFactory {
|
|
|
74
69
|
if (input instanceof Semver)
|
|
75
70
|
return input;
|
|
76
71
|
const t = input.split('.');
|
|
77
|
-
return new Semver(
|
|
72
|
+
return new Semver(_range(3).map(i => parseInt(t[i]) || 0));
|
|
78
73
|
}
|
|
79
74
|
/**
|
|
80
75
|
* Returns the highest (max) Semver from the array, or undefined if the array is empty.
|
|
@@ -95,7 +90,7 @@ class SemverFactory {
|
|
|
95
90
|
*/
|
|
96
91
|
max(items) {
|
|
97
92
|
const max = this.maxOrUndefined(items);
|
|
98
|
-
|
|
93
|
+
_assert(max, 'semver.max called on empty array');
|
|
99
94
|
return max;
|
|
100
95
|
}
|
|
101
96
|
/**
|
|
@@ -117,7 +112,7 @@ class SemverFactory {
|
|
|
117
112
|
*/
|
|
118
113
|
min(items) {
|
|
119
114
|
const min = this.minOrUndefined(items);
|
|
120
|
-
|
|
115
|
+
_assert(min, 'semver.min called on empty array');
|
|
121
116
|
return min;
|
|
122
117
|
}
|
|
123
118
|
/**
|
|
@@ -129,10 +124,10 @@ class SemverFactory {
|
|
|
129
124
|
}
|
|
130
125
|
}
|
|
131
126
|
const semverFactory = new SemverFactory();
|
|
132
|
-
|
|
127
|
+
export const semver2 = semverFactory.fromInput.bind(semverFactory);
|
|
133
128
|
// The line below is the blackest of black magic I have ever written in 2024.
|
|
134
129
|
// And probably 2023 as well.
|
|
135
|
-
Object.setPrototypeOf(
|
|
130
|
+
Object.setPrototypeOf(semver2, semverFactory);
|
|
136
131
|
/**
|
|
137
132
|
* Returns 1 if a > b
|
|
138
133
|
* returns 0 if they are equal
|
|
@@ -142,13 +137,13 @@ Object.setPrototypeOf(exports.semver2, semverFactory);
|
|
|
142
137
|
*
|
|
143
138
|
* Credit: https://stackoverflow.com/a/47159772/4919972
|
|
144
139
|
*/
|
|
145
|
-
function _quickSemverCompare(a, b) {
|
|
140
|
+
export function _quickSemverCompare(a, b) {
|
|
146
141
|
const t1 = a.split('.');
|
|
147
142
|
const t2 = b.split('.');
|
|
148
|
-
const s1 =
|
|
143
|
+
const s1 = _range(3)
|
|
149
144
|
.map(i => (t1[i] || '').padStart(5))
|
|
150
145
|
.join('');
|
|
151
|
-
const s2 =
|
|
146
|
+
const s2 = _range(3)
|
|
152
147
|
.map(i => (t2[i] || '').padStart(5))
|
|
153
148
|
.join('');
|
|
154
149
|
return s1 < s2 ? -1 : s1 > s2 ? 1 : 0;
|
package/dist/string/case.js
CHANGED
|
@@ -1,28 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
exports._snakeCase = _snakeCase;
|
|
5
|
-
exports._kebabCase = _kebabCase;
|
|
6
|
-
const words_1 = require("./lodash/words");
|
|
7
|
-
const string_util_1 = require("./string.util");
|
|
8
|
-
function _camelCase(s) {
|
|
1
|
+
import { words } from './lodash/words.js';
|
|
2
|
+
import { _upperFirst } from './string.util.js';
|
|
3
|
+
export function _camelCase(s) {
|
|
9
4
|
let r = '';
|
|
10
|
-
for (let word of
|
|
5
|
+
for (let word of words(s.replaceAll(/['\u2019]/g, ''))) {
|
|
11
6
|
word = word.toLowerCase();
|
|
12
|
-
r += r ?
|
|
7
|
+
r += r ? _upperFirst(word) : word;
|
|
13
8
|
}
|
|
14
9
|
return r;
|
|
15
10
|
}
|
|
16
|
-
function _snakeCase(s) {
|
|
11
|
+
export function _snakeCase(s) {
|
|
17
12
|
let r = '';
|
|
18
|
-
for (const word of
|
|
13
|
+
for (const word of words(s.replaceAll(/['\u2019]/g, ''))) {
|
|
19
14
|
r += (r ? '_' : '') + word.toLowerCase();
|
|
20
15
|
}
|
|
21
16
|
return r;
|
|
22
17
|
}
|
|
23
|
-
function _kebabCase(s) {
|
|
18
|
+
export function _kebabCase(s) {
|
|
24
19
|
let r = '';
|
|
25
|
-
for (const word of
|
|
20
|
+
for (const word of words(s.replaceAll(/['\u2019]/g, ''))) {
|
|
26
21
|
r += (r ? '-' : '') + word.toLowerCase();
|
|
27
22
|
}
|
|
28
23
|
return r;
|
package/dist/string/escape.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/*
|
|
3
2
|
|
|
4
3
|
Vendored:
|
|
@@ -11,9 +10,6 @@ Reasons:
|
|
|
11
10
|
2. ESM-only
|
|
12
11
|
|
|
13
12
|
*/
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.htmlEscape = htmlEscape;
|
|
16
|
-
exports.htmlUnescape = htmlUnescape;
|
|
17
13
|
// Multiple `.replace()` calls are actually faster than using replacer functions
|
|
18
14
|
function _htmlEscape(s) {
|
|
19
15
|
return s
|
|
@@ -31,7 +27,7 @@ function _htmlUnescape(html) {
|
|
|
31
27
|
.replaceAll('"', '"')
|
|
32
28
|
.replaceAll('&', '&'); // Must happen last or else it will unescape other characters in the wrong order.
|
|
33
29
|
}
|
|
34
|
-
function htmlEscape(strings, ...values) {
|
|
30
|
+
export function htmlEscape(strings, ...values) {
|
|
35
31
|
if (typeof strings === 'string') {
|
|
36
32
|
return _htmlEscape(strings);
|
|
37
33
|
}
|
|
@@ -41,7 +37,7 @@ function htmlEscape(strings, ...values) {
|
|
|
41
37
|
}
|
|
42
38
|
return output;
|
|
43
39
|
}
|
|
44
|
-
function htmlUnescape(strings, ...values) {
|
|
40
|
+
export function htmlUnescape(strings, ...values) {
|
|
45
41
|
if (typeof strings === 'string') {
|
|
46
42
|
return _htmlUnescape(strings);
|
|
47
43
|
}
|
package/dist/string/hash.util.js
CHANGED
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.hashCode16 = hashCode16;
|
|
4
|
-
exports.hashCode36 = hashCode36;
|
|
5
|
-
exports.hashCode64 = hashCode64;
|
|
6
|
-
exports.hashCode = hashCode;
|
|
7
1
|
const BASE62 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
8
2
|
// const BASE64 = BASE62 + '+/'
|
|
9
3
|
const BASE64URL = BASE62 + '-_';
|
|
@@ -24,7 +18,7 @@ const BASE64URL = BASE62 + '-_';
|
|
|
24
18
|
* Perf: it runs ~10 times faster than CryptoJS md5, and ~3 times smaller String hash size (for
|
|
25
19
|
* hashCode64).
|
|
26
20
|
*/
|
|
27
|
-
function hashCode16(s) {
|
|
21
|
+
export function hashCode16(s) {
|
|
28
22
|
return hashCode(s).toString(16);
|
|
29
23
|
}
|
|
30
24
|
/**
|
|
@@ -33,14 +27,14 @@ function hashCode16(s) {
|
|
|
33
27
|
*
|
|
34
28
|
* See the hashCode16 for full description.
|
|
35
29
|
*/
|
|
36
|
-
function hashCode36(s) {
|
|
30
|
+
export function hashCode36(s) {
|
|
37
31
|
return hashCode(s).toString(36);
|
|
38
32
|
}
|
|
39
33
|
/**
|
|
40
34
|
* Returns hashCode as "radix 64", using Base64url alphabet.
|
|
41
35
|
* See the hashCode16 for full description.
|
|
42
36
|
*/
|
|
43
|
-
function hashCode64(s) {
|
|
37
|
+
export function hashCode64(s) {
|
|
44
38
|
return numberToBase(hashCode(s), BASE64URL);
|
|
45
39
|
}
|
|
46
40
|
/**
|
|
@@ -49,7 +43,7 @@ function hashCode64(s) {
|
|
|
49
43
|
* by adding 2147483647 + 1 to the end result.
|
|
50
44
|
* Source: https://stackoverflow.com/a/33647870/4919972
|
|
51
45
|
*/
|
|
52
|
-
function hashCode(s) {
|
|
46
|
+
export function hashCode(s) {
|
|
53
47
|
let hash = 0;
|
|
54
48
|
let i = 0;
|
|
55
49
|
const len = s.length;
|
package/dist/string/json.util.js
CHANGED
|
@@ -1,16 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports._jsonParseIfPossible = _jsonParseIfPossible;
|
|
4
|
-
exports._jsonParseOrUndefined = _jsonParseOrUndefined;
|
|
5
|
-
exports._jsonParse = _jsonParse;
|
|
6
|
-
const error_util_1 = require("../error/error.util");
|
|
1
|
+
import { JsonParseError } from '../error/error.util.js';
|
|
7
2
|
// const possibleJsonStartTokens = ['{', '[', '"']
|
|
8
3
|
const DETECT_JSON = /^\s*[{["\-\d]/;
|
|
9
4
|
/**
|
|
10
5
|
* Attempts to parse object as JSON.
|
|
11
6
|
* Returns original object if JSON parse failed (silently).
|
|
12
7
|
*/
|
|
13
|
-
function _jsonParseIfPossible(obj, reviver) {
|
|
8
|
+
export function _jsonParseIfPossible(obj, reviver) {
|
|
14
9
|
// Optimization: only try to parse if it looks like JSON: starts with a json possible character
|
|
15
10
|
if (typeof obj === 'string' && obj && DETECT_JSON.test(obj)) {
|
|
16
11
|
try {
|
|
@@ -24,7 +19,7 @@ function _jsonParseIfPossible(obj, reviver) {
|
|
|
24
19
|
* Convenience function that does JSON.parse, but doesn't throw on error,
|
|
25
20
|
* instead - safely returns `undefined`.
|
|
26
21
|
*/
|
|
27
|
-
function _jsonParseOrUndefined(obj, reviver) {
|
|
22
|
+
export function _jsonParseOrUndefined(obj, reviver) {
|
|
28
23
|
// Optimization: only try to parse if it looks like JSON: starts with a json possible character
|
|
29
24
|
if (typeof obj === 'string' && obj && DETECT_JSON.test(obj)) {
|
|
30
25
|
try {
|
|
@@ -39,12 +34,12 @@ function _jsonParseOrUndefined(obj, reviver) {
|
|
|
39
34
|
* 1. It's message includes a piece of source text (truncated)
|
|
40
35
|
* 2. It's data.text contains full source text
|
|
41
36
|
*/
|
|
42
|
-
function _jsonParse(s, reviver) {
|
|
37
|
+
export function _jsonParse(s, reviver) {
|
|
43
38
|
try {
|
|
44
39
|
return JSON.parse(s, reviver);
|
|
45
40
|
}
|
|
46
41
|
catch {
|
|
47
|
-
throw new
|
|
42
|
+
throw new JsonParseError({
|
|
48
43
|
text: s,
|
|
49
44
|
});
|
|
50
45
|
}
|
package/dist/string/leven.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports._leven = _leven;
|
|
4
1
|
const array = [];
|
|
5
2
|
const characterCodeCache = [];
|
|
6
3
|
/* eslint-disable unicorn/prefer-code-point, no-bitwise */
|
|
@@ -12,7 +9,7 @@ const characterCodeCache = [];
|
|
|
12
9
|
* `limit` optional parameter can be used to limit the distance calculation
|
|
13
10
|
* and skip unnecessary iterations when limit is reached.
|
|
14
11
|
*/
|
|
15
|
-
function _leven(first, second, limit) {
|
|
12
|
+
export function _leven(first, second, limit) {
|
|
16
13
|
if (first === second || limit === 0) {
|
|
17
14
|
return 0;
|
|
18
15
|
}
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
// from: https://github.com/lodash/lodash/blob/master/.internal/unicodeWords.js
|
|
3
2
|
/* eslint-disable */
|
|
4
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.unicodeWords = unicodeWords;
|
|
6
3
|
/** Used to compose unicode character classes. */
|
|
7
4
|
const rsAstralRange = '\\ud800-\\udfff';
|
|
8
5
|
const rsComboMarksRange = '\\u0300-\\u036f';
|
|
@@ -66,6 +63,6 @@ const reUnicodeWords = new RegExp([
|
|
|
66
63
|
*
|
|
67
64
|
* @returns {Array} Returns the words of `string`.
|
|
68
65
|
*/
|
|
69
|
-
function unicodeWords(s) {
|
|
66
|
+
export function unicodeWords(s) {
|
|
70
67
|
return s.match(reUnicodeWords);
|
|
71
68
|
}
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
// from: https://github.com/lodash/lodash/blob/master/words.js
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.words = words;
|
|
5
2
|
/* eslint-disable */
|
|
6
|
-
|
|
3
|
+
import { unicodeWords } from './unicodeWords.js';
|
|
7
4
|
const hasUnicodeWord = RegExp.prototype.test.bind(/[a-z][A-Z]|[A-Z]{2}[a-z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/);
|
|
8
5
|
/** Used to match words composed of alphanumeric characters. */
|
|
9
6
|
// biome-ignore lint/suspicious/noControlCharactersInRegex: ok
|
|
@@ -25,9 +22,9 @@ function asciiWords(s) {
|
|
|
25
22
|
* words('fred, barney, & pebbles', /[^, ]+/g)
|
|
26
23
|
* // => ['fred', 'barney', '&', 'pebbles']
|
|
27
24
|
*/
|
|
28
|
-
function words(s, pattern) {
|
|
25
|
+
export function words(s, pattern) {
|
|
29
26
|
if (pattern === undefined) {
|
|
30
|
-
const result = hasUnicodeWord(s) ?
|
|
27
|
+
const result = hasUnicodeWord(s) ? unicodeWords(s) : asciiWords(s);
|
|
31
28
|
return result || [];
|
|
32
29
|
}
|
|
33
30
|
return s.match(pattern) || [];
|