@visulima/string 3.0.0-alpha.10 → 3.0.0-alpha.12
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/CHANGELOG.md +33 -0
- package/LICENSE.md +68 -3
- package/dist/align-text.d.ts +35 -0
- package/dist/align-text.js +2 -34
- package/dist/case/camel-case.d.ts +17 -2
- package/dist/case/camel-case.js +1 -55
- package/dist/case/capital-case.d.ts +14 -2
- package/dist/case/capital-case.js +1 -47
- package/dist/case/constant-case.d.ts +14 -2
- package/dist/case/constant-case.js +1 -7
- package/dist/case/dot-case.d.ts +14 -2
- package/dist/case/dot-case.js +1 -7
- package/dist/case/flat-case.d.ts +12 -2
- package/dist/case/flat-case.js +1 -7
- package/dist/case/flip-case.d.ts +16 -2
- package/dist/case/flip-case.js +1 -82
- package/dist/case/identify-case.d.ts +15 -2
- package/dist/case/identify-case.js +1 -66
- package/dist/case/index.d.ts +8 -2
- package/dist/case/index.js +1 -20
- package/dist/case/kebab-case.d.ts +25 -2
- package/dist/case/kebab-case.js +1 -55
- package/dist/case/lower-first.d.ts +13 -2
- package/dist/case/lower-first.js +1 -9
- package/dist/case/no-case.d.ts +14 -2
- package/dist/case/no-case.js +1 -7
- package/dist/case/pascal-case.d.ts +17 -2
- package/dist/case/pascal-case.js +1 -48
- package/dist/case/pascal-snake-case.d.ts +14 -2
- package/dist/case/pascal-snake-case.js +1 -28
- package/dist/case/path-case.d.ts +14 -2
- package/dist/case/path-case.js +1 -7
- package/dist/case/sentence-case.d.ts +14 -2
- package/dist/case/sentence-case.js +1 -54
- package/dist/case/snake-case.d.ts +14 -2
- package/dist/case/snake-case.js +1 -7
- package/dist/case/split-by-case.d.ts +29 -2
- package/dist/case/split-by-case.js +1 -763
- package/dist/case/title-case.d.ts +12 -2
- package/dist/case/title-case.js +1 -40
- package/dist/case/train-case.d.ts +14 -2
- package/dist/case/train-case.js +1 -40
- package/dist/case/upper-first.d.ts +13 -2
- package/dist/case/upper-first.js +1 -9
- package/dist/closest-string.d.ts +32 -0
- package/dist/closest-string.js +1 -22
- package/dist/compare-similarity.d.ts +38 -1
- package/dist/compare-similarity.js +1 -12
- package/dist/get-string-truncated-width.d.ts +151 -0
- package/dist/get-string-truncated-width.js +1 -332
- package/dist/get-string-width.d.ts +58 -0
- package/dist/get-string-width.js +1 -5
- package/dist/index.d.ts +194 -9
- package/dist/index.js +1 -44
- package/dist/native-string-types.d.ts +239 -0
- package/dist/outdent.d.ts +74 -0
- package/dist/outdent.js +1 -109
- package/dist/packem_shared/LRUCache-Bjo6gsbC.js +1 -0
- package/dist/packem_shared/closest-uarbVSbs.js +1 -0
- package/dist/packem_shared/closestN-Vd5oNJy_.js +1 -0
- package/dist/packem_shared/constants-DmzZF6_u.js +1 -0
- package/dist/packem_shared/countOccurrences-DIHSCdcG.js +1 -0
- package/dist/packem_shared/direction-dtczwUOE.js +1 -0
- package/dist/packem_shared/eastAsianWidthType-lcBsj7vg.js +1 -0
- package/dist/packem_shared/excerpt-DhV2yoHG.js +54 -0
- package/dist/packem_shared/generate-cache-key-DPByFaMH.js +1 -0
- package/dist/packem_shared/indent-CDlPQmpe.js +1 -0
- package/dist/packem_shared/isFullwidthCodePoint-Dmsf2-5L.js +1 -0
- package/dist/packem_shared/joinSegments-D27SxoCV.js +1 -0
- package/dist/packem_shared/lookup-ChWuUpyb.js +1 -0
- package/dist/packem_shared/normalize-german-eszett-AKfdw2MZ.js +1 -0
- package/dist/packem_shared/redent-BECVOaZp.js +1 -0
- package/dist/packem_shared/replaceString-aq-C7Wor.js +1 -0
- package/dist/packem_shared/stripIndent-Dt8hSxVM.js +1 -0
- package/dist/packem_shared/transliterate-D1p1yYE7.js +5 -0
- package/dist/packem_shared/types.d-FOLSY2Tc.d.ts +392 -0
- package/dist/packem_shared/types.d-NJ4vcG-A.d.ts +346 -0
- package/dist/slice.d.ts +42 -0
- package/dist/slice.js +1 -415
- package/dist/slugify.d.ts +10 -1
- package/dist/slugify.js +1 -46
- package/dist/test/utils.d.ts +17 -0
- package/dist/test/utils.js +13 -88
- package/dist/test/vitest.d.ts +3 -0
- package/dist/test/vitest.js +1 -5
- package/dist/truncate.d.ts +43 -0
- package/dist/truncate.js +1 -112
- package/dist/utilities.d.ts +28 -1
- package/dist/utilities.js +1 -52
- package/dist/word-similarity-sort.d.ts +34 -0
- package/dist/word-similarity-sort.js +1 -22
- package/dist/word-wrap.d.ts +44 -0
- package/dist/word-wrap.js +8 -639
- package/package.json +46 -46
- package/dist/packem_shared/LRUCache-3r3SovvR.js +0 -46
- package/dist/packem_shared/closest-IHuSvnSn.js +0 -139
- package/dist/packem_shared/closestN-DUsjgiXb.js +0 -25
- package/dist/packem_shared/constants-BsZS5f0z.js +0 -95
- package/dist/packem_shared/countOccurrences-CS9XprQN.js +0 -22
- package/dist/packem_shared/direction-C9gfWWTK.js +0 -16
- package/dist/packem_shared/eastAsianWidthType-SD3YniiT.js +0 -20
- package/dist/packem_shared/excerpt-COsVNttN.js +0 -1502
- package/dist/packem_shared/generate-cache-key-DdayDfjV.js +0 -6
- package/dist/packem_shared/indent-D3DSCa6s.js +0 -33
- package/dist/packem_shared/isFullwidthCodePoint-IFXZxNjq.js +0 -10
- package/dist/packem_shared/joinSegments-CvxSgKz0.js +0 -44
- package/dist/packem_shared/lookup-BE8lEqy4.js +0 -104
- package/dist/packem_shared/normalize-german-eszett-4p3yKEzn.js +0 -8
- package/dist/packem_shared/redent-DSb1IJWn.js +0 -8
- package/dist/packem_shared/replaceString-Ce8X2ZQ-.js +0 -192
- package/dist/packem_shared/stripIndent-D_TRjxZ_.js +0 -20
- package/dist/packem_shared/transliterate-CKt9VK7D.js +0 -47756
- package/dist/packem_shared/types.d-BVNv675q.d.ts +0 -61
- package/dist/packem_shared/types.d-DfgbcNKh.d.ts +0 -57
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
const generateCacheKey = (value, options) => (
|
|
2
|
-
// Only include options that affect the output
|
|
3
|
-
`${value}::${options?.joiner ?? ""}::${options?.locale ?? ""}::${options?.knownAcronyms?.join(",") ?? ""}::${options?.normalize ? "true" : "false"}`
|
|
4
|
-
);
|
|
5
|
-
|
|
6
|
-
export { generateCacheKey as g };
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
function indentString(string, count = 1, options = {}) {
|
|
2
|
-
const {
|
|
3
|
-
indent = " ",
|
|
4
|
-
includeEmptyLines = false
|
|
5
|
-
} = options;
|
|
6
|
-
if (typeof string !== "string") {
|
|
7
|
-
throw new TypeError(
|
|
8
|
-
`Expected \`input\` to be a \`string\`, got \`${typeof string}\``
|
|
9
|
-
);
|
|
10
|
-
}
|
|
11
|
-
if (typeof count !== "number") {
|
|
12
|
-
throw new TypeError(
|
|
13
|
-
`Expected \`count\` to be a \`number\`, got \`${typeof count}\``
|
|
14
|
-
);
|
|
15
|
-
}
|
|
16
|
-
if (count < 0) {
|
|
17
|
-
throw new RangeError(
|
|
18
|
-
`Expected \`count\` to be at least 0, got \`${count}\``
|
|
19
|
-
);
|
|
20
|
-
}
|
|
21
|
-
if (typeof indent !== "string") {
|
|
22
|
-
throw new TypeError(
|
|
23
|
-
`Expected \`options.indent\` to be a \`string\`, got \`${typeof indent}\``
|
|
24
|
-
);
|
|
25
|
-
}
|
|
26
|
-
if (count === 0) {
|
|
27
|
-
return string;
|
|
28
|
-
}
|
|
29
|
-
const regex = includeEmptyLines ? /^/gm : /^(?!\s*$)/gm;
|
|
30
|
-
return string.replace(regex, indent.repeat(count));
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export { indentString as default };
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { i as isFullWidth, a as isWide } from './lookup-BE8lEqy4.js';
|
|
2
|
-
|
|
3
|
-
const isFullwidthCodePoint = (codePoint) => {
|
|
4
|
-
if (!Number.isInteger(codePoint)) {
|
|
5
|
-
return false;
|
|
6
|
-
}
|
|
7
|
-
return isFullWidth(codePoint) || isWide(codePoint);
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
export { isFullwidthCodePoint as default };
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { R as RE_FAST_ANSI } from './constants-BsZS5f0z.js';
|
|
2
|
-
|
|
3
|
-
const joinSegments = (segments, joiner) => {
|
|
4
|
-
const { length } = segments;
|
|
5
|
-
if (length === 0) {
|
|
6
|
-
return "";
|
|
7
|
-
}
|
|
8
|
-
if (length === 1) {
|
|
9
|
-
return segments[0];
|
|
10
|
-
}
|
|
11
|
-
const result = [];
|
|
12
|
-
let ansiStart = "";
|
|
13
|
-
let currentContent = "";
|
|
14
|
-
for (let index = 0; index < length; index++) {
|
|
15
|
-
const segment = segments[index];
|
|
16
|
-
if (RE_FAST_ANSI.test(segment)) {
|
|
17
|
-
if (ansiStart) {
|
|
18
|
-
result.push(ansiStart + currentContent + segment);
|
|
19
|
-
ansiStart = "";
|
|
20
|
-
currentContent = "";
|
|
21
|
-
} else {
|
|
22
|
-
if (result.length > 0) {
|
|
23
|
-
result.push(joiner);
|
|
24
|
-
}
|
|
25
|
-
ansiStart = segment;
|
|
26
|
-
}
|
|
27
|
-
continue;
|
|
28
|
-
}
|
|
29
|
-
if (ansiStart) {
|
|
30
|
-
if (currentContent) {
|
|
31
|
-
currentContent += joiner;
|
|
32
|
-
}
|
|
33
|
-
currentContent += segment;
|
|
34
|
-
} else {
|
|
35
|
-
if (result.length > 0) {
|
|
36
|
-
result.push(joiner);
|
|
37
|
-
}
|
|
38
|
-
result.push(segment);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
return result.join("");
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
export { joinSegments as default };
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
const ambiguousRanges = [161, 161, 164, 164, 167, 168, 170, 170, 173, 174, 176, 180, 182, 186, 188, 191, 198, 198, 208, 208, 215, 216, 222, 225, 230, 230, 232, 234, 236, 237, 240, 240, 242, 243, 247, 250, 252, 252, 254, 254, 257, 257, 273, 273, 275, 275, 283, 283, 294, 295, 299, 299, 305, 307, 312, 312, 319, 322, 324, 324, 328, 331, 333, 333, 338, 339, 358, 359, 363, 363, 462, 462, 464, 464, 466, 466, 468, 468, 470, 470, 472, 472, 474, 474, 476, 476, 593, 593, 609, 609, 708, 708, 711, 711, 713, 715, 717, 717, 720, 720, 728, 731, 733, 733, 735, 735, 768, 879, 913, 929, 931, 937, 945, 961, 963, 969, 1025, 1025, 1040, 1103, 1105, 1105, 8208, 8208, 8211, 8214, 8216, 8217, 8220, 8221, 8224, 8226, 8228, 8231, 8240, 8240, 8242, 8243, 8245, 8245, 8251, 8251, 8254, 8254, 8308, 8308, 8319, 8319, 8321, 8324, 8364, 8364, 8451, 8451, 8453, 8453, 8457, 8457, 8467, 8467, 8470, 8470, 8481, 8482, 8486, 8486, 8491, 8491, 8531, 8532, 8539, 8542, 8544, 8555, 8560, 8569, 8585, 8585, 8592, 8601, 8632, 8633, 8658, 8658, 8660, 8660, 8679, 8679, 8704, 8704, 8706, 8707, 8711, 8712, 8715, 8715, 8719, 8719, 8721, 8721, 8725, 8725, 8730, 8730, 8733, 8736, 8739, 8739, 8741, 8741, 8743, 8748, 8750, 8750, 8756, 8759, 8764, 8765, 8776, 8776, 8780, 8780, 8786, 8786, 8800, 8801, 8804, 8807, 8810, 8811, 8814, 8815, 8834, 8835, 8838, 8839, 8853, 8853, 8857, 8857, 8869, 8869, 8895, 8895, 8978, 8978, 9312, 9449, 9451, 9547, 9552, 9587, 9600, 9615, 9618, 9621, 9632, 9633, 9635, 9641, 9650, 9651, 9654, 9655, 9660, 9661, 9664, 9665, 9670, 9672, 9675, 9675, 9678, 9681, 9698, 9701, 9711, 9711, 9733, 9734, 9737, 9737, 9742, 9743, 9756, 9756, 9758, 9758, 9792, 9792, 9794, 9794, 9824, 9825, 9827, 9829, 9831, 9834, 9836, 9837, 9839, 9839, 9886, 9887, 9919, 9919, 9926, 9933, 9935, 9939, 9941, 9953, 9955, 9955, 9960, 9961, 9963, 9969, 9972, 9972, 9974, 9977, 9979, 9980, 9982, 9983, 10045, 10045, 10102, 10111, 11094, 11097, 12872, 12879, 57344, 63743, 65024, 65039, 65533, 65533, 127232, 127242, 127248, 127277, 127280, 127337, 127344, 127373, 127375, 127376, 127387, 127404, 917760, 917999, 983040, 1048573, 1048576, 1114109];
|
|
2
|
-
const fullwidthRanges = [12288, 12288, 65281, 65376, 65504, 65510];
|
|
3
|
-
const halfwidthRanges = [8361, 8361, 65377, 65470, 65474, 65479, 65482, 65487, 65490, 65495, 65498, 65500, 65512, 65518];
|
|
4
|
-
const narrowRanges = [32, 126, 162, 163, 165, 166, 172, 172, 175, 175, 10214, 10221, 10629, 10630];
|
|
5
|
-
const wideRanges = [4352, 4447, 8986, 8987, 9001, 9002, 9193, 9196, 9200, 9200, 9203, 9203, 9725, 9726, 9748, 9749, 9776, 9783, 9800, 9811, 9855, 9855, 9866, 9871, 9875, 9875, 9889, 9889, 9898, 9899, 9917, 9918, 9924, 9925, 9934, 9934, 9940, 9940, 9962, 9962, 9970, 9971, 9973, 9973, 9978, 9978, 9981, 9981, 9989, 9989, 9994, 9995, 10024, 10024, 10060, 10060, 10062, 10062, 10067, 10069, 10071, 10071, 10133, 10135, 10160, 10160, 10175, 10175, 11035, 11036, 11088, 11088, 11093, 11093, 11904, 11929, 11931, 12019, 12032, 12245, 12272, 12287, 12289, 12350, 12353, 12438, 12441, 12543, 12549, 12591, 12593, 12686, 12688, 12773, 12783, 12830, 12832, 12871, 12880, 42124, 42128, 42182, 43360, 43388, 44032, 55203, 63744, 64255, 65040, 65049, 65072, 65106, 65108, 65126, 65128, 65131, 94176, 94180, 94192, 94198, 94208, 101589, 101631, 101662, 101760, 101874, 110576, 110579, 110581, 110587, 110589, 110590, 110592, 110882, 110898, 110898, 110928, 110930, 110933, 110933, 110948, 110951, 110960, 111355, 119552, 119638, 119648, 119670, 126980, 126980, 127183, 127183, 127374, 127374, 127377, 127386, 127488, 127490, 127504, 127547, 127552, 127560, 127568, 127569, 127584, 127589, 127744, 127776, 127789, 127797, 127799, 127868, 127870, 127891, 127904, 127946, 127951, 127955, 127968, 127984, 127988, 127988, 127992, 128062, 128064, 128064, 128066, 128252, 128255, 128317, 128331, 128334, 128336, 128359, 128378, 128378, 128405, 128406, 128420, 128420, 128507, 128591, 128640, 128709, 128716, 128716, 128720, 128722, 128725, 128728, 128732, 128735, 128747, 128748, 128756, 128764, 128992, 129003, 129008, 129008, 129292, 129338, 129340, 129349, 129351, 129535, 129648, 129660, 129664, 129674, 129678, 129734, 129736, 129736, 129741, 129756, 129759, 129770, 129775, 129784, 131072, 196605, 196608, 262141];
|
|
6
|
-
|
|
7
|
-
const isInRange = (ranges, codePoint) => {
|
|
8
|
-
let low = 0;
|
|
9
|
-
let high = Math.floor(ranges.length / 2) - 1;
|
|
10
|
-
while (low <= high) {
|
|
11
|
-
const mid = Math.floor((low + high) / 2);
|
|
12
|
-
const i = mid * 2;
|
|
13
|
-
if (codePoint < ranges[i]) {
|
|
14
|
-
high = mid - 1;
|
|
15
|
-
} else if (codePoint > ranges[i + 1]) {
|
|
16
|
-
low = mid + 1;
|
|
17
|
-
} else {
|
|
18
|
-
return true;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
return false;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
const minimumAmbiguousCodePoint = ambiguousRanges[0];
|
|
25
|
-
const maximumAmbiguousCodePoint = ambiguousRanges.at(-1);
|
|
26
|
-
const minimumFullWidthCodePoint = fullwidthRanges[0];
|
|
27
|
-
const maximumFullWidthCodePoint = fullwidthRanges.at(-1);
|
|
28
|
-
const minimumHalfWidthCodePoint = halfwidthRanges[0];
|
|
29
|
-
const maximumHalfWidthCodePoint = halfwidthRanges.at(-1);
|
|
30
|
-
const minimumNarrowCodePoint = narrowRanges[0];
|
|
31
|
-
const maximumNarrowCodePoint = narrowRanges.at(-1);
|
|
32
|
-
const minimumWideCodePoint = wideRanges[0];
|
|
33
|
-
const maximumWideCodePoint = wideRanges.at(-1);
|
|
34
|
-
const commonCjkCodePoint = 19968;
|
|
35
|
-
const [wideFastPathStart, wideFastPathEnd] = findWideFastPathRange(wideRanges);
|
|
36
|
-
function findWideFastPathRange(ranges) {
|
|
37
|
-
let fastPathStart = ranges[0];
|
|
38
|
-
let fastPathEnd = ranges[1];
|
|
39
|
-
for (let index = 0; index < ranges.length; index += 2) {
|
|
40
|
-
const start = ranges[index];
|
|
41
|
-
const end = ranges[index + 1];
|
|
42
|
-
if (commonCjkCodePoint >= start && commonCjkCodePoint <= end) {
|
|
43
|
-
return [start, end];
|
|
44
|
-
}
|
|
45
|
-
if (end - start > fastPathEnd - fastPathStart) {
|
|
46
|
-
fastPathStart = start;
|
|
47
|
-
fastPathEnd = end;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
return [fastPathStart, fastPathEnd];
|
|
51
|
-
}
|
|
52
|
-
const isAmbiguous = (codePoint) => {
|
|
53
|
-
if (codePoint < minimumAmbiguousCodePoint || codePoint > maximumAmbiguousCodePoint) {
|
|
54
|
-
return false;
|
|
55
|
-
}
|
|
56
|
-
return isInRange(ambiguousRanges, codePoint);
|
|
57
|
-
};
|
|
58
|
-
const isFullWidth = (codePoint) => {
|
|
59
|
-
if (codePoint < minimumFullWidthCodePoint || codePoint > maximumFullWidthCodePoint) {
|
|
60
|
-
return false;
|
|
61
|
-
}
|
|
62
|
-
return isInRange(fullwidthRanges, codePoint);
|
|
63
|
-
};
|
|
64
|
-
const isHalfWidth = (codePoint) => {
|
|
65
|
-
if (codePoint < minimumHalfWidthCodePoint || codePoint > maximumHalfWidthCodePoint) {
|
|
66
|
-
return false;
|
|
67
|
-
}
|
|
68
|
-
return isInRange(halfwidthRanges, codePoint);
|
|
69
|
-
};
|
|
70
|
-
const isNarrow = (codePoint) => {
|
|
71
|
-
if (codePoint < minimumNarrowCodePoint || codePoint > maximumNarrowCodePoint) {
|
|
72
|
-
return false;
|
|
73
|
-
}
|
|
74
|
-
return isInRange(narrowRanges, codePoint);
|
|
75
|
-
};
|
|
76
|
-
const isWide = (codePoint) => {
|
|
77
|
-
if (codePoint >= wideFastPathStart && codePoint <= wideFastPathEnd) {
|
|
78
|
-
return true;
|
|
79
|
-
}
|
|
80
|
-
if (codePoint < minimumWideCodePoint || codePoint > maximumWideCodePoint) {
|
|
81
|
-
return false;
|
|
82
|
-
}
|
|
83
|
-
return isInRange(wideRanges, codePoint);
|
|
84
|
-
};
|
|
85
|
-
function getCategory(codePoint) {
|
|
86
|
-
if (isAmbiguous(codePoint)) {
|
|
87
|
-
return "ambiguous";
|
|
88
|
-
}
|
|
89
|
-
if (isFullWidth(codePoint)) {
|
|
90
|
-
return "fullwidth";
|
|
91
|
-
}
|
|
92
|
-
if (isHalfWidth(codePoint)) {
|
|
93
|
-
return "halfwidth";
|
|
94
|
-
}
|
|
95
|
-
if (isNarrow(codePoint)) {
|
|
96
|
-
return "narrow";
|
|
97
|
-
}
|
|
98
|
-
if (isWide(codePoint)) {
|
|
99
|
-
return "wide";
|
|
100
|
-
}
|
|
101
|
-
return "neutral";
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
export { isWide as a, isAmbiguous as b, getCategory as g, isFullWidth as i };
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
const RE_GERMAN_DOUBLE_S = /(?<![a-zß])SS(?![a-z])/g;
|
|
2
|
-
const normalizeGermanEszett = (value) => (
|
|
3
|
-
// Replace "SS" with "ß" only when both letters are uppercase
|
|
4
|
-
// This uses a positive lookbehind to ensure we don't convert "ss" or "Ss"
|
|
5
|
-
value.replaceAll(RE_GERMAN_DOUBLE_S, "ß")
|
|
6
|
-
);
|
|
7
|
-
|
|
8
|
-
export { normalizeGermanEszett as n };
|
|
@@ -1,192 +0,0 @@
|
|
|
1
|
-
const RE_REPLACEMENT_REGEX = /\$([\d&$`'])/g;
|
|
2
|
-
const RE_REPLACEMENT_STRING = /\$(\d+|&|\$)/g;
|
|
3
|
-
const mergeIntervals = (intervals) => {
|
|
4
|
-
if (intervals.length === 0) {
|
|
5
|
-
return [];
|
|
6
|
-
}
|
|
7
|
-
const merged = [];
|
|
8
|
-
let currentMerge = [...intervals[0]];
|
|
9
|
-
for (let index = 1; index < intervals.length; index++) {
|
|
10
|
-
const next = intervals[index];
|
|
11
|
-
if (next && next[0] <= currentMerge[1] + 1) {
|
|
12
|
-
currentMerge[1] = Math.max(currentMerge[1], next[1]);
|
|
13
|
-
} else {
|
|
14
|
-
merged.push(currentMerge);
|
|
15
|
-
currentMerge = [...next];
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
merged.push(currentMerge);
|
|
19
|
-
return merged;
|
|
20
|
-
};
|
|
21
|
-
const replaceString = (source, searches, ignoreRanges) => {
|
|
22
|
-
if (!source) {
|
|
23
|
-
return "";
|
|
24
|
-
}
|
|
25
|
-
const potentialMatches = [];
|
|
26
|
-
let matchIdCounter = 0;
|
|
27
|
-
for (const item of searches) {
|
|
28
|
-
const [searchKey, replacementValue] = item;
|
|
29
|
-
if (replacementValue === void 0) {
|
|
30
|
-
continue;
|
|
31
|
-
}
|
|
32
|
-
try {
|
|
33
|
-
if (searchKey instanceof RegExp) {
|
|
34
|
-
const searchPattern = new RegExp(searchKey.source, `${searchKey.flags.replace("g", "")}g`);
|
|
35
|
-
let match;
|
|
36
|
-
while ((match = searchPattern.exec(source)) !== null) {
|
|
37
|
-
const start = match.index;
|
|
38
|
-
const original = match[0];
|
|
39
|
-
if (original.length === 0 && searchPattern.lastIndex === match.index) {
|
|
40
|
-
searchPattern.lastIndex += 1;
|
|
41
|
-
}
|
|
42
|
-
const end = start + original.length - 1;
|
|
43
|
-
const finalReplacement = replacementValue.replaceAll(RE_REPLACEMENT_REGEX, (substringFound, capturedSymbolOrDigits) => {
|
|
44
|
-
if (capturedSymbolOrDigits === "&") {
|
|
45
|
-
return original;
|
|
46
|
-
}
|
|
47
|
-
if (capturedSymbolOrDigits === "$") {
|
|
48
|
-
return "$";
|
|
49
|
-
}
|
|
50
|
-
if (capturedSymbolOrDigits === "`") {
|
|
51
|
-
return source.slice(0, Math.max(0, start));
|
|
52
|
-
}
|
|
53
|
-
if (capturedSymbolOrDigits === "'") {
|
|
54
|
-
return source.slice(Math.max(0, start + original.length));
|
|
55
|
-
}
|
|
56
|
-
const groupIndex = Number.parseInt(capturedSymbolOrDigits, 10);
|
|
57
|
-
if (match && groupIndex > 0 && groupIndex < match.length) {
|
|
58
|
-
return match[groupIndex] ?? "";
|
|
59
|
-
}
|
|
60
|
-
return substringFound;
|
|
61
|
-
});
|
|
62
|
-
potentialMatches.push({ end, id: matchIdCounter++, original, replacement: finalReplacement, start });
|
|
63
|
-
if (original.length === 0 && searchPattern.lastIndex === start) {
|
|
64
|
-
searchPattern.lastIndex += 1;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
} else if (typeof searchKey === "string" && searchKey.length > 0) {
|
|
68
|
-
for (let index = 0; (index = source.indexOf(searchKey, index)) !== -1; index++) {
|
|
69
|
-
const start = index;
|
|
70
|
-
const original = searchKey;
|
|
71
|
-
const end = start + original.length - 1;
|
|
72
|
-
const mockMatch = Object.assign([original], { index: start, input: source });
|
|
73
|
-
const finalReplacement = replacementValue.replaceAll(RE_REPLACEMENT_STRING, (substringFound, capturedSymbolOrDigits) => {
|
|
74
|
-
if (capturedSymbolOrDigits === "&") {
|
|
75
|
-
return original;
|
|
76
|
-
}
|
|
77
|
-
if (capturedSymbolOrDigits === "$") {
|
|
78
|
-
return "$";
|
|
79
|
-
}
|
|
80
|
-
const groupIndex = Number.parseInt(capturedSymbolOrDigits, 10);
|
|
81
|
-
if (groupIndex > 0 && groupIndex < mockMatch.length) {
|
|
82
|
-
return mockMatch[groupIndex] ?? "";
|
|
83
|
-
}
|
|
84
|
-
return substringFound;
|
|
85
|
-
});
|
|
86
|
-
potentialMatches.push({ end, id: matchIdCounter++, original, replacement: finalReplacement, start });
|
|
87
|
-
}
|
|
88
|
-
} else {
|
|
89
|
-
continue;
|
|
90
|
-
}
|
|
91
|
-
} catch {
|
|
92
|
-
continue;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
potentialMatches.sort((a, b) => {
|
|
96
|
-
if (a.start !== b.start) {
|
|
97
|
-
return a.start - b.start;
|
|
98
|
-
}
|
|
99
|
-
return b.end - a.end;
|
|
100
|
-
});
|
|
101
|
-
const sortedIgnores = ignoreRanges.toSorted((a, b) => a[0] - b[0]);
|
|
102
|
-
const mergedIgnores = mergeIntervals(sortedIgnores);
|
|
103
|
-
const processedChars = source.split("").map((char, index) => {
|
|
104
|
-
return {
|
|
105
|
-
appliedMatchId: void 0,
|
|
106
|
-
char,
|
|
107
|
-
index,
|
|
108
|
-
insertBeforeReplacement: void 0,
|
|
109
|
-
isIgnored: false,
|
|
110
|
-
isMatchStart: false,
|
|
111
|
-
matchReplacement: void 0
|
|
112
|
-
};
|
|
113
|
-
});
|
|
114
|
-
for (const mergedIgnore of mergedIgnores) {
|
|
115
|
-
const range = mergedIgnore;
|
|
116
|
-
for (let index = range[0]; index <= range[1]; index++) {
|
|
117
|
-
if (processedChars[index]) {
|
|
118
|
-
processedChars[index].isIgnored = true;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
let insertionAfterEnd = "";
|
|
123
|
-
for (const potentialMatch of potentialMatches) {
|
|
124
|
-
const match = potentialMatch;
|
|
125
|
-
if (match.original.length === 0 && match.start >= 0 && match.start <= processedChars.length) {
|
|
126
|
-
const targetIndex = match.start;
|
|
127
|
-
if (processedChars[targetIndex]) {
|
|
128
|
-
const targetChar = processedChars[targetIndex];
|
|
129
|
-
if (!targetChar.isIgnored) {
|
|
130
|
-
targetChar.insertBeforeReplacement = (targetChar.insertBeforeReplacement ?? "") + match.replacement;
|
|
131
|
-
}
|
|
132
|
-
} else if (targetIndex === processedChars.length) {
|
|
133
|
-
insertionAfterEnd += match.replacement;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
for (const potentialMatch of potentialMatches) {
|
|
138
|
-
const match = potentialMatch;
|
|
139
|
-
if (match.original.length === 0) {
|
|
140
|
-
continue;
|
|
141
|
-
}
|
|
142
|
-
let canApply = true;
|
|
143
|
-
for (let index = match.start; index <= match.end; index++) {
|
|
144
|
-
if (!processedChars[index] || processedChars[index].isIgnored || processedChars[index].appliedMatchId !== void 0) {
|
|
145
|
-
canApply = false;
|
|
146
|
-
break;
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
if (canApply && match.start >= 0 && match.start < processedChars.length) {
|
|
150
|
-
for (let index = match.start; index <= match.end; index++) {
|
|
151
|
-
if (processedChars[index]) {
|
|
152
|
-
processedChars[index].appliedMatchId = match.id;
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
if (processedChars[match.start]) {
|
|
156
|
-
processedChars[match.start].isMatchStart = true;
|
|
157
|
-
processedChars[match.start].matchReplacement = match.replacement;
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
let result = "";
|
|
162
|
-
let currentIndex = 0;
|
|
163
|
-
while (currentIndex < processedChars.length) {
|
|
164
|
-
const pChar = processedChars[currentIndex];
|
|
165
|
-
if (pChar.insertBeforeReplacement !== void 0) {
|
|
166
|
-
result += pChar.insertBeforeReplacement;
|
|
167
|
-
}
|
|
168
|
-
if (pChar.isMatchStart && pChar.appliedMatchId !== void 0) {
|
|
169
|
-
result += pChar.matchReplacement ?? "";
|
|
170
|
-
let matchEndIndex = currentIndex;
|
|
171
|
-
for (let index = currentIndex + 1; index < processedChars.length; index++) {
|
|
172
|
-
if (processedChars[index]?.appliedMatchId === pChar.appliedMatchId) {
|
|
173
|
-
matchEndIndex = index;
|
|
174
|
-
} else {
|
|
175
|
-
break;
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
currentIndex = matchEndIndex + 1;
|
|
179
|
-
} else if (pChar.appliedMatchId === void 0) {
|
|
180
|
-
result += pChar.char;
|
|
181
|
-
currentIndex += 1;
|
|
182
|
-
} else {
|
|
183
|
-
currentIndex += 1;
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
if (insertionAfterEnd.length > 0) {
|
|
187
|
-
result += insertionAfterEnd;
|
|
188
|
-
}
|
|
189
|
-
return result;
|
|
190
|
-
};
|
|
191
|
-
|
|
192
|
-
export { replaceString as default };
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
function stripIndent(string) {
|
|
2
|
-
const match = string.match(/^[ \t]*(?=\S)/gm);
|
|
3
|
-
if (!match) {
|
|
4
|
-
return string;
|
|
5
|
-
}
|
|
6
|
-
let minIndent = Number.POSITIVE_INFINITY;
|
|
7
|
-
for (const indent of match) {
|
|
8
|
-
minIndent = Math.min(minIndent, indent.length);
|
|
9
|
-
}
|
|
10
|
-
if (minIndent === 0 || minIndent === Number.POSITIVE_INFINITY) {
|
|
11
|
-
return string;
|
|
12
|
-
}
|
|
13
|
-
return string.replace(new RegExp(`^[ \\t]{${minIndent}}`, "gm"), "");
|
|
14
|
-
}
|
|
15
|
-
function dedent(string) {
|
|
16
|
-
const trimmed = string.replace(/^(?:[ \t]*\r?\n)+|(?:\r?\n[ \t]*)+$/g, "");
|
|
17
|
-
return stripIndent(trimmed);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export { dedent, stripIndent as default };
|