@ls-stack/utils 3.18.0 → 3.20.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/README.md +1 -15
- package/docs/README.md +72 -0
- package/docs/_media/modules.md +52 -0
- package/docs/arrayUtils/-internal-.md +17 -0
- package/docs/arrayUtils/README.md +423 -0
- package/docs/assertions/-internal-.md +63 -0
- package/docs/assertions/README.md +565 -0
- package/docs/asyncQueue/-internal-.md +815 -0
- package/docs/asyncQueue/README.md +75 -0
- package/docs/awaitDebounce.md +66 -0
- package/docs/cache/-internal-.md +168 -0
- package/docs/cache/README.md +360 -0
- package/docs/castValues.md +47 -0
- package/docs/concurrentCalls/-internal-.md +416 -0
- package/docs/concurrentCalls/README.md +77 -0
- package/docs/consoleFmt.md +91 -0
- package/docs/conversions.md +27 -0
- package/docs/createThrottleController/-internal-.md +73 -0
- package/docs/createThrottleController/README.md +31 -0
- package/docs/debounce.md +188 -0
- package/docs/dedent/-internal-.md +17 -0
- package/docs/dedent/README.md +204 -0
- package/docs/deepEqual.md +94 -0
- package/docs/enhancedMap.md +358 -0
- package/docs/exhaustiveMatch/-internal-.md +39 -0
- package/docs/exhaustiveMatch/README.md +146 -0
- package/docs/getAutoIncrementId.md +93 -0
- package/docs/getCompositeKey.md +39 -0
- package/docs/getValueStableKey.md +57 -0
- package/docs/hash.md +31 -0
- package/docs/interpolate/-internal-.md +61 -0
- package/docs/interpolate/README.md +62 -0
- package/docs/levenshtein.md +93 -0
- package/docs/main.md +21 -0
- package/docs/mathUtils.md +137 -0
- package/docs/modules.md +52 -0
- package/docs/objUtils.md +237 -0
- package/docs/parallelAsyncCalls/-internal-.md +347 -0
- package/docs/parallelAsyncCalls/README.md +45 -0
- package/docs/promiseUtils/-internal-.md +69 -0
- package/docs/promiseUtils/README.md +31 -0
- package/docs/retryOnError.md +67 -0
- package/docs/runShellCmd/-internal-.md +111 -0
- package/docs/runShellCmd/README.md +201 -0
- package/docs/safeJson.md +51 -0
- package/docs/saferTyping.md +228 -0
- package/docs/serializeXML.md +100 -0
- package/docs/shallowEqual.md +33 -0
- package/docs/sleep.md +27 -0
- package/docs/stringUtils/-internal-.md +17 -0
- package/docs/stringUtils/README.md +166 -0
- package/docs/testUtils.md +315 -0
- package/docs/throttle/-internal-.md +47 -0
- package/docs/throttle/README.md +178 -0
- package/docs/time.md +274 -0
- package/docs/timers.md +256 -0
- package/docs/tsResult/-internal-.md +327 -0
- package/docs/tsResult/README.md +696 -0
- package/docs/typeGuards.md +399 -0
- package/docs/typingFnUtils/-internal-.md +27 -0
- package/docs/typingFnUtils/README.md +293 -0
- package/docs/typingTestUtils.md +172 -0
- package/docs/typingUtils.md +111 -0
- package/docs/yamlStringify.md +45 -0
- package/lib/arrayUtils.js +3 -3
- package/lib/assertions.js +2 -2
- package/lib/awaitDebounce.cjs +106 -0
- package/lib/awaitDebounce.d.cts +38 -0
- package/lib/awaitDebounce.d.ts +38 -0
- package/lib/awaitDebounce.js +28 -0
- package/lib/cache.js +2 -2
- package/lib/{chunk-NH2LCAQS.js → chunk-6FIBVC2P.js} +1 -1
- package/lib/{chunk-GKOTKAIV.js → chunk-7CQPOM5I.js} +1 -1
- package/lib/{chunk-WS4WEVHU.js → chunk-C2SVCIWE.js} +1 -1
- package/lib/{chunk-SSKW673U.js → chunk-JF2MDHOJ.js} +5 -1
- package/lib/chunk-NW5H5EW7.js +100 -0
- package/lib/{chunk-DMW5Q4T2.js → chunk-SRVMMYSW.js} +1 -1
- package/lib/concurrentCalls.js +3 -3
- package/lib/createThrottleController.js +3 -3
- package/lib/debounce.js +4 -95
- package/lib/dedent.cjs +31 -3
- package/lib/dedent.d.cts +61 -1
- package/lib/dedent.d.ts +61 -1
- package/lib/dedent.js +31 -3
- package/lib/enhancedMap.js +3 -3
- package/lib/getAutoIncrementId.cjs +44 -0
- package/lib/getAutoIncrementId.d.cts +44 -0
- package/lib/getAutoIncrementId.d.ts +44 -0
- package/lib/getAutoIncrementId.js +18 -0
- package/lib/getCompositeKey.js +3 -3
- package/lib/getValueStableKey.js +3 -3
- package/lib/interpolate.js +2 -2
- package/lib/parallelAsyncCalls.js +2 -2
- package/lib/runShellCmd.d.cts +50 -0
- package/lib/runShellCmd.d.ts +50 -0
- package/lib/serializeXML.cjs +7 -2
- package/lib/serializeXML.d.cts +1 -1
- package/lib/serializeXML.d.ts +1 -1
- package/lib/serializeXML.js +7 -5
- package/lib/testUtils.js +3 -3
- package/lib/throttle.cjs +250 -0
- package/lib/throttle.d.cts +89 -0
- package/lib/throttle.d.ts +89 -0
- package/lib/throttle.js +38 -0
- package/lib/tsResult.js +2 -2
- package/lib/typeGuards.cjs +7 -2
- package/lib/typeGuards.d.cts +2 -1
- package/lib/typeGuards.d.ts +2 -1
- package/lib/typeGuards.js +5 -3
- package/lib/typingFnUtils.cjs +5 -1
- package/lib/typingFnUtils.d.cts +1 -1
- package/lib/typingFnUtils.d.ts +1 -1
- package/lib/typingFnUtils.js +5 -1
- package/lib/yamlStringify.js +5 -5
- package/package.json +22 -12
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
// src/debounce.ts
|
|
2
|
+
function debounce(func, wait, options) {
|
|
3
|
+
let lastArgs;
|
|
4
|
+
let lastThis;
|
|
5
|
+
let maxWait;
|
|
6
|
+
let result;
|
|
7
|
+
let timerId;
|
|
8
|
+
let lastCallTime;
|
|
9
|
+
let lastInvokeTime = 0;
|
|
10
|
+
let leading = false;
|
|
11
|
+
let maxing = false;
|
|
12
|
+
let trailing = true;
|
|
13
|
+
if (options) {
|
|
14
|
+
leading = !!options.leading;
|
|
15
|
+
maxing = "maxWait" in options;
|
|
16
|
+
maxWait = maxing ? Math.max(options.maxWait || 0, wait) : maxWait;
|
|
17
|
+
trailing = "trailing" in options ? !!options.trailing : trailing;
|
|
18
|
+
}
|
|
19
|
+
function invokeFunc(time) {
|
|
20
|
+
const args = lastArgs;
|
|
21
|
+
const thisArg = lastThis;
|
|
22
|
+
lastArgs = lastThis = void 0;
|
|
23
|
+
lastInvokeTime = time;
|
|
24
|
+
result = func.apply(thisArg, args);
|
|
25
|
+
return result;
|
|
26
|
+
}
|
|
27
|
+
function leadingEdge(time) {
|
|
28
|
+
lastInvokeTime = time;
|
|
29
|
+
timerId = setTimeout(timerExpired, wait);
|
|
30
|
+
return leading ? invokeFunc(time) : result;
|
|
31
|
+
}
|
|
32
|
+
function remainingWait(time) {
|
|
33
|
+
const timeSinceLastCall = time - (lastCallTime ?? 0);
|
|
34
|
+
const timeSinceLastInvoke = time - lastInvokeTime;
|
|
35
|
+
const timeWaiting = wait - timeSinceLastCall;
|
|
36
|
+
return maxing ? Math.min(timeWaiting, (maxWait ?? 0) - timeSinceLastInvoke) : timeWaiting;
|
|
37
|
+
}
|
|
38
|
+
function shouldInvoke(time) {
|
|
39
|
+
const timeSinceLastCall = time - (lastCallTime ?? 0);
|
|
40
|
+
const timeSinceLastInvoke = time - lastInvokeTime;
|
|
41
|
+
return lastCallTime === void 0 || timeSinceLastCall >= wait || timeSinceLastCall < 0 || maxing && timeSinceLastInvoke >= (maxWait ?? 0);
|
|
42
|
+
}
|
|
43
|
+
function timerExpired() {
|
|
44
|
+
const time = Date.now();
|
|
45
|
+
if (shouldInvoke(time)) {
|
|
46
|
+
return trailingEdge(time);
|
|
47
|
+
}
|
|
48
|
+
timerId = setTimeout(timerExpired, remainingWait(time));
|
|
49
|
+
}
|
|
50
|
+
function trailingEdge(time) {
|
|
51
|
+
timerId = void 0;
|
|
52
|
+
if (trailing && lastArgs) {
|
|
53
|
+
return invokeFunc(time);
|
|
54
|
+
}
|
|
55
|
+
lastArgs = lastThis = void 0;
|
|
56
|
+
return result;
|
|
57
|
+
}
|
|
58
|
+
function cancel() {
|
|
59
|
+
if (timerId !== void 0) {
|
|
60
|
+
clearTimeout(timerId);
|
|
61
|
+
}
|
|
62
|
+
lastInvokeTime = 0;
|
|
63
|
+
lastArgs = lastCallTime = lastThis = timerId = void 0;
|
|
64
|
+
}
|
|
65
|
+
function flush() {
|
|
66
|
+
return timerId === void 0 ? result : trailingEdge(Date.now());
|
|
67
|
+
}
|
|
68
|
+
function debounced() {
|
|
69
|
+
const time = Date.now();
|
|
70
|
+
const isInvoking = shouldInvoke(time);
|
|
71
|
+
lastArgs = arguments;
|
|
72
|
+
lastThis = this;
|
|
73
|
+
lastCallTime = time;
|
|
74
|
+
if (isInvoking) {
|
|
75
|
+
if (timerId === void 0) {
|
|
76
|
+
return leadingEdge(lastCallTime);
|
|
77
|
+
}
|
|
78
|
+
if (maxing) {
|
|
79
|
+
clearTimeout(timerId);
|
|
80
|
+
timerId = setTimeout(timerExpired, wait);
|
|
81
|
+
return invokeFunc(lastCallTime);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
if (timerId === void 0) {
|
|
85
|
+
timerId = setTimeout(timerExpired, wait);
|
|
86
|
+
}
|
|
87
|
+
return result;
|
|
88
|
+
}
|
|
89
|
+
debounced.cancel = cancel;
|
|
90
|
+
debounced.flush = flush;
|
|
91
|
+
return debounced;
|
|
92
|
+
}
|
|
93
|
+
function isDebouncedFn(fn) {
|
|
94
|
+
return typeof fn === "function" && "cancel" in fn && "flush" in fn;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export {
|
|
98
|
+
debounce,
|
|
99
|
+
isDebouncedFn
|
|
100
|
+
};
|
package/lib/concurrentCalls.js
CHANGED
|
@@ -6,12 +6,12 @@ import {
|
|
|
6
6
|
} from "./chunk-5DZT3Z5Z.js";
|
|
7
7
|
import {
|
|
8
8
|
truncateArray
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-SRVMMYSW.js";
|
|
10
10
|
import {
|
|
11
11
|
invariant,
|
|
12
12
|
isPromise
|
|
13
|
-
} from "./chunk-
|
|
14
|
-
import "./chunk-
|
|
13
|
+
} from "./chunk-C2SVCIWE.js";
|
|
14
|
+
import "./chunk-JF2MDHOJ.js";
|
|
15
15
|
|
|
16
16
|
// src/concurrentCalls.ts
|
|
17
17
|
import { Result, resultify, unknownToError } from "t-result";
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
EnhancedMap
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-7CQPOM5I.js";
|
|
4
4
|
import {
|
|
5
5
|
durationObjToMs
|
|
6
6
|
} from "./chunk-5MNYPLZI.js";
|
|
7
7
|
import "./chunk-HTCYUMDR.js";
|
|
8
8
|
import "./chunk-II4R3VVX.js";
|
|
9
|
-
import "./chunk-
|
|
10
|
-
import "./chunk-
|
|
9
|
+
import "./chunk-C2SVCIWE.js";
|
|
10
|
+
import "./chunk-JF2MDHOJ.js";
|
|
11
11
|
|
|
12
12
|
// src/createThrottleController.ts
|
|
13
13
|
function createThrottleController({
|
package/lib/debounce.js
CHANGED
|
@@ -1,98 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
let maxWait;
|
|
6
|
-
let result;
|
|
7
|
-
let timerId;
|
|
8
|
-
let lastCallTime;
|
|
9
|
-
let lastInvokeTime = 0;
|
|
10
|
-
let leading = false;
|
|
11
|
-
let maxing = false;
|
|
12
|
-
let trailing = true;
|
|
13
|
-
if (options) {
|
|
14
|
-
leading = !!options.leading;
|
|
15
|
-
maxing = "maxWait" in options;
|
|
16
|
-
maxWait = maxing ? Math.max(options.maxWait || 0, wait) : maxWait;
|
|
17
|
-
trailing = "trailing" in options ? !!options.trailing : trailing;
|
|
18
|
-
}
|
|
19
|
-
function invokeFunc(time) {
|
|
20
|
-
const args = lastArgs;
|
|
21
|
-
const thisArg = lastThis;
|
|
22
|
-
lastArgs = lastThis = void 0;
|
|
23
|
-
lastInvokeTime = time;
|
|
24
|
-
result = func.apply(thisArg, args);
|
|
25
|
-
return result;
|
|
26
|
-
}
|
|
27
|
-
function leadingEdge(time) {
|
|
28
|
-
lastInvokeTime = time;
|
|
29
|
-
timerId = setTimeout(timerExpired, wait);
|
|
30
|
-
return leading ? invokeFunc(time) : result;
|
|
31
|
-
}
|
|
32
|
-
function remainingWait(time) {
|
|
33
|
-
const timeSinceLastCall = time - (lastCallTime ?? 0);
|
|
34
|
-
const timeSinceLastInvoke = time - lastInvokeTime;
|
|
35
|
-
const timeWaiting = wait - timeSinceLastCall;
|
|
36
|
-
return maxing ? Math.min(timeWaiting, (maxWait ?? 0) - timeSinceLastInvoke) : timeWaiting;
|
|
37
|
-
}
|
|
38
|
-
function shouldInvoke(time) {
|
|
39
|
-
const timeSinceLastCall = time - (lastCallTime ?? 0);
|
|
40
|
-
const timeSinceLastInvoke = time - lastInvokeTime;
|
|
41
|
-
return lastCallTime === void 0 || timeSinceLastCall >= wait || timeSinceLastCall < 0 || maxing && timeSinceLastInvoke >= (maxWait ?? 0);
|
|
42
|
-
}
|
|
43
|
-
function timerExpired() {
|
|
44
|
-
const time = Date.now();
|
|
45
|
-
if (shouldInvoke(time)) {
|
|
46
|
-
return trailingEdge(time);
|
|
47
|
-
}
|
|
48
|
-
timerId = setTimeout(timerExpired, remainingWait(time));
|
|
49
|
-
}
|
|
50
|
-
function trailingEdge(time) {
|
|
51
|
-
timerId = void 0;
|
|
52
|
-
if (trailing && lastArgs) {
|
|
53
|
-
return invokeFunc(time);
|
|
54
|
-
}
|
|
55
|
-
lastArgs = lastThis = void 0;
|
|
56
|
-
return result;
|
|
57
|
-
}
|
|
58
|
-
function cancel() {
|
|
59
|
-
if (timerId !== void 0) {
|
|
60
|
-
clearTimeout(timerId);
|
|
61
|
-
}
|
|
62
|
-
lastInvokeTime = 0;
|
|
63
|
-
lastArgs = lastCallTime = lastThis = timerId = void 0;
|
|
64
|
-
}
|
|
65
|
-
function flush() {
|
|
66
|
-
return timerId === void 0 ? result : trailingEdge(Date.now());
|
|
67
|
-
}
|
|
68
|
-
function debounced() {
|
|
69
|
-
const time = Date.now();
|
|
70
|
-
const isInvoking = shouldInvoke(time);
|
|
71
|
-
lastArgs = arguments;
|
|
72
|
-
lastThis = this;
|
|
73
|
-
lastCallTime = time;
|
|
74
|
-
if (isInvoking) {
|
|
75
|
-
if (timerId === void 0) {
|
|
76
|
-
return leadingEdge(lastCallTime);
|
|
77
|
-
}
|
|
78
|
-
if (maxing) {
|
|
79
|
-
clearTimeout(timerId);
|
|
80
|
-
timerId = setTimeout(timerExpired, wait);
|
|
81
|
-
return invokeFunc(lastCallTime);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
if (timerId === void 0) {
|
|
85
|
-
timerId = setTimeout(timerExpired, wait);
|
|
86
|
-
}
|
|
87
|
-
return result;
|
|
88
|
-
}
|
|
89
|
-
debounced.cancel = cancel;
|
|
90
|
-
debounced.flush = flush;
|
|
91
|
-
return debounced;
|
|
92
|
-
}
|
|
93
|
-
function isDebouncedFn(fn) {
|
|
94
|
-
return typeof fn === "function" && "cancel" in fn && "flush" in fn;
|
|
95
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
debounce,
|
|
3
|
+
isDebouncedFn
|
|
4
|
+
} from "./chunk-NW5H5EW7.js";
|
|
96
5
|
export {
|
|
97
6
|
debounce,
|
|
98
7
|
isDebouncedFn
|
package/lib/dedent.cjs
CHANGED
|
@@ -23,7 +23,9 @@ __export(dedent_exports, {
|
|
|
23
23
|
dedent: () => dedent
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(dedent_exports);
|
|
26
|
-
var dedent = createDedent({
|
|
26
|
+
var dedent = createDedent({
|
|
27
|
+
identInterpolations: true
|
|
28
|
+
});
|
|
27
29
|
function createDedent(options) {
|
|
28
30
|
d.withOptions = (newOptions) => createDedent({ ...options, ...newOptions });
|
|
29
31
|
return d;
|
|
@@ -31,7 +33,9 @@ function createDedent(options) {
|
|
|
31
33
|
const raw = typeof strings === "string" ? [strings] : strings.raw;
|
|
32
34
|
const {
|
|
33
35
|
escapeSpecialCharacters = Array.isArray(strings),
|
|
34
|
-
trimWhitespace = true
|
|
36
|
+
trimWhitespace = true,
|
|
37
|
+
identInterpolations = true,
|
|
38
|
+
showNullishOrFalseValues = false
|
|
35
39
|
} = options;
|
|
36
40
|
let result = "";
|
|
37
41
|
for (let i = 0; i < raw.length; i++) {
|
|
@@ -41,7 +45,24 @@ function createDedent(options) {
|
|
|
41
45
|
}
|
|
42
46
|
result += next;
|
|
43
47
|
if (i < values.length) {
|
|
44
|
-
|
|
48
|
+
let val = values[i];
|
|
49
|
+
if (!showNullishOrFalseValues && (val === false || val === null || val === void 0)) {
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
val = String(val);
|
|
53
|
+
if (identInterpolations && val.includes("\n")) {
|
|
54
|
+
let withIdent = val;
|
|
55
|
+
const currentIndent = getCurrentIndent(result);
|
|
56
|
+
if (currentIndent && withIdent) {
|
|
57
|
+
const lines2 = withIdent.split("\n");
|
|
58
|
+
withIdent = lines2.map((line, index) => {
|
|
59
|
+
return index === 0 || line === "" ? line : currentIndent + line;
|
|
60
|
+
}).join("\n");
|
|
61
|
+
}
|
|
62
|
+
result += withIdent;
|
|
63
|
+
} else {
|
|
64
|
+
result += val;
|
|
65
|
+
}
|
|
45
66
|
}
|
|
46
67
|
}
|
|
47
68
|
const lines = result.split("\n");
|
|
@@ -70,6 +91,13 @@ function createDedent(options) {
|
|
|
70
91
|
return result;
|
|
71
92
|
}
|
|
72
93
|
}
|
|
94
|
+
function getCurrentIndent(str) {
|
|
95
|
+
const lines = str.split("\n");
|
|
96
|
+
const lastLine = lines[lines.length - 1];
|
|
97
|
+
if (!lastLine) return "";
|
|
98
|
+
const match = lastLine.match(/^(\s*)/);
|
|
99
|
+
return match ? match[1] : "";
|
|
100
|
+
}
|
|
73
101
|
// Annotate the CommonJS export names for ESM import in node:
|
|
74
102
|
0 && (module.exports = {
|
|
75
103
|
dedent
|
package/lib/dedent.d.cts
CHANGED
|
@@ -1,13 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration options for the dedent function behavior
|
|
3
|
+
*/
|
|
1
4
|
interface DedentOptions {
|
|
5
|
+
/**
|
|
6
|
+
* Whether to process escape sequences like \n, \`, \$, and \{
|
|
7
|
+
* When true, allows using escaped characters in template literals
|
|
8
|
+
* @default true for template literals, false for plain strings
|
|
9
|
+
*/
|
|
2
10
|
escapeSpecialCharacters?: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Whether to trim leading and trailing whitespace from the final result
|
|
13
|
+
* @default true
|
|
14
|
+
*/
|
|
3
15
|
trimWhitespace?: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Whether to preserve relative indentation of interpolated multi-line values
|
|
18
|
+
* When true, multi-line interpolations are re-indented to match the surrounding context
|
|
19
|
+
* @default true
|
|
20
|
+
*/
|
|
21
|
+
identInterpolations?: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Whether to display nullish or false values (false, null, undefined) in interpolations
|
|
24
|
+
* When false, nullish or false values are skipped entirely
|
|
25
|
+
* @default false
|
|
26
|
+
*/
|
|
27
|
+
showNullishOrFalseValues?: boolean;
|
|
4
28
|
}
|
|
29
|
+
type InterpolationValue = string | number | boolean | null | undefined;
|
|
30
|
+
/**
|
|
31
|
+
* Dedent function interface that can be used both as a template tag and a regular function
|
|
32
|
+
*/
|
|
5
33
|
interface Dedent {
|
|
34
|
+
/**
|
|
35
|
+
* Process a plain string to remove common indentation
|
|
36
|
+
*/
|
|
6
37
|
(literals: string): string;
|
|
7
|
-
|
|
38
|
+
/**
|
|
39
|
+
* Process a template literal to remove common indentation while handling interpolations
|
|
40
|
+
*/
|
|
41
|
+
(strings: TemplateStringsArray, ...values: InterpolationValue[]): string;
|
|
42
|
+
/**
|
|
43
|
+
* Create a new dedent function with custom options
|
|
44
|
+
*/
|
|
8
45
|
withOptions: CreateDedent;
|
|
9
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* Factory function type for creating dedent functions with custom options
|
|
49
|
+
*/
|
|
10
50
|
type CreateDedent = (options: DedentOptions) => Dedent;
|
|
51
|
+
/**
|
|
52
|
+
* Remove common leading indentation from multi-line strings while preserving relative indentation.
|
|
53
|
+
* Can be used as a tagged template literal or called with a plain string.
|
|
54
|
+
*
|
|
55
|
+
* By default, it will dedent interpolated multi-line strings to match the surrounding context.
|
|
56
|
+
* And it will not show falsy values.
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```typescript
|
|
60
|
+
* const text = dedent`
|
|
61
|
+
* function hello() {
|
|
62
|
+
* console.log('world');
|
|
63
|
+
* }
|
|
64
|
+
* `;
|
|
65
|
+
* // Result:
|
|
66
|
+
* "function hello() {
|
|
67
|
+
* console.log('world');
|
|
68
|
+
* }"
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
11
71
|
declare const dedent: Dedent;
|
|
12
72
|
|
|
13
73
|
export { type CreateDedent, type Dedent, type DedentOptions, dedent };
|
package/lib/dedent.d.ts
CHANGED
|
@@ -1,13 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration options for the dedent function behavior
|
|
3
|
+
*/
|
|
1
4
|
interface DedentOptions {
|
|
5
|
+
/**
|
|
6
|
+
* Whether to process escape sequences like \n, \`, \$, and \{
|
|
7
|
+
* When true, allows using escaped characters in template literals
|
|
8
|
+
* @default true for template literals, false for plain strings
|
|
9
|
+
*/
|
|
2
10
|
escapeSpecialCharacters?: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Whether to trim leading and trailing whitespace from the final result
|
|
13
|
+
* @default true
|
|
14
|
+
*/
|
|
3
15
|
trimWhitespace?: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Whether to preserve relative indentation of interpolated multi-line values
|
|
18
|
+
* When true, multi-line interpolations are re-indented to match the surrounding context
|
|
19
|
+
* @default true
|
|
20
|
+
*/
|
|
21
|
+
identInterpolations?: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Whether to display nullish or false values (false, null, undefined) in interpolations
|
|
24
|
+
* When false, nullish or false values are skipped entirely
|
|
25
|
+
* @default false
|
|
26
|
+
*/
|
|
27
|
+
showNullishOrFalseValues?: boolean;
|
|
4
28
|
}
|
|
29
|
+
type InterpolationValue = string | number | boolean | null | undefined;
|
|
30
|
+
/**
|
|
31
|
+
* Dedent function interface that can be used both as a template tag and a regular function
|
|
32
|
+
*/
|
|
5
33
|
interface Dedent {
|
|
34
|
+
/**
|
|
35
|
+
* Process a plain string to remove common indentation
|
|
36
|
+
*/
|
|
6
37
|
(literals: string): string;
|
|
7
|
-
|
|
38
|
+
/**
|
|
39
|
+
* Process a template literal to remove common indentation while handling interpolations
|
|
40
|
+
*/
|
|
41
|
+
(strings: TemplateStringsArray, ...values: InterpolationValue[]): string;
|
|
42
|
+
/**
|
|
43
|
+
* Create a new dedent function with custom options
|
|
44
|
+
*/
|
|
8
45
|
withOptions: CreateDedent;
|
|
9
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* Factory function type for creating dedent functions with custom options
|
|
49
|
+
*/
|
|
10
50
|
type CreateDedent = (options: DedentOptions) => Dedent;
|
|
51
|
+
/**
|
|
52
|
+
* Remove common leading indentation from multi-line strings while preserving relative indentation.
|
|
53
|
+
* Can be used as a tagged template literal or called with a plain string.
|
|
54
|
+
*
|
|
55
|
+
* By default, it will dedent interpolated multi-line strings to match the surrounding context.
|
|
56
|
+
* And it will not show falsy values.
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```typescript
|
|
60
|
+
* const text = dedent`
|
|
61
|
+
* function hello() {
|
|
62
|
+
* console.log('world');
|
|
63
|
+
* }
|
|
64
|
+
* `;
|
|
65
|
+
* // Result:
|
|
66
|
+
* "function hello() {
|
|
67
|
+
* console.log('world');
|
|
68
|
+
* }"
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
11
71
|
declare const dedent: Dedent;
|
|
12
72
|
|
|
13
73
|
export { type CreateDedent, type Dedent, type DedentOptions, dedent };
|
package/lib/dedent.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
// src/dedent.ts
|
|
2
|
-
var dedent = createDedent({
|
|
2
|
+
var dedent = createDedent({
|
|
3
|
+
identInterpolations: true
|
|
4
|
+
});
|
|
3
5
|
function createDedent(options) {
|
|
4
6
|
d.withOptions = (newOptions) => createDedent({ ...options, ...newOptions });
|
|
5
7
|
return d;
|
|
@@ -7,7 +9,9 @@ function createDedent(options) {
|
|
|
7
9
|
const raw = typeof strings === "string" ? [strings] : strings.raw;
|
|
8
10
|
const {
|
|
9
11
|
escapeSpecialCharacters = Array.isArray(strings),
|
|
10
|
-
trimWhitespace = true
|
|
12
|
+
trimWhitespace = true,
|
|
13
|
+
identInterpolations = true,
|
|
14
|
+
showNullishOrFalseValues = false
|
|
11
15
|
} = options;
|
|
12
16
|
let result = "";
|
|
13
17
|
for (let i = 0; i < raw.length; i++) {
|
|
@@ -17,7 +21,24 @@ function createDedent(options) {
|
|
|
17
21
|
}
|
|
18
22
|
result += next;
|
|
19
23
|
if (i < values.length) {
|
|
20
|
-
|
|
24
|
+
let val = values[i];
|
|
25
|
+
if (!showNullishOrFalseValues && (val === false || val === null || val === void 0)) {
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
val = String(val);
|
|
29
|
+
if (identInterpolations && val.includes("\n")) {
|
|
30
|
+
let withIdent = val;
|
|
31
|
+
const currentIndent = getCurrentIndent(result);
|
|
32
|
+
if (currentIndent && withIdent) {
|
|
33
|
+
const lines2 = withIdent.split("\n");
|
|
34
|
+
withIdent = lines2.map((line, index) => {
|
|
35
|
+
return index === 0 || line === "" ? line : currentIndent + line;
|
|
36
|
+
}).join("\n");
|
|
37
|
+
}
|
|
38
|
+
result += withIdent;
|
|
39
|
+
} else {
|
|
40
|
+
result += val;
|
|
41
|
+
}
|
|
21
42
|
}
|
|
22
43
|
}
|
|
23
44
|
const lines = result.split("\n");
|
|
@@ -46,6 +67,13 @@ function createDedent(options) {
|
|
|
46
67
|
return result;
|
|
47
68
|
}
|
|
48
69
|
}
|
|
70
|
+
function getCurrentIndent(str) {
|
|
71
|
+
const lines = str.split("\n");
|
|
72
|
+
const lastLine = lines[lines.length - 1];
|
|
73
|
+
if (!lastLine) return "";
|
|
74
|
+
const match = lastLine.match(/^(\s*)/);
|
|
75
|
+
return match ? match[1] : "";
|
|
76
|
+
}
|
|
49
77
|
export {
|
|
50
78
|
dedent
|
|
51
79
|
};
|
package/lib/enhancedMap.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
EnhancedMap,
|
|
3
3
|
enhancedMapReject
|
|
4
|
-
} from "./chunk-
|
|
5
|
-
import "./chunk-
|
|
6
|
-
import "./chunk-
|
|
4
|
+
} from "./chunk-7CQPOM5I.js";
|
|
5
|
+
import "./chunk-C2SVCIWE.js";
|
|
6
|
+
import "./chunk-JF2MDHOJ.js";
|
|
7
7
|
export {
|
|
8
8
|
EnhancedMap,
|
|
9
9
|
enhancedMapReject
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/getAutoIncrementId.ts
|
|
21
|
+
var getAutoIncrementId_exports = {};
|
|
22
|
+
__export(getAutoIncrementId_exports, {
|
|
23
|
+
getAutoIncrementId: () => getAutoIncrementId,
|
|
24
|
+
getLocalAutoIncrementIdGenerator: () => getLocalAutoIncrementIdGenerator
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(getAutoIncrementId_exports);
|
|
27
|
+
var id = 1;
|
|
28
|
+
function getAutoIncrementId() {
|
|
29
|
+
return id++;
|
|
30
|
+
}
|
|
31
|
+
function getLocalAutoIncrementIdGenerator({
|
|
32
|
+
prefix,
|
|
33
|
+
suffix
|
|
34
|
+
}) {
|
|
35
|
+
let localId = 1;
|
|
36
|
+
return () => {
|
|
37
|
+
return `${prefix || ""}${localId++}${suffix || ""}`;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
41
|
+
0 && (module.exports = {
|
|
42
|
+
getAutoIncrementId,
|
|
43
|
+
getLocalAutoIncrementIdGenerator
|
|
44
|
+
});
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns a unique auto-incrementing number each time it's called.
|
|
3
|
+
* This is useful for generating simple unique identifiers within a single session/process.
|
|
4
|
+
*
|
|
5
|
+
* **Note:** This is not suitable for distributed systems or persistent storage.
|
|
6
|
+
* For cryptographically secure or collision-resistant IDs, use `nanoid()` instead.
|
|
7
|
+
*
|
|
8
|
+
* @returns A unique incrementing number starting from 1
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* const id1 = getAutoIncrementId(); // 1
|
|
13
|
+
* const id2 = getAutoIncrementId(); // 2
|
|
14
|
+
* const id3 = getAutoIncrementId(); // 3
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
declare function getAutoIncrementId(): number;
|
|
18
|
+
/**
|
|
19
|
+
* Creates a local auto-increment ID generator with optional prefix and suffix.
|
|
20
|
+
* Each generator maintains its own independent counter starting from 1.
|
|
21
|
+
* This is useful when you need multiple independent ID sequences or formatted IDs.
|
|
22
|
+
*
|
|
23
|
+
* @param options - Configuration object
|
|
24
|
+
* @param options.prefix - Optional prefix to prepend to each generated ID
|
|
25
|
+
* @param options.suffix - Optional suffix to append to each generated ID
|
|
26
|
+
* @returns A function that generates formatted auto-increment IDs
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* const userIdGen = getLocalAutoIncrementIdGenerator({ prefix: 'user-' });
|
|
31
|
+
* const postIdGen = getLocalAutoIncrementIdGenerator({ prefix: 'post-', suffix: '-draft' });
|
|
32
|
+
*
|
|
33
|
+
* console.log(userIdGen()); // "user-1"
|
|
34
|
+
* console.log(userIdGen()); // "user-2"
|
|
35
|
+
* console.log(postIdGen()); // "post-1-draft"
|
|
36
|
+
* console.log(postIdGen()); // "post-2-draft"
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
declare function getLocalAutoIncrementIdGenerator({ prefix, suffix, }: {
|
|
40
|
+
prefix?: string;
|
|
41
|
+
suffix?: string;
|
|
42
|
+
}): () => string;
|
|
43
|
+
|
|
44
|
+
export { getAutoIncrementId, getLocalAutoIncrementIdGenerator };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns a unique auto-incrementing number each time it's called.
|
|
3
|
+
* This is useful for generating simple unique identifiers within a single session/process.
|
|
4
|
+
*
|
|
5
|
+
* **Note:** This is not suitable for distributed systems or persistent storage.
|
|
6
|
+
* For cryptographically secure or collision-resistant IDs, use `nanoid()` instead.
|
|
7
|
+
*
|
|
8
|
+
* @returns A unique incrementing number starting from 1
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* const id1 = getAutoIncrementId(); // 1
|
|
13
|
+
* const id2 = getAutoIncrementId(); // 2
|
|
14
|
+
* const id3 = getAutoIncrementId(); // 3
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
declare function getAutoIncrementId(): number;
|
|
18
|
+
/**
|
|
19
|
+
* Creates a local auto-increment ID generator with optional prefix and suffix.
|
|
20
|
+
* Each generator maintains its own independent counter starting from 1.
|
|
21
|
+
* This is useful when you need multiple independent ID sequences or formatted IDs.
|
|
22
|
+
*
|
|
23
|
+
* @param options - Configuration object
|
|
24
|
+
* @param options.prefix - Optional prefix to prepend to each generated ID
|
|
25
|
+
* @param options.suffix - Optional suffix to append to each generated ID
|
|
26
|
+
* @returns A function that generates formatted auto-increment IDs
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* const userIdGen = getLocalAutoIncrementIdGenerator({ prefix: 'user-' });
|
|
31
|
+
* const postIdGen = getLocalAutoIncrementIdGenerator({ prefix: 'post-', suffix: '-draft' });
|
|
32
|
+
*
|
|
33
|
+
* console.log(userIdGen()); // "user-1"
|
|
34
|
+
* console.log(userIdGen()); // "user-2"
|
|
35
|
+
* console.log(postIdGen()); // "post-1-draft"
|
|
36
|
+
* console.log(postIdGen()); // "post-2-draft"
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
declare function getLocalAutoIncrementIdGenerator({ prefix, suffix, }: {
|
|
40
|
+
prefix?: string;
|
|
41
|
+
suffix?: string;
|
|
42
|
+
}): () => string;
|
|
43
|
+
|
|
44
|
+
export { getAutoIncrementId, getLocalAutoIncrementIdGenerator };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// src/getAutoIncrementId.ts
|
|
2
|
+
var id = 1;
|
|
3
|
+
function getAutoIncrementId() {
|
|
4
|
+
return id++;
|
|
5
|
+
}
|
|
6
|
+
function getLocalAutoIncrementIdGenerator({
|
|
7
|
+
prefix,
|
|
8
|
+
suffix
|
|
9
|
+
}) {
|
|
10
|
+
let localId = 1;
|
|
11
|
+
return () => {
|
|
12
|
+
return `${prefix || ""}${localId++}${suffix || ""}`;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
export {
|
|
16
|
+
getAutoIncrementId,
|
|
17
|
+
getLocalAutoIncrementIdGenerator
|
|
18
|
+
};
|