@oscarpalmer/atoms 0.212.0 → 0.214.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/dist/array/difference.d.mts +1 -1
- package/dist/array/difference.mjs +3 -2
- package/dist/array/exists.d.mts +1 -1
- package/dist/array/exists.mjs +3 -2
- package/dist/array/filter.d.mts +1 -1
- package/dist/array/filter.mjs +1 -0
- package/dist/array/find.d.mts +1 -1
- package/dist/array/find.mjs +4 -3
- package/dist/array/first.d.mts +1 -1
- package/dist/array/flatten.d.mts +1 -1
- package/dist/array/group-by.d.mts +1 -1
- package/dist/array/index.d.mts +2 -2
- package/dist/array/insert.mjs +3 -2
- package/dist/array/intersection.mjs +3 -2
- package/dist/array/last.d.mts +1 -1
- package/dist/array/move.d.mts +1 -1
- package/dist/array/partition.d.mts +1 -1
- package/dist/array/partition.mjs +1 -0
- package/dist/array/push.mjs +3 -2
- package/dist/array/select.d.mts +10 -12
- package/dist/array/select.mjs +1 -0
- package/dist/array/single.d.mts +1 -1
- package/dist/array/single.mjs +1 -0
- package/dist/array/slice.d.mts +1 -1
- package/dist/array/slice.mjs +4 -5
- package/dist/array/sort.d.mts +4 -103
- package/dist/array/sort.mjs +6 -14
- package/dist/array/splice.mjs +3 -2
- package/dist/array/swap.d.mts +1 -1
- package/dist/array/to-map.d.mts +1 -1
- package/dist/array/to-record.d.mts +1 -1
- package/dist/array/to-set.d.mts +1 -1
- package/dist/array/toggle.d.mts +1 -1
- package/dist/array/union.mjs +3 -2
- package/dist/array/unique.d.mts +1 -1
- package/dist/array/unique.mjs +3 -2
- package/dist/array/update.d.mts +1 -1
- package/dist/beacon.d.mts +6 -92
- package/dist/beacon.mjs +6 -16
- package/dist/color/constants.d.mts +2 -2
- package/dist/color/constants.mjs +1 -1
- package/dist/color/index.d.mts +1 -1
- package/dist/color/instance.d.mts +1 -1
- package/dist/color/instance.mjs +0 -1
- package/dist/color/misc/alpha.d.mts +1 -1
- package/dist/color/misc/format.d.mts +1 -1
- package/dist/color/misc/get.d.mts +1 -1
- package/dist/color/misc/is.d.mts +2 -2
- package/dist/color/misc/is.mjs +1 -0
- package/dist/color/misc/state.d.mts +1 -1
- package/dist/color/space/hex.d.mts +1 -1
- package/dist/color/space/hsl.d.mts +1 -1
- package/dist/color/space/hwb.d.mts +1 -1
- package/dist/color/space/rgb.d.mts +1 -1
- package/dist/function/limit.d.mts +2 -2
- package/dist/function/limit.mjs +2 -1
- package/dist/function/once.d.mts +7 -3
- package/dist/function/once.mjs +5 -10
- package/dist/function/retry.d.mts +4 -14
- package/dist/function/retry.mjs +3 -15
- package/dist/herald.d.mts +2 -2
- package/dist/index.d.mts +466 -351
- package/dist/index.mjs +491 -439
- package/dist/internal/aborter.d.mts +1 -6
- package/dist/internal/aborter.mjs +3 -4
- package/dist/internal/array/callbacks.d.mts +3 -7
- package/dist/internal/array/chunk.mjs +2 -2
- package/dist/internal/array/find.d.mts +5 -23
- package/dist/internal/array/find.mjs +5 -9
- package/dist/internal/array/get.d.mts +1 -1
- package/dist/internal/array/group.d.mts +1 -1
- package/dist/internal/array/index-of.d.mts +1 -1
- package/dist/internal/array/index-of.mjs +4 -3
- package/dist/internal/array/insert.d.mts +2 -5
- package/dist/internal/array/insert.mjs +2 -4
- package/dist/internal/array/match.d.mts +2 -5
- package/dist/internal/array/match.mjs +10 -20
- package/dist/internal/array/overlap.d.mts +2 -10
- package/dist/internal/array/sets.d.mts +2 -5
- package/dist/internal/array/sets.mjs +5 -7
- package/dist/internal/function/assert.d.mts +5 -12
- package/dist/internal/function/assert.mjs +2 -2
- package/dist/internal/function/limit.d.mts +2 -37
- package/dist/internal/function/limit.mjs +4 -15
- package/dist/internal/function/memoize.d.mts +5 -70
- package/dist/internal/function/memoize.mjs +2 -5
- package/dist/internal/function/work.d.mts +16 -22
- package/dist/internal/function/work.mjs +1 -8
- package/dist/internal/herald.d.mts +3 -3
- package/dist/internal/herald.mjs +2 -1
- package/dist/internal/is.d.mts +1 -1
- package/dist/internal/math/aggregate.d.mts +2 -14
- package/dist/internal/math/aggregate.mjs +2 -5
- package/dist/internal/number.mjs +4 -7
- package/dist/internal/result/attempt.d.mts +1 -1
- package/dist/internal/result/misc.d.mts +1 -1
- package/dist/internal/string/case.mjs +6 -16
- package/dist/internal/string/misc.mjs +1 -3
- package/dist/internal/subscription.d.mts +1 -100
- package/dist/internal/subscription.mjs +3 -9
- package/dist/internal/value/compare.d.mts +4 -4
- package/dist/internal/value/compare.mjs +1 -1
- package/dist/internal/value/equal.d.mts +6 -57
- package/dist/internal/value/equal.mjs +5 -10
- package/dist/internal/value/get.d.mts +1 -1
- package/dist/internal/value/handlers.d.mts +2 -21
- package/dist/internal/value/has.d.mts +2 -2
- package/dist/internal/value/misc.d.mts +1 -1
- package/dist/internal/value/misc.mjs +8 -14
- package/dist/internal/value/set.d.mts +1 -1
- package/dist/internal/value/set.mjs +2 -2
- package/dist/is.mjs +3 -3
- package/dist/logger.d.mts +3 -70
- package/dist/logger.mjs +2 -5
- package/dist/math.d.mts +1 -1
- package/dist/math.mjs +2 -1
- package/dist/models/aborter.model.d.mts +12 -0
- package/dist/models/aborter.model.mjs +5 -0
- package/dist/models/array/array.find.model.d.mts +22 -0
- package/dist/models/array/array.find.model.mjs +8 -0
- package/dist/models/array/array.match.model.d.mts +14 -0
- package/dist/models/array/array.match.model.mjs +14 -0
- package/dist/models/array/array.misc.model.d.mts +36 -0
- package/dist/models/array/array.misc.model.mjs +12 -0
- package/dist/models/array/array.sort.model.d.mts +122 -0
- package/dist/models/array/array.sort.model.mjs +12 -0
- package/dist/models/beacon.model.d.mts +119 -0
- package/dist/models/beacon.model.mjs +16 -0
- package/dist/{color/models.d.mts → models/color.model.d.mts} +4 -4
- package/dist/models/function/assert.model.d.mts +13 -0
- package/dist/models/function/assert.model.mjs +4 -0
- package/dist/models/function/limiter.model.d.mts +71 -0
- package/dist/models/function/limiter.model.mjs +15 -0
- package/dist/models/function/memoize.model.d.mts +88 -0
- package/dist/models/function/memoize.model.mjs +7 -0
- package/dist/models/function/once.model.d.mts +76 -0
- package/dist/models/function/once.model.mjs +9 -0
- package/dist/models/function/retry.model.d.mts +17 -0
- package/dist/models/function/retry.model.mjs +17 -0
- package/dist/models/function/work.model.d.mts +20 -0
- package/dist/models/function/work.model.mjs +11 -0
- package/dist/{internal/models → models}/herald.model.d.mts +3 -3
- package/dist/{internal/models → models}/herald.model.mjs +2 -2
- package/dist/{models.d.mts → models/index.d.mts} +8 -50
- package/dist/models/logger.model.d.mts +83 -0
- package/dist/models/logger.model.mjs +7 -0
- package/dist/models/math.model.d.mts +16 -0
- package/dist/models/math.model.mjs +7 -0
- package/dist/models/misc.model.d.mts +10 -0
- package/dist/models/misc.model.mjs +11 -0
- package/dist/{internal/models → models}/plan.model.d.mts +17 -15
- package/dist/{internal/models → models}/plan.model.mjs +1 -1
- package/dist/models/promise.model.d.mts +119 -0
- package/dist/models/promise.model.mjs +47 -0
- package/dist/models/query.model.d.mts +9 -0
- package/dist/models/query.model.mjs +14 -0
- package/dist/models/queue.model.d.mts +251 -0
- package/dist/models/queue.model.mjs +29 -0
- package/dist/models/random.model.d.mts +6 -0
- package/dist/models/random.model.mjs +7 -0
- package/dist/{internal/models → models}/result.model.d.mts +10 -2
- package/dist/models/string/string.case.model.d.mts +19 -0
- package/dist/models/string/string.case.model.mjs +14 -0
- package/dist/models/string/string.fuzzy.model.d.mts +108 -0
- package/dist/models/string/string.fuzzy.model.mjs +9 -0
- package/dist/models/string/string.misc.model.d.mts +13 -0
- package/dist/models/string/string.misc.model.mjs +13 -0
- package/dist/models/string/string.normalize.model.d.mts +85 -0
- package/dist/models/string/string.normalize.model.mjs +43 -0
- package/dist/models/string/string.template.model.d.mts +50 -0
- package/dist/models/string/string.template.model.mjs +5 -0
- package/dist/models/subscription.model.d.mts +127 -0
- package/dist/models/subscription.model.mjs +10 -0
- package/dist/models/value/value.clone.model.d.mts +56 -0
- package/dist/models/value/value.clone.model.mjs +24 -0
- package/dist/models/value/value.diff.model.d.mts +61 -0
- package/dist/models/value/value.diff.model.mjs +6 -0
- package/dist/models/value/value.equal.model.d.mts +76 -0
- package/dist/models/value/value.equal.model.mjs +9 -0
- package/dist/models/value/value.handler.model.d.mts +27 -0
- package/dist/models/value/value.handler.model.mjs +1 -0
- package/dist/models/value/value.merge.model.d.mts +82 -0
- package/dist/models/value/value.merge.model.mjs +5 -0
- package/dist/models/value/value.misc.model.d.mts +33 -0
- package/dist/models/value/value.misc.model.mjs +12 -0
- package/dist/models/value/value.transform.model.d.mts +28 -0
- package/dist/models/value/value.transform.model.mjs +4 -0
- package/dist/plan/generate.d.mts +3 -2
- package/dist/plan/generate.mjs +14 -10
- package/dist/plan/index.d.mts +1 -1
- package/dist/plan/index.mjs +2 -2
- package/dist/plan/is.d.mts +31 -2
- package/dist/plan/is.mjs +45 -1
- package/dist/plan/misc.d.mts +21 -2
- package/dist/plan/misc.mjs +32 -2
- package/dist/plan/models.d.mts +1 -1
- package/dist/plan/result.d.mts +7 -7
- package/dist/plan/result.mjs +6 -6
- package/dist/plan/run.d.mts +5 -5
- package/dist/plan/run.mjs +6 -6
- package/dist/promise/delay.d.mts +1 -1
- package/dist/promise/delay.mjs +2 -1
- package/dist/promise/helpers.d.mts +2 -2
- package/dist/promise/helpers.mjs +6 -6
- package/dist/promise/index.d.mts +2 -2
- package/dist/promise/index.mjs +1 -1
- package/dist/promise/misc.d.mts +3 -3
- package/dist/promise/misc.mjs +7 -4
- package/dist/promise/models.d.mts +2 -106
- package/dist/promise/models.mjs +1 -35
- package/dist/promise/timed.d.mts +2 -2
- package/dist/promise/timed.mjs +3 -3
- package/dist/query.d.mts +1 -1
- package/dist/query.mjs +5 -15
- package/dist/queue.d.mts +6 -200
- package/dist/queue.mjs +9 -34
- package/dist/random.mjs +2 -5
- package/dist/result/match.d.mts +1 -1
- package/dist/result/match.mjs +27 -15
- package/dist/result/misc.d.mts +1 -1
- package/dist/result/work/flow.d.mts +13 -21
- package/dist/result/work/flow.mjs +0 -1
- package/dist/result/work/pipe.d.mts +2 -2
- package/dist/result/work/pipe.mjs +0 -1
- package/dist/string/fuzzy.d.mts +5 -87
- package/dist/string/fuzzy.mjs +6 -11
- package/dist/string/index.mjs +6 -8
- package/dist/string/match.mjs +4 -6
- package/dist/string/normalize.d.mts +4 -40
- package/dist/string/normalize.mjs +9 -48
- package/dist/string/template.d.mts +5 -43
- package/dist/string/template.mjs +1 -2
- package/dist/subscription.d.mts +2 -1
- package/dist/value/clone.d.mts +6 -42
- package/dist/value/clone.mjs +10 -30
- package/dist/value/collection.mjs +2 -0
- package/dist/value/diff.d.mts +3 -44
- package/dist/value/diff.mjs +1 -3
- package/dist/value/freeze.d.mts +1 -5
- package/dist/value/index.d.mts +4 -3
- package/dist/value/merge.d.mts +6 -64
- package/dist/value/merge.mjs +8 -8
- package/dist/value/omit.d.mts +1 -1
- package/dist/value/pick.d.mts +1 -1
- package/dist/value/shake.d.mts +4 -6
- package/dist/value/smush.d.mts +4 -6
- package/dist/value/smush.mjs +2 -2
- package/dist/value/transform.d.mts +6 -22
- package/dist/value/transform.mjs +1 -1
- package/dist/value/unsmush.d.mts +4 -10
- package/package.json +12 -3
- package/dist/internal/plan.d.mts +0 -45
- package/dist/internal/plan.mjs +0 -70
- package/dist/promise/constants.d.mts +0 -17
- package/dist/promise/constants.mjs +0 -15
- /package/dist/{color/models.mjs → models/color.model.mjs} +0 -0
- /package/dist/{internal/models/result.model.mjs → models/index.mjs} +0 -0
- /package/dist/{models.mjs → models/result.model.mjs} +0 -0
package/dist/random.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { getRandomFloatingNumber, getRandomInteger } from "./internal/random.mjs";
|
|
2
2
|
import { shuffle } from "./internal/array/shuffle.mjs";
|
|
3
3
|
import { join } from "./internal/string/misc.mjs";
|
|
4
|
+
import { RANDOM_ALPHABET, RANDOM_BOOLEAN_MODIFIER, RANDOM_HEX_CHARACTERS } from "./models/random.model.mjs";
|
|
4
5
|
//#region src/random.ts
|
|
5
6
|
/**
|
|
6
7
|
* Get a random boolean
|
|
@@ -39,7 +40,7 @@ function getRandomColor(prefix) {
|
|
|
39
40
|
* @returns Random hexadecimal character from `0-9` and `A-F`
|
|
40
41
|
*/
|
|
41
42
|
function getRandomHex() {
|
|
42
|
-
return RANDOM_HEX_CHARACTERS[getRandomInteger(0,
|
|
43
|
+
return RANDOM_HEX_CHARACTERS[getRandomInteger(0, 15)];
|
|
43
44
|
}
|
|
44
45
|
/**
|
|
45
46
|
* Get a random item from an array
|
|
@@ -57,9 +58,5 @@ function getRandomItems(array, amount) {
|
|
|
57
58
|
if (amount === 1) return [array[getRandomInteger(0, array.length - 1)]];
|
|
58
59
|
return typeof amount !== "number" || amount <= 0 || amount >= array.length ? shuffle(array) : shuffle(array).slice(0, amount);
|
|
59
60
|
}
|
|
60
|
-
const RANDOM_ALPHABET = "abcdefghijklmnopqrstuvwxyz";
|
|
61
|
-
const RANDOM_BOOLEAN_MODIFIER = .5;
|
|
62
|
-
const RANDOM_HEX_CHARACTERS = "0123456789ABCDEF";
|
|
63
|
-
const RANDOM_HEX_MAXIMUM = 15;
|
|
64
61
|
//#endregion
|
|
65
62
|
export { getRandomBoolean, getRandomCharacters, getRandomColor, getRandomFloatingNumber as getRandomFloat, getRandomHex, getRandomInteger, getRandomItem, getRandomItems };
|
package/dist/result/match.d.mts
CHANGED
package/dist/result/match.mjs
CHANGED
|
@@ -1,27 +1,39 @@
|
|
|
1
|
+
import { isPlainObject } from "../internal/is.mjs";
|
|
1
2
|
import { isOk, isResult } from "../internal/result/misc.mjs";
|
|
2
3
|
//#region src/result/match.ts
|
|
3
|
-
async function asyncMatchResult(result, first,
|
|
4
|
+
async function asyncMatchResult(result, first, second) {
|
|
4
5
|
let value;
|
|
5
6
|
if (typeof result === "function") value = await result();
|
|
6
7
|
else if (result instanceof Promise) value = await result;
|
|
7
8
|
else value = result;
|
|
8
|
-
if (!isResult(value)) throw new Error(
|
|
9
|
-
|
|
10
|
-
const okHandler = hasObj ? first.ok : first;
|
|
11
|
-
const errorHandler = hasObj ? first.error : error;
|
|
12
|
-
if (isOk(value)) return okHandler(value.value);
|
|
13
|
-
return errorHandler(value.error, value.original);
|
|
9
|
+
if (!isResult(value)) throw new Error(MATCH_MESSAGE_RESULT);
|
|
10
|
+
return handleResult(value, first, second);
|
|
14
11
|
}
|
|
15
|
-
function
|
|
12
|
+
function handleResult(result, first, second) {
|
|
13
|
+
let error;
|
|
14
|
+
let ok;
|
|
15
|
+
if (isPlainObject(first)) {
|
|
16
|
+
ok = first.ok;
|
|
17
|
+
error = first.error;
|
|
18
|
+
} else {
|
|
19
|
+
ok = first;
|
|
20
|
+
error = second;
|
|
21
|
+
}
|
|
22
|
+
if (isOk(result)) {
|
|
23
|
+
if (typeof ok !== "function") throw new Error(MATCH_MESSAGE_OK);
|
|
24
|
+
return ok(result.value);
|
|
25
|
+
}
|
|
26
|
+
if (typeof error !== "function") throw new Error(MATCH_MESSAGE_ERROR);
|
|
27
|
+
return error(result.error, result.original);
|
|
28
|
+
}
|
|
29
|
+
function matchResult(result, first, second) {
|
|
16
30
|
const value = typeof result === "function" ? result() : result;
|
|
17
|
-
if (!isResult(value)) throw new Error(
|
|
18
|
-
|
|
19
|
-
const okHandler = hasObj ? first.ok : first;
|
|
20
|
-
const errorHandler = hasObj ? first.error : error;
|
|
21
|
-
if (isOk(value)) return okHandler(value.value);
|
|
22
|
-
return errorHandler(value.error, value.original);
|
|
31
|
+
if (!isResult(value)) throw new Error(MATCH_MESSAGE_RESULT);
|
|
32
|
+
return handleResult(value, first, second);
|
|
23
33
|
}
|
|
24
|
-
const
|
|
34
|
+
const MATCH_MESSAGE_ERROR = "`result.match` expected an Error callback";
|
|
35
|
+
const MATCH_MESSAGE_OK = "`result.match` expected an Ok callback";
|
|
36
|
+
const MATCH_MESSAGE_RESULT = "`result.match` expected a Result or a function that returns a Result";
|
|
25
37
|
matchResult.async = asyncMatchResult;
|
|
26
38
|
//#endregion
|
|
27
39
|
export { asyncMatchResult, matchResult };
|
package/dist/result/misc.d.mts
CHANGED
|
@@ -1,14 +1,6 @@
|
|
|
1
|
-
import { GenericCallback } from "../../models.mjs";
|
|
2
|
-
import { Result, UnwrapValue } from "../../
|
|
1
|
+
import { GenericCallback } from "../../models/index.mjs";
|
|
2
|
+
import { AttemptAsyncFlow, AttemptFlow, Result, UnwrapValue } from "../../models/result.model.mjs";
|
|
3
3
|
//#region src/result/work/flow.d.ts
|
|
4
|
-
/**
|
|
5
|
-
* A synchronous _Flow_, a function that attempts to pipe values through a series of functions
|
|
6
|
-
*/
|
|
7
|
-
export type AttemptFlow<Callback extends GenericCallback, Value> = (...args: Parameters<Callback>) => Result<UnwrapValue<Value>>;
|
|
8
|
-
/**
|
|
9
|
-
* An asynchronous _Flow_, a function that attempts to pipe values through a series of functions
|
|
10
|
-
*/
|
|
11
|
-
export type AttemptFlowPromise<Callback extends GenericCallback, Value> = (...args: Parameters<Callback>) => Promise<Result<UnwrapValue<Value>>>;
|
|
12
4
|
/**
|
|
13
5
|
* Create an asynchronous _Flow_, a function that attempts to pipe a value through a series of functions
|
|
14
6
|
*
|
|
@@ -16,7 +8,7 @@ export type AttemptFlowPromise<Callback extends GenericCallback, Value> = (...ar
|
|
|
16
8
|
*
|
|
17
9
|
* @returns _Flow_ function
|
|
18
10
|
*/
|
|
19
|
-
export declare function attemptAsyncFlow<Fn extends GenericCallback>(fn: Fn):
|
|
11
|
+
export declare function attemptAsyncFlow<Fn extends GenericCallback>(fn: Fn): AttemptAsyncFlow<Fn, ReturnType<Fn>>;
|
|
20
12
|
/**
|
|
21
13
|
* Create an asynchronous _Flow_, a function that pipes values through a series of functions
|
|
22
14
|
*
|
|
@@ -24,7 +16,7 @@ export declare function attemptAsyncFlow<Fn extends GenericCallback>(fn: Fn): At
|
|
|
24
16
|
*
|
|
25
17
|
* @returns _Flow_ function
|
|
26
18
|
*/
|
|
27
|
-
export declare function attemptAsyncFlow<First extends GenericCallback, Second>(first: First, second: (value: Awaited<UnwrapValue<ReturnType<First>>>) => Second):
|
|
19
|
+
export declare function attemptAsyncFlow<First extends GenericCallback, Second>(first: First, second: (value: Awaited<UnwrapValue<ReturnType<First>>>) => Second): AttemptAsyncFlow<First, Second>;
|
|
28
20
|
/**
|
|
29
21
|
* Create an asynchronous _Flow_, a function that pipes values through a series of functions
|
|
30
22
|
*
|
|
@@ -32,7 +24,7 @@ export declare function attemptAsyncFlow<First extends GenericCallback, Second>(
|
|
|
32
24
|
*
|
|
33
25
|
* @returns _Flow_ function
|
|
34
26
|
*/
|
|
35
|
-
export declare function attemptAsyncFlow<First extends GenericCallback, Second, Third>(first: First, second: (value: Awaited<UnwrapValue<ReturnType<First>>>) => Second, third: (value: Awaited<UnwrapValue<Second>>) => Third):
|
|
27
|
+
export declare function attemptAsyncFlow<First extends GenericCallback, Second, Third>(first: First, second: (value: Awaited<UnwrapValue<ReturnType<First>>>) => Second, third: (value: Awaited<UnwrapValue<Second>>) => Third): AttemptAsyncFlow<First, Third>;
|
|
36
28
|
/**
|
|
37
29
|
* Create an asynchronous _Flow_, a function that pipes values through a series of functions
|
|
38
30
|
*
|
|
@@ -40,7 +32,7 @@ export declare function attemptAsyncFlow<First extends GenericCallback, Second,
|
|
|
40
32
|
*
|
|
41
33
|
* @returns _Flow_ function
|
|
42
34
|
*/
|
|
43
|
-
export declare function attemptAsyncFlow<First extends GenericCallback, Second, Third, Fourth>(first: First, second: (value: Awaited<UnwrapValue<ReturnType<First>>>) => Second, third: (value: Awaited<UnwrapValue<Second>>) => Third, fourth: (value: Awaited<UnwrapValue<Third>>) => Fourth):
|
|
35
|
+
export declare function attemptAsyncFlow<First extends GenericCallback, Second, Third, Fourth>(first: First, second: (value: Awaited<UnwrapValue<ReturnType<First>>>) => Second, third: (value: Awaited<UnwrapValue<Second>>) => Third, fourth: (value: Awaited<UnwrapValue<Third>>) => Fourth): AttemptAsyncFlow<First, Fourth>;
|
|
44
36
|
/**
|
|
45
37
|
* Create an asynchronous _Flow_, a function that pipes values through a series of functions
|
|
46
38
|
*
|
|
@@ -48,7 +40,7 @@ export declare function attemptAsyncFlow<First extends GenericCallback, Second,
|
|
|
48
40
|
*
|
|
49
41
|
* @returns _Flow_ function
|
|
50
42
|
*/
|
|
51
|
-
export declare function attemptAsyncFlow<First extends GenericCallback, Second, Third, Fourth, Fifth>(first: First, second: (value: Awaited<UnwrapValue<ReturnType<First>>>) => Second, third: (value: Awaited<UnwrapValue<Second>>) => Third, fourth: (value: Awaited<UnwrapValue<Third>>) => Fourth, fifth: (value: Awaited<UnwrapValue<Fourth>>) => Fifth):
|
|
43
|
+
export declare function attemptAsyncFlow<First extends GenericCallback, Second, Third, Fourth, Fifth>(first: First, second: (value: Awaited<UnwrapValue<ReturnType<First>>>) => Second, third: (value: Awaited<UnwrapValue<Second>>) => Third, fourth: (value: Awaited<UnwrapValue<Third>>) => Fourth, fifth: (value: Awaited<UnwrapValue<Fourth>>) => Fifth): AttemptAsyncFlow<First, Fifth>;
|
|
52
44
|
/**
|
|
53
45
|
* Create an asynchronous _Flow_, a function that pipes values through a series of functions
|
|
54
46
|
*
|
|
@@ -56,7 +48,7 @@ export declare function attemptAsyncFlow<First extends GenericCallback, Second,
|
|
|
56
48
|
*
|
|
57
49
|
* @returns _Flow_ function
|
|
58
50
|
*/
|
|
59
|
-
export declare function attemptAsyncFlow<First extends GenericCallback, Second, Third, Fourth, Fifth, Sixth>(first: First, second: (value: Awaited<UnwrapValue<ReturnType<First>>>) => Second, third: (value: Awaited<UnwrapValue<Second>>) => Third, fourth: (value: Awaited<UnwrapValue<Third>>) => Fourth, fifth: (value: Awaited<UnwrapValue<Fourth>>) => Fifth, sixth: (value: Awaited<UnwrapValue<Fifth>>) => Sixth):
|
|
51
|
+
export declare function attemptAsyncFlow<First extends GenericCallback, Second, Third, Fourth, Fifth, Sixth>(first: First, second: (value: Awaited<UnwrapValue<ReturnType<First>>>) => Second, third: (value: Awaited<UnwrapValue<Second>>) => Third, fourth: (value: Awaited<UnwrapValue<Third>>) => Fourth, fifth: (value: Awaited<UnwrapValue<Fourth>>) => Fifth, sixth: (value: Awaited<UnwrapValue<Fifth>>) => Sixth): AttemptAsyncFlow<First, Sixth>;
|
|
60
52
|
/**
|
|
61
53
|
* Create an asynchronous _Flow_, a function that pipes values through a series of functions
|
|
62
54
|
*
|
|
@@ -64,7 +56,7 @@ export declare function attemptAsyncFlow<First extends GenericCallback, Second,
|
|
|
64
56
|
*
|
|
65
57
|
* @returns _Flow_ function
|
|
66
58
|
*/
|
|
67
|
-
export declare function attemptAsyncFlow<First extends GenericCallback, Second, Third, Fourth, Fifth, Sixth, Seventh>(first: First, second: (value: Awaited<UnwrapValue<ReturnType<First>>>) => Second, third: (value: Awaited<UnwrapValue<Second>>) => Third, fourth: (value: Awaited<UnwrapValue<Third>>) => Fourth, fifth: (value: Awaited<UnwrapValue<Fourth>>) => Fifth, sixth: (value: Awaited<UnwrapValue<Fifth>>) => Sixth, seventh: (value: Awaited<UnwrapValue<Sixth>>) => Seventh):
|
|
59
|
+
export declare function attemptAsyncFlow<First extends GenericCallback, Second, Third, Fourth, Fifth, Sixth, Seventh>(first: First, second: (value: Awaited<UnwrapValue<ReturnType<First>>>) => Second, third: (value: Awaited<UnwrapValue<Second>>) => Third, fourth: (value: Awaited<UnwrapValue<Third>>) => Fourth, fifth: (value: Awaited<UnwrapValue<Fourth>>) => Fifth, sixth: (value: Awaited<UnwrapValue<Fifth>>) => Sixth, seventh: (value: Awaited<UnwrapValue<Sixth>>) => Seventh): AttemptAsyncFlow<First, Seventh>;
|
|
68
60
|
/**
|
|
69
61
|
* Create an asynchronous _Flow_, a function that pipes values through a series of functions
|
|
70
62
|
*
|
|
@@ -72,7 +64,7 @@ export declare function attemptAsyncFlow<First extends GenericCallback, Second,
|
|
|
72
64
|
*
|
|
73
65
|
* @returns _Flow_ function
|
|
74
66
|
*/
|
|
75
|
-
export declare function attemptAsyncFlow<First extends GenericCallback, Second, Third, Fourth, Fifth, Sixth, Seventh, Eighth>(first: First, second: (value: Awaited<UnwrapValue<ReturnType<First>>>) => Second, third: (value: Awaited<UnwrapValue<Second>>) => Third, fourth: (value: Awaited<UnwrapValue<Third>>) => Fourth, fifth: (value: Awaited<UnwrapValue<Fourth>>) => Fifth, sixth: (value: Awaited<UnwrapValue<Fifth>>) => Sixth, seventh: (value: Awaited<UnwrapValue<Sixth>>) => Seventh, eighth: (value: Awaited<UnwrapValue<Seventh>>) => Eighth):
|
|
67
|
+
export declare function attemptAsyncFlow<First extends GenericCallback, Second, Third, Fourth, Fifth, Sixth, Seventh, Eighth>(first: First, second: (value: Awaited<UnwrapValue<ReturnType<First>>>) => Second, third: (value: Awaited<UnwrapValue<Second>>) => Third, fourth: (value: Awaited<UnwrapValue<Third>>) => Fourth, fifth: (value: Awaited<UnwrapValue<Fourth>>) => Fifth, sixth: (value: Awaited<UnwrapValue<Fifth>>) => Sixth, seventh: (value: Awaited<UnwrapValue<Sixth>>) => Seventh, eighth: (value: Awaited<UnwrapValue<Seventh>>) => Eighth): AttemptAsyncFlow<First, Eighth>;
|
|
76
68
|
/**
|
|
77
69
|
* Create an asynchronous _Flow_, a function that pipes values through a series of functions
|
|
78
70
|
*
|
|
@@ -80,7 +72,7 @@ export declare function attemptAsyncFlow<First extends GenericCallback, Second,
|
|
|
80
72
|
*
|
|
81
73
|
* @returns _Flow_ function
|
|
82
74
|
*/
|
|
83
|
-
export declare function attemptAsyncFlow<First extends GenericCallback, Second, Third, Fourth, Fifth, Sixth, Seventh, Eighth, Ninth>(first: First, second: (value: Awaited<UnwrapValue<ReturnType<First>>>) => Second, third: (value: Awaited<UnwrapValue<Second>>) => Third, fourth: (value: Awaited<UnwrapValue<Third>>) => Fourth, fifth: (value: Awaited<UnwrapValue<Fourth>>) => Fifth, sixth: (value: Awaited<UnwrapValue<Fifth>>) => Sixth, seventh: (value: Awaited<UnwrapValue<Sixth>>) => Seventh, eighth: (value: Awaited<UnwrapValue<Seventh>>) => Eighth, ninth: (value: Awaited<UnwrapValue<Eighth>>) => Ninth):
|
|
75
|
+
export declare function attemptAsyncFlow<First extends GenericCallback, Second, Third, Fourth, Fifth, Sixth, Seventh, Eighth, Ninth>(first: First, second: (value: Awaited<UnwrapValue<ReturnType<First>>>) => Second, third: (value: Awaited<UnwrapValue<Second>>) => Third, fourth: (value: Awaited<UnwrapValue<Third>>) => Fourth, fifth: (value: Awaited<UnwrapValue<Fourth>>) => Fifth, sixth: (value: Awaited<UnwrapValue<Fifth>>) => Sixth, seventh: (value: Awaited<UnwrapValue<Sixth>>) => Seventh, eighth: (value: Awaited<UnwrapValue<Seventh>>) => Eighth, ninth: (value: Awaited<UnwrapValue<Eighth>>) => Ninth): AttemptAsyncFlow<First, Ninth>;
|
|
84
76
|
/**
|
|
85
77
|
* Create an asynchronous _Flow_, a function that pipes values through a series of functions
|
|
86
78
|
*
|
|
@@ -88,7 +80,7 @@ export declare function attemptAsyncFlow<First extends GenericCallback, Second,
|
|
|
88
80
|
*
|
|
89
81
|
* @returns _Flow_ function
|
|
90
82
|
*/
|
|
91
|
-
export declare function attemptAsyncFlow<First extends GenericCallback, Second, Third, Fourth, Fifth, Sixth, Seventh, Eighth, Ninth, Tenth>(first: First, second: (value: Awaited<UnwrapValue<ReturnType<First>>>) => Second, third: (value: Awaited<UnwrapValue<Second>>) => Third, fourth: (value: Awaited<UnwrapValue<Third>>) => Fourth, fifth: (value: Awaited<UnwrapValue<Fourth>>) => Fifth, sixth: (value: Awaited<UnwrapValue<Fifth>>) => Sixth, seventh: (value: Awaited<UnwrapValue<Sixth>>) => Seventh, eighth: (value: Awaited<UnwrapValue<Seventh>>) => Eighth, ninth: (value: Awaited<UnwrapValue<Eighth>>) => Ninth, tenth: (value: Awaited<UnwrapValue<Ninth>>) => Tenth):
|
|
83
|
+
export declare function attemptAsyncFlow<First extends GenericCallback, Second, Third, Fourth, Fifth, Sixth, Seventh, Eighth, Ninth, Tenth>(first: First, second: (value: Awaited<UnwrapValue<ReturnType<First>>>) => Second, third: (value: Awaited<UnwrapValue<Second>>) => Third, fourth: (value: Awaited<UnwrapValue<Third>>) => Fourth, fifth: (value: Awaited<UnwrapValue<Fourth>>) => Fifth, sixth: (value: Awaited<UnwrapValue<Fifth>>) => Sixth, seventh: (value: Awaited<UnwrapValue<Sixth>>) => Seventh, eighth: (value: Awaited<UnwrapValue<Seventh>>) => Eighth, ninth: (value: Awaited<UnwrapValue<Eighth>>) => Ninth, tenth: (value: Awaited<UnwrapValue<Ninth>>) => Tenth): AttemptAsyncFlow<First, Tenth>;
|
|
92
84
|
/**
|
|
93
85
|
* Create an asynchronous _Flow_, a function that pipes values through a series of functions
|
|
94
86
|
*
|
|
@@ -96,7 +88,7 @@ export declare function attemptAsyncFlow<First extends GenericCallback, Second,
|
|
|
96
88
|
*
|
|
97
89
|
* @returns _Flow_ function
|
|
98
90
|
*/
|
|
99
|
-
export declare function attemptAsyncFlow<Fn extends GenericCallback>(fn: Fn, ...fns: Array<(value: Awaited<UnwrapValue<ReturnType<Fn>>>) => unknown>):
|
|
91
|
+
export declare function attemptAsyncFlow<Fn extends GenericCallback>(fn: Fn, ...fns: Array<(value: Awaited<UnwrapValue<ReturnType<Fn>>>) => unknown>): AttemptAsyncFlow<Fn, ReturnType<Fn>>;
|
|
100
92
|
/**
|
|
101
93
|
* Create an asynchronous _Flow_, a function that pipes values through a series of functions
|
|
102
94
|
*
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { isError, isOk } from "../../internal/result/misc.mjs";
|
|
2
2
|
import { asyncAttempt, attempt } from "../../internal/result/attempt.mjs";
|
|
3
3
|
import { asyncFlow, flow } from "../../internal/function/work.mjs";
|
|
4
|
-
import "../index.mjs";
|
|
5
4
|
//#region src/result/work/flow.ts
|
|
6
5
|
function attemptAsyncFlow(...fns) {
|
|
7
6
|
let Flow;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { GenericCallback } from "../../models.mjs";
|
|
2
|
-
import { Result, UnwrapValue } from "../../
|
|
1
|
+
import { GenericCallback } from "../../models/index.mjs";
|
|
2
|
+
import { Result, UnwrapValue } from "../../models/result.model.mjs";
|
|
3
3
|
//#region src/result/work/pipe.d.ts
|
|
4
4
|
type WrapValue<Value> = Result<UnwrapValue<Value>>;
|
|
5
5
|
/**
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { isError, isOk } from "../../internal/result/misc.mjs";
|
|
2
2
|
import { asyncAttempt, attempt } from "../../internal/result/attempt.mjs";
|
|
3
3
|
import { asyncPipe, pipe } from "../../internal/function/work.mjs";
|
|
4
|
-
import "../index.mjs";
|
|
5
4
|
//#region src/result/work/pipe.ts
|
|
6
5
|
async function attemptAsyncPipe(initial, first, ...seconds) {
|
|
7
6
|
return asyncAttempt(() => {
|
package/dist/string/fuzzy.d.mts
CHANGED
|
@@ -1,90 +1,7 @@
|
|
|
1
|
-
import { PlainObject } from "../models.mjs";
|
|
1
|
+
import { PlainObject } from "../models/index.mjs";
|
|
2
|
+
import { Fuzzy, FuzzyConfiguration, FuzzyItem, FuzzyOptions, FuzzyResult, FuzzyState } from "../models/string/string.fuzzy.model.mjs";
|
|
2
3
|
//#region src/string/fuzzy.d.ts
|
|
3
|
-
|
|
4
|
-
* Fuzzy searcher for an array of items
|
|
5
|
-
*/
|
|
6
|
-
export type Fuzzy<Item> = {
|
|
7
|
-
/**
|
|
8
|
-
* Get items currently being searched through
|
|
9
|
-
*
|
|
10
|
-
* @returns Original items
|
|
11
|
-
*/
|
|
12
|
-
get items(): Item[];
|
|
13
|
-
/**
|
|
14
|
-
* Set new items to search through
|
|
15
|
-
*
|
|
16
|
-
* @param items New items to search through
|
|
17
|
-
*/
|
|
18
|
-
set items(items: Item[]);
|
|
19
|
-
/**
|
|
20
|
-
* Get strings currently being searched through _(the stringified version of `items`)_
|
|
21
|
-
*
|
|
22
|
-
* @returns Stringified items
|
|
23
|
-
*/
|
|
24
|
-
get strings(): string[];
|
|
25
|
-
/**
|
|
26
|
-
* Search for items matching the given value
|
|
27
|
-
*
|
|
28
|
-
* @param value Value to search for
|
|
29
|
-
* @param options Search options
|
|
30
|
-
* @returns Search results, with exact matches _(ordered)_ and similar matches _(ordered by relevance)_
|
|
31
|
-
*/
|
|
32
|
-
search(value: string, options?: FuzzyOptions): FuzzyResult<Item>;
|
|
33
|
-
/**
|
|
34
|
-
* Search for items matching the given value
|
|
35
|
-
*
|
|
36
|
-
* @param value Value to search for
|
|
37
|
-
* @param limit Maximum number of combined items to return in `exact` and `similar`
|
|
38
|
-
* @returns Search results, with exact matches _(ordered)_ and similar matches _(ordered by relevance)_
|
|
39
|
-
*/
|
|
40
|
-
search(value: string, limit: number): FuzzyResult<Item>;
|
|
41
|
-
};
|
|
42
|
-
export type FuzzyConfiguration<Item> = {
|
|
43
|
-
/**
|
|
44
|
-
* Handler to stringify items
|
|
45
|
-
*
|
|
46
|
-
* - May be a function that takes an item and returns a string, or if items are plain objects, a key of the item to use to grab a string value from
|
|
47
|
-
* - Defaults to `getString`
|
|
48
|
-
*/
|
|
49
|
-
handler?: (item: Item) => string;
|
|
50
|
-
} & (Item extends PlainObject ? {
|
|
51
|
-
/**
|
|
52
|
-
* Key to use to stringify items
|
|
53
|
-
*
|
|
54
|
-
* _Prioritized over `handler`_
|
|
55
|
-
*/
|
|
56
|
-
key?: keyof Item;
|
|
57
|
-
} : {}) & FuzzyOptions;
|
|
58
|
-
export type FuzzyOptions = {
|
|
59
|
-
/**
|
|
60
|
-
* Maximum number of combined items to return in `exact` and `similar` _(defaults to all matches)_
|
|
61
|
-
*/
|
|
62
|
-
limit?: number;
|
|
63
|
-
/**
|
|
64
|
-
* Maximum score difference between the best and worst similar matches included in results
|
|
65
|
-
*
|
|
66
|
-
* - Higher values cast a wider net
|
|
67
|
-
* - Defaults to `5`
|
|
68
|
-
*/
|
|
69
|
-
tolerance?: number;
|
|
70
|
-
};
|
|
71
|
-
/**
|
|
72
|
-
* Search results from a fuzzy search, with exact and similar matches
|
|
73
|
-
*/
|
|
74
|
-
export type FuzzyResult<Item> = {
|
|
75
|
-
/**
|
|
76
|
-
* Ordered items that exactly match the search value
|
|
77
|
-
*/
|
|
78
|
-
exact: Item[];
|
|
79
|
-
/**
|
|
80
|
-
* Ordered items that are similar to the search value, ranked by relevance
|
|
81
|
-
*/
|
|
82
|
-
similar: Item[];
|
|
83
|
-
};
|
|
84
|
-
/**
|
|
85
|
-
* Options for fuzzy searching
|
|
86
|
-
*/
|
|
87
|
-
export type FuzzySearchOptions = FuzzyOptions;
|
|
4
|
+
declare function Fuzzy(this: any, state: FuzzyState<unknown>): void;
|
|
88
5
|
/**
|
|
89
6
|
* Create a fuzzy searcher for an array of items
|
|
90
7
|
*
|
|
@@ -132,4 +49,5 @@ export declare namespace fuzzy {
|
|
|
132
49
|
export var is: typeof isFuzzy;
|
|
133
50
|
export var match: typeof fuzzyMatch;
|
|
134
51
|
}
|
|
135
|
-
//#endregion
|
|
52
|
+
//#endregion
|
|
53
|
+
export type { Fuzzy, FuzzyItem, FuzzyOptions, FuzzyResult };
|
package/dist/string/fuzzy.mjs
CHANGED
|
@@ -3,10 +3,9 @@ import { floor } from "../internal/math/misc.mjs";
|
|
|
3
3
|
import { max } from "../internal/math/aggregate.mjs";
|
|
4
4
|
import { getString } from "../internal/string/misc.mjs";
|
|
5
5
|
import { lowerCase } from "../internal/string/case.mjs";
|
|
6
|
+
import { FUZZY_MESSAGE_ARRAY, FUZZY_MESSAGE_HANDLER, FUZZY_PROPERTY, FUZZY_SYMBOL } from "../models/string/string.fuzzy.model.mjs";
|
|
6
7
|
import { includes } from "./match.mjs";
|
|
7
8
|
//#region src/string/fuzzy.ts
|
|
8
|
-
const FUZZY_PROPERTY = "$fuzzy";
|
|
9
|
-
const FUZZY_SYMBOL = Symbol(FUZZY_PROPERTY);
|
|
10
9
|
function Fuzzy(state) {
|
|
11
10
|
this[FUZZY_SYMBOL] = state;
|
|
12
11
|
}
|
|
@@ -94,19 +93,19 @@ function getScore(haystack, needle) {
|
|
|
94
93
|
if (haystackIndex === 0) score += 1;
|
|
95
94
|
if (previousMatchIndex !== -1) {
|
|
96
95
|
const gap = haystackIndex - previousMatchIndex - 1;
|
|
97
|
-
score += max([0,
|
|
96
|
+
score += max([0, 5 - gap]);
|
|
98
97
|
}
|
|
99
98
|
previousMatchIndex = haystackIndex;
|
|
100
99
|
needleIndex += 1;
|
|
101
100
|
}
|
|
102
101
|
if (needleIndex === needleLength) break;
|
|
103
102
|
}
|
|
104
|
-
score -= floor(lowerCaseHaystack.length /
|
|
103
|
+
score -= floor(lowerCaseHaystack.length / 3);
|
|
105
104
|
return max([0, score]);
|
|
106
105
|
}
|
|
107
106
|
function getTolerance(input, state) {
|
|
108
107
|
if (typeof input === "number" && !Number.isNaN(input)) return input < 0 ? 0 : floor(input);
|
|
109
|
-
return state?.tolerance ??
|
|
108
|
+
return state?.tolerance ?? 5;
|
|
110
109
|
}
|
|
111
110
|
/**
|
|
112
111
|
* Is the value a fuzzy searcher?
|
|
@@ -117,7 +116,7 @@ function getTolerance(input, state) {
|
|
|
117
116
|
* @returns `true` if the value is a fuzzy searcher, otherwise `false`
|
|
118
117
|
*/
|
|
119
118
|
function isFuzzy(value) {
|
|
120
|
-
return typeof value === "object" && value !== null &&
|
|
119
|
+
return typeof value === "object" && value !== null && "$fuzzy" in value && value["$fuzzy"] === true;
|
|
121
120
|
}
|
|
122
121
|
function isSubsequence(haystack, needle) {
|
|
123
122
|
const lowerCaseHaystack = lowerCase(haystack);
|
|
@@ -185,12 +184,8 @@ function setFuzzyItems(value) {
|
|
|
185
184
|
if (!Array.isArray(value)) throw new TypeError(FUZZY_MESSAGE_ARRAY);
|
|
186
185
|
const state = this[FUZZY_SYMBOL];
|
|
187
186
|
state.items = value.slice();
|
|
188
|
-
state.strings = value.map(state.handler);
|
|
187
|
+
state.strings = value.map((item) => state.handler(item));
|
|
189
188
|
}
|
|
190
|
-
const FUZZY_LENGTH_DIVISOR = 3;
|
|
191
|
-
const FUZZY_MESSAGE_ARRAY = "Fuzzy requires an array of items";
|
|
192
|
-
const FUZZY_MESSAGE_HANDLER = "Fuzzy requires a key or function to stringify items";
|
|
193
|
-
const FUZZY_PROXIMITY_THRESHOLD = 5;
|
|
194
189
|
fuzzy.is = isFuzzy;
|
|
195
190
|
fuzzy.match = fuzzyMatch;
|
|
196
191
|
//#endregion
|
package/dist/string/index.mjs
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { isTemplateStringsArray } from "../internal/is.mjs";
|
|
2
2
|
import { min } from "../internal/math/aggregate.mjs";
|
|
3
|
+
import { STRING_EXPRESSION_WHITESPACE_PREFIX } from "../models/string/string.misc.model.mjs";
|
|
3
4
|
import { getString, interpolate, join, words } from "../internal/string/misc.mjs";
|
|
5
|
+
import { EXPRESSION_NUMERICAL_PREFIX } from "../models/misc.model.mjs";
|
|
4
6
|
//#region src/string/index.ts
|
|
5
7
|
function dedent(value, ...values) {
|
|
6
8
|
let actual;
|
|
@@ -13,7 +15,7 @@ function dedent(value, ...values) {
|
|
|
13
15
|
const lastIndex = length - 1;
|
|
14
16
|
const lengths = [];
|
|
15
17
|
for (let index = 0; index < length; index += 1) {
|
|
16
|
-
const [, indentation] =
|
|
18
|
+
const [, indentation] = STRING_EXPRESSION_WHITESPACE_PREFIX.exec(lines[index]) ?? [];
|
|
17
19
|
if (indentation != null) lengths.push(indentation.length);
|
|
18
20
|
}
|
|
19
21
|
if (lengths.length === 0) return actual.trim();
|
|
@@ -38,16 +40,16 @@ function getUuid(html) {
|
|
|
38
40
|
crypto.getRandomValues(bytes);
|
|
39
41
|
bytes[6] = bytes[6] & 15 | 64;
|
|
40
42
|
bytes[8] = bytes[8] & 63 | 128;
|
|
41
|
-
const hex = Array.from(bytes, (byte) => byte.toString(16).padStart(2,
|
|
43
|
+
const hex = Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
42
44
|
const first = hex.substring(0, 8);
|
|
43
|
-
if (forHTML &&
|
|
45
|
+
if (forHTML && EXPRESSION_NUMERICAL_PREFIX.test(first)) continue;
|
|
44
46
|
return [
|
|
45
47
|
first,
|
|
46
48
|
hex.substring(8, 12),
|
|
47
49
|
hex.substring(12, 16),
|
|
48
50
|
hex.substring(16, 20),
|
|
49
51
|
hex.substring(20, 32)
|
|
50
|
-
].join(forHTML ?
|
|
52
|
+
].join(forHTML ? "_" : "-");
|
|
51
53
|
}
|
|
52
54
|
}
|
|
53
55
|
/**
|
|
@@ -90,9 +92,5 @@ function truncate(value, length, suffix) {
|
|
|
90
92
|
const truncatedLength = length - actualSuffixLength;
|
|
91
93
|
return `${value.slice(0, truncatedLength)}${actualSuffix}`;
|
|
92
94
|
}
|
|
93
|
-
const STRING_DELIMITER_UUID_DEFAULT = "-";
|
|
94
|
-
const STRING_DELIMITER_UUID_HTML = "_";
|
|
95
|
-
const STRING_NUMERICAL_PREFIX_PATTERN = /^\d/;
|
|
96
|
-
const STRING_ZERO = "0";
|
|
97
95
|
//#endregion
|
|
98
96
|
export { dedent, getString, getUuid, join, parse, trim, truncate, words };
|
package/dist/string/match.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { STRING_MATCH_ENDS_WITH, STRING_MATCH_INCLUDES, STRING_MATCH_STARTS_WITH } from "../models/string/string.misc.model.mjs";
|
|
1
2
|
import { memoize } from "../internal/function/memoize.mjs";
|
|
2
3
|
//#region src/string/match.ts
|
|
3
4
|
/**
|
|
@@ -9,7 +10,7 @@ import { memoize } from "../internal/function/memoize.mjs";
|
|
|
9
10
|
* @returns `true` if the string ends with the given substring, otherwise `false`
|
|
10
11
|
*/
|
|
11
12
|
function endsWith(haystack, needle, ignoreCase) {
|
|
12
|
-
return match(
|
|
13
|
+
return match(STRING_MATCH_ENDS_WITH, haystack, needle, ignoreCase === true);
|
|
13
14
|
}
|
|
14
15
|
/**
|
|
15
16
|
* Check if a string includes a specified substring
|
|
@@ -20,7 +21,7 @@ function endsWith(haystack, needle, ignoreCase) {
|
|
|
20
21
|
* @returns `true` if the string includes the given substring, otherwise `false`
|
|
21
22
|
*/
|
|
22
23
|
function includes(haystack, needle, ignoreCase) {
|
|
23
|
-
return match(
|
|
24
|
+
return match(STRING_MATCH_INCLUDES, haystack, needle, ignoreCase === true);
|
|
24
25
|
}
|
|
25
26
|
function match(type, haystack, needle, ignoreCase) {
|
|
26
27
|
if (typeof haystack !== "string" || typeof needle !== "string") return false;
|
|
@@ -39,11 +40,8 @@ function matchCallback(haystack, needle, ignoreCase) {
|
|
|
39
40
|
* @returns `true` if the string starts with the given substring, otherwise `false`
|
|
40
41
|
*/
|
|
41
42
|
function startsWith(haystack, needle, ignoreCase) {
|
|
42
|
-
return match(
|
|
43
|
+
return match(STRING_MATCH_STARTS_WITH, haystack, needle, ignoreCase === true);
|
|
43
44
|
}
|
|
44
|
-
const MATCH_ENDS_WITH = "endsWith";
|
|
45
|
-
const MATCH_INCLUDES = "includes";
|
|
46
|
-
const MATCH_STARTS_WITH = "startsWith";
|
|
47
45
|
const matchMemoizers = {};
|
|
48
46
|
//#endregion
|
|
49
47
|
export { endsWith, includes, startsWith };
|
|
@@ -1,43 +1,6 @@
|
|
|
1
|
+
import { NormalizeOptions, Normalizer, NormalizerOptions } from "../models/string/string.normalize.model.mjs";
|
|
1
2
|
//#region src/string/normalize.d.ts
|
|
2
|
-
|
|
3
|
-
* Options for normalizing a string
|
|
4
|
-
*/
|
|
5
|
-
export type NormalizeOptions = {
|
|
6
|
-
/**
|
|
7
|
-
* Remove diacritical marks from the string? _(defaults to `true`)_
|
|
8
|
-
*/
|
|
9
|
-
deburr?: boolean;
|
|
10
|
-
/**
|
|
11
|
-
* Convert the string to lower case? _(defaults to `true`)_
|
|
12
|
-
*/
|
|
13
|
-
lowerCase?: boolean;
|
|
14
|
-
/**
|
|
15
|
-
* Remove special characters from the string? _(defaults to `false`)_
|
|
16
|
-
*
|
|
17
|
-
* _(Punctuation and symbol characters are considered special)_
|
|
18
|
-
*/
|
|
19
|
-
special?: boolean;
|
|
20
|
-
/**
|
|
21
|
-
* Trim the string? _(defaults to `true`)_
|
|
22
|
-
*/
|
|
23
|
-
trim?: boolean;
|
|
24
|
-
/**
|
|
25
|
-
* Shorten consecutive whitespace characters to a single space? _(defaults to `true`)_
|
|
26
|
-
*/
|
|
27
|
-
whitespace?: boolean;
|
|
28
|
-
};
|
|
29
|
-
/**
|
|
30
|
-
* String normalizer function
|
|
31
|
-
*/
|
|
32
|
-
export type Normalizer = {
|
|
33
|
-
/**
|
|
34
|
-
* Normalize a string
|
|
35
|
-
*
|
|
36
|
-
* @param value String to normalize
|
|
37
|
-
* @returns Normalized string
|
|
38
|
-
*/
|
|
39
|
-
normalize(value: string): string;
|
|
40
|
-
};
|
|
3
|
+
declare function Normalizer(this: any, options: NormalizerOptions): void;
|
|
41
4
|
/**
|
|
42
5
|
* Deburr a string, removing diacritical marks
|
|
43
6
|
*
|
|
@@ -67,4 +30,5 @@ export declare function normalize(value: string, options?: NormalizeOptions): st
|
|
|
67
30
|
export declare namespace normalize {
|
|
68
31
|
export var initialize: typeof initializeNormalizer;
|
|
69
32
|
}
|
|
70
|
-
//#endregion
|
|
33
|
+
//#endregion
|
|
34
|
+
export type { NormalizeOptions, Normalizer };
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { isPlainObject } from "../internal/is.mjs";
|
|
2
|
+
import { EXPRESSION_WHITESPACE_MULTIPLE } from "../models/misc.model.mjs";
|
|
2
3
|
import { memoize } from "../internal/function/memoize.mjs";
|
|
3
4
|
import { lowerCase } from "../internal/string/case.mjs";
|
|
5
|
+
import { NORMALIZE_DEBURR_CHARACTERS, NORMALIZE_DEBURR_PATTERN_CHARACTERS, NORMALIZE_DEBURR_PATTERN_SIMPLE, NORMALIZE_SPECIAL_PATTERN, NORMALIZE_SYMBOL } from "../models/string/string.normalize.model.mjs";
|
|
4
6
|
//#region src/string/normalize.ts
|
|
5
7
|
function Normalizer(options) {
|
|
6
8
|
this[NORMALIZE_SYMBOL] = options;
|
|
7
9
|
}
|
|
8
10
|
Normalizer.prototype.normalize = normalizeString;
|
|
9
|
-
function
|
|
11
|
+
function createNormalizerOptions(input) {
|
|
10
12
|
const options = isPlainObject(input) ? input : {};
|
|
11
13
|
return {
|
|
12
14
|
deburr: options.deburr !== false,
|
|
@@ -25,7 +27,7 @@ function createNormalizeOptions(input) {
|
|
|
25
27
|
function deburr(value) {
|
|
26
28
|
if (typeof value !== "string") return "";
|
|
27
29
|
deburrMemoizer ??= memoize((value) => {
|
|
28
|
-
let deburred = value.normalize(
|
|
30
|
+
let deburred = value.normalize("NFD").replace(NORMALIZE_DEBURR_PATTERN_SIMPLE, "");
|
|
29
31
|
deburred = deburred.replace(NORMALIZE_DEBURR_PATTERN_CHARACTERS, (_, character) => NORMALIZE_DEBURR_CHARACTERS[character]);
|
|
30
32
|
return deburred;
|
|
31
33
|
});
|
|
@@ -40,7 +42,7 @@ function deburr(value) {
|
|
|
40
42
|
* @returns Normalizer function
|
|
41
43
|
*/
|
|
42
44
|
function initializeNormalizer(options) {
|
|
43
|
-
return new Normalizer(
|
|
45
|
+
return new Normalizer(createNormalizerOptions(options));
|
|
44
46
|
}
|
|
45
47
|
/**
|
|
46
48
|
* Normalize a string
|
|
@@ -52,60 +54,19 @@ function initializeNormalizer(options) {
|
|
|
52
54
|
* @returns Normalized string
|
|
53
55
|
*/
|
|
54
56
|
function normalize(value, options) {
|
|
55
|
-
return normalizeString.call(
|
|
57
|
+
return normalizeString.call(createNormalizerOptions(options), value);
|
|
56
58
|
}
|
|
57
59
|
function normalizeString(value) {
|
|
58
60
|
if (typeof value !== "string") return "";
|
|
59
61
|
const options = NORMALIZE_SYMBOL in this ? this[NORMALIZE_SYMBOL] : this;
|
|
60
62
|
let result = value;
|
|
61
63
|
if (options.trim) result = result.trim();
|
|
62
|
-
if (options.whitespace) result = result.replace(
|
|
64
|
+
if (options.whitespace) result = result.replace(EXPRESSION_WHITESPACE_MULTIPLE, " ");
|
|
63
65
|
if (options.deburr) result = deburr(result);
|
|
64
66
|
if (options.lowerCase) result = lowerCase(result);
|
|
65
|
-
if (options.special) result = result.replace(NORMALIZE_SPECIAL_PATTERN,
|
|
66
|
-
return result.normalize(
|
|
67
|
+
if (options.special) result = result.replace(NORMALIZE_SPECIAL_PATTERN, "");
|
|
68
|
+
return result.normalize("NFC");
|
|
67
69
|
}
|
|
68
|
-
const NORMALIZE_DEBURR_CHARACTERS = {
|
|
69
|
-
Æ: "AE",
|
|
70
|
-
æ: "ae",
|
|
71
|
-
Ð: "D",
|
|
72
|
-
ð: "d",
|
|
73
|
-
Đ: "D",
|
|
74
|
-
đ: "d",
|
|
75
|
-
Ħ: "H",
|
|
76
|
-
ħ: "h",
|
|
77
|
-
IJ: "IJ",
|
|
78
|
-
ij: "ij",
|
|
79
|
-
İ: "I",
|
|
80
|
-
ı: "i",
|
|
81
|
-
ĸ: "k",
|
|
82
|
-
Ŀ: "L",
|
|
83
|
-
ŀ: "l",
|
|
84
|
-
Ł: "L",
|
|
85
|
-
ł: "l",
|
|
86
|
-
Ŋ: "N",
|
|
87
|
-
ŋ: "n",
|
|
88
|
-
ʼn: "'n",
|
|
89
|
-
Œ: "OE",
|
|
90
|
-
œ: "oe",
|
|
91
|
-
Ø: "O",
|
|
92
|
-
ø: "o",
|
|
93
|
-
ſ: "s",
|
|
94
|
-
ß: "ss",
|
|
95
|
-
Þ: "TH",
|
|
96
|
-
þ: "th",
|
|
97
|
-
Ŧ: "T",
|
|
98
|
-
ŧ: "t"
|
|
99
|
-
};
|
|
100
|
-
const NORMALIZE_DEBURR_NORMALIZATION = "NFD";
|
|
101
|
-
const NORMALIZE_DEBURR_PATTERN_CHARACTERS = new RegExp(`(${Object.keys(NORMALIZE_DEBURR_CHARACTERS).join("|")})`, "g");
|
|
102
|
-
const NORMALIZE_DEBURR_PATTERN_SIMPLE = /[\u0300-\u036f]/g;
|
|
103
|
-
const NORMALIZE_NORMALIZATION_NORMALIZATION = "NFC";
|
|
104
|
-
const NORMALIZE_SPECIAL_PATTERN = /[\p{P}\p{S}]/gu;
|
|
105
|
-
const NORMALIZE_SPECIAL_REPLACEMENT = "";
|
|
106
|
-
const NORMALIZE_SYMBOL = Symbol("normalize");
|
|
107
|
-
const NORMALIZE_WHITESPACE_PATTERN = /\s+/g;
|
|
108
|
-
const NORMALIZE_WHITESPACE_REPLACEMENT = " ";
|
|
109
70
|
let deburrMemoizer;
|
|
110
71
|
normalize.initialize = initializeNormalizer;
|
|
111
72
|
//#endregion
|