@visulima/string 3.0.0-alpha.1 → 3.0.0-alpha.11
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 +155 -0
- package/LICENSE.md +429 -1
- package/README.md +72 -20
- package/dist/align-text.d.ts +7 -10
- package/dist/align-text.js +7 -5
- package/dist/case/camel-case.d.ts +3 -5
- package/dist/case/camel-case.js +7 -7
- package/dist/case/capital-case.d.ts +3 -5
- package/dist/case/capital-case.js +3 -3
- package/dist/case/constant-case.d.ts +3 -5
- package/dist/case/dot-case.d.ts +3 -5
- package/dist/case/flat-case.d.ts +3 -5
- package/dist/case/flip-case.d.ts +4 -7
- package/dist/case/flip-case.js +8 -2
- package/dist/case/identify-case.d.ts +3 -5
- package/dist/case/identify-case.js +2 -1
- package/dist/case/index.d.ts +23 -25
- package/dist/case/index.js +1 -1
- package/dist/case/kebab-case.d.ts +6 -9
- package/dist/case/kebab-case.js +3 -3
- package/dist/case/lower-first.d.ts +3 -5
- package/dist/case/no-case.d.ts +3 -5
- package/dist/case/pascal-case.d.ts +3 -5
- package/dist/case/pascal-case.js +3 -3
- package/dist/case/pascal-snake-case.d.ts +3 -5
- package/dist/case/path-case.d.ts +3 -5
- package/dist/case/sentence-case.d.ts +3 -5
- package/dist/case/sentence-case.js +7 -7
- package/dist/case/snake-case.d.ts +3 -5
- package/dist/case/split-by-case.d.ts +11 -14
- package/dist/case/split-by-case.js +171 -52
- package/dist/case/title-case.d.ts +3 -5
- package/dist/case/title-case.js +3 -5
- package/dist/case/train-case.d.ts +3 -5
- package/dist/case/train-case.js +1 -1
- package/dist/case/upper-first.d.ts +3 -5
- package/dist/closest-string.d.ts +3 -5
- package/dist/closest-string.js +5 -8
- package/dist/compare-similarity.d.ts +3 -5
- package/dist/compare-similarity.js +2 -2
- package/dist/get-string-truncated-width.d.ts +18 -20
- package/dist/get-string-truncated-width.js +2 -33
- package/dist/get-string-width.d.ts +2 -5
- package/dist/index.d.ts +49 -45
- package/dist/index.js +12 -4
- package/dist/native-string-types.d.ts +145 -128
- package/dist/outdent.d.ts +9 -11
- package/dist/outdent.js +7 -15
- package/dist/packem_shared/closestN-DUsjgiXb.js +25 -0
- package/dist/packem_shared/{constants-CTzC6Gjg.js → constants-BsZS5f0z.js} +1 -1
- package/dist/packem_shared/countOccurrences-CS9XprQN.js +22 -0
- package/dist/packem_shared/direction-C9gfWWTK.js +16 -0
- package/dist/packem_shared/eastAsianWidthType-SD3YniiT.js +20 -0
- package/dist/packem_shared/excerpt-COsVNttN.js +1502 -0
- package/dist/packem_shared/indent-D3DSCa6s.js +33 -0
- package/dist/packem_shared/isFullwidthCodePoint-IFXZxNjq.js +10 -0
- package/dist/packem_shared/{joinSegments-CuU8RGpP.js → joinSegments-CvxSgKz0.js} +1 -1
- package/dist/packem_shared/lookup-BE8lEqy4.js +104 -0
- package/dist/packem_shared/lru-cache.d-BsP6kbVJ.d.ts +13 -0
- package/dist/packem_shared/{normalize-german-eszett-DEB8-ZPT.js → normalize-german-eszett-4p3yKEzn.js} +2 -1
- package/dist/packem_shared/redent-DSb1IJWn.js +8 -0
- package/dist/packem_shared/{replaceString-vYvRBMfC.js → replaceString-Ce8X2ZQ-.js} +19 -17
- package/dist/packem_shared/stripIndent-D_TRjxZ_.js +20 -0
- package/dist/packem_shared/{transliterate-CYnKKT8f.js → transliterate-CKt9VK7D.js} +10 -12
- package/dist/packem_shared/{types-Daae0hGf.d.ts → types.d-BVNv675q.d.ts} +18 -21
- package/dist/packem_shared/{types-CfPsw9ix.d.ts → types.d-DfgbcNKh.d.ts} +19 -21
- package/dist/slice.d.ts +5 -8
- package/dist/slice.js +9 -7
- package/dist/slugify.d.ts +1 -3
- package/dist/slugify.js +1 -1
- package/dist/test/utils.d.ts +20 -22
- package/dist/test/utils.js +2 -2
- package/dist/test/vitest.d.ts +3 -6
- package/dist/truncate.d.ts +7 -10
- package/dist/truncate.js +49 -26
- package/dist/utilities.d.ts +2 -4
- package/dist/utilities.js +6 -8
- package/dist/word-similarity-sort.d.ts +3 -5
- package/dist/word-wrap.d.ts +9 -11
- package/dist/word-wrap.js +37 -35
- package/package.json +2 -2
- package/dist/packem_shared/closestN-BREy4E7C.js +0 -19
- package/dist/packem_shared/lru-cache-B_t27XwI.d.ts +0 -14
|
@@ -0,0 +1,33 @@
|
|
|
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 };
|
|
@@ -0,0 +1,10 @@
|
|
|
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 };
|
|
@@ -0,0 +1,104 @@
|
|
|
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 };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
declare class LRUCache<K, V> {
|
|
2
|
+
private readonly capacity;
|
|
3
|
+
private readonly cache;
|
|
4
|
+
private keyOrder;
|
|
5
|
+
constructor(capacity: number);
|
|
6
|
+
get(key: K): V | undefined;
|
|
7
|
+
has(key: K): boolean;
|
|
8
|
+
set(key: K, value: V): void;
|
|
9
|
+
delete(key: K): void;
|
|
10
|
+
clear(): void;
|
|
11
|
+
size(): number;
|
|
12
|
+
}
|
|
13
|
+
export { LRUCache as L };
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
const RE_GERMAN_DOUBLE_S = /(?<![a-zß])SS(?![a-z])/g;
|
|
1
2
|
const normalizeGermanEszett = (value) => (
|
|
2
3
|
// Replace "SS" with "ß" only when both letters are uppercase
|
|
3
4
|
// This uses a positive lookbehind to ensure we don't convert "ss" or "Ss"
|
|
4
|
-
value.replaceAll(
|
|
5
|
+
value.replaceAll(RE_GERMAN_DOUBLE_S, "ß")
|
|
5
6
|
);
|
|
6
7
|
|
|
7
8
|
export { normalizeGermanEszett as n };
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
const RE_REPLACEMENT_REGEX = /\$([\d&$`'])/g;
|
|
2
|
+
const RE_REPLACEMENT_STRING = /\$(\d+|&|\$)/g;
|
|
1
3
|
const mergeIntervals = (intervals) => {
|
|
2
4
|
if (intervals.length === 0) {
|
|
3
5
|
return [];
|
|
@@ -23,9 +25,6 @@ const replaceString = (source, searches, ignoreRanges) => {
|
|
|
23
25
|
const potentialMatches = [];
|
|
24
26
|
let matchIdCounter = 0;
|
|
25
27
|
for (const item of searches) {
|
|
26
|
-
if (!item || item.length < 2) {
|
|
27
|
-
continue;
|
|
28
|
-
}
|
|
29
28
|
const [searchKey, replacementValue] = item;
|
|
30
29
|
if (replacementValue === void 0) {
|
|
31
30
|
continue;
|
|
@@ -41,7 +40,7 @@ const replaceString = (source, searches, ignoreRanges) => {
|
|
|
41
40
|
searchPattern.lastIndex += 1;
|
|
42
41
|
}
|
|
43
42
|
const end = start + original.length - 1;
|
|
44
|
-
const finalReplacement = replacementValue.replaceAll(
|
|
43
|
+
const finalReplacement = replacementValue.replaceAll(RE_REPLACEMENT_REGEX, (substringFound, capturedSymbolOrDigits) => {
|
|
45
44
|
if (capturedSymbolOrDigits === "&") {
|
|
46
45
|
return original;
|
|
47
46
|
}
|
|
@@ -71,7 +70,7 @@ const replaceString = (source, searches, ignoreRanges) => {
|
|
|
71
70
|
const original = searchKey;
|
|
72
71
|
const end = start + original.length - 1;
|
|
73
72
|
const mockMatch = Object.assign([original], { index: start, input: source });
|
|
74
|
-
const finalReplacement = replacementValue.replaceAll(
|
|
73
|
+
const finalReplacement = replacementValue.replaceAll(RE_REPLACEMENT_STRING, (substringFound, capturedSymbolOrDigits) => {
|
|
75
74
|
if (capturedSymbolOrDigits === "&") {
|
|
76
75
|
return original;
|
|
77
76
|
}
|
|
@@ -79,7 +78,7 @@ const replaceString = (source, searches, ignoreRanges) => {
|
|
|
79
78
|
return "$";
|
|
80
79
|
}
|
|
81
80
|
const groupIndex = Number.parseInt(capturedSymbolOrDigits, 10);
|
|
82
|
-
if (
|
|
81
|
+
if (groupIndex > 0 && groupIndex < mockMatch.length) {
|
|
83
82
|
return mockMatch[groupIndex] ?? "";
|
|
84
83
|
}
|
|
85
84
|
return substringFound;
|
|
@@ -99,20 +98,21 @@ const replaceString = (source, searches, ignoreRanges) => {
|
|
|
99
98
|
}
|
|
100
99
|
return b.end - a.end;
|
|
101
100
|
});
|
|
102
|
-
const sortedIgnores =
|
|
101
|
+
const sortedIgnores = ignoreRanges.toSorted((a, b) => a[0] - b[0]);
|
|
103
102
|
const mergedIgnores = mergeIntervals(sortedIgnores);
|
|
104
103
|
const processedChars = source.split("").map((char, index) => {
|
|
105
104
|
return {
|
|
106
|
-
appliedMatchId:
|
|
105
|
+
appliedMatchId: void 0,
|
|
107
106
|
char,
|
|
108
107
|
index,
|
|
109
|
-
insertBeforeReplacement:
|
|
108
|
+
insertBeforeReplacement: void 0,
|
|
110
109
|
isIgnored: false,
|
|
111
110
|
isMatchStart: false,
|
|
112
|
-
matchReplacement:
|
|
111
|
+
matchReplacement: void 0
|
|
113
112
|
};
|
|
114
113
|
});
|
|
115
|
-
for (const
|
|
114
|
+
for (const mergedIgnore of mergedIgnores) {
|
|
115
|
+
const range = mergedIgnore;
|
|
116
116
|
for (let index = range[0]; index <= range[1]; index++) {
|
|
117
117
|
if (processedChars[index]) {
|
|
118
118
|
processedChars[index].isIgnored = true;
|
|
@@ -120,7 +120,8 @@ const replaceString = (source, searches, ignoreRanges) => {
|
|
|
120
120
|
}
|
|
121
121
|
}
|
|
122
122
|
let insertionAfterEnd = "";
|
|
123
|
-
for (const
|
|
123
|
+
for (const potentialMatch of potentialMatches) {
|
|
124
|
+
const match = potentialMatch;
|
|
124
125
|
if (match.original.length === 0 && match.start >= 0 && match.start <= processedChars.length) {
|
|
125
126
|
const targetIndex = match.start;
|
|
126
127
|
if (processedChars[targetIndex]) {
|
|
@@ -133,13 +134,14 @@ const replaceString = (source, searches, ignoreRanges) => {
|
|
|
133
134
|
}
|
|
134
135
|
}
|
|
135
136
|
}
|
|
136
|
-
for (const
|
|
137
|
+
for (const potentialMatch of potentialMatches) {
|
|
138
|
+
const match = potentialMatch;
|
|
137
139
|
if (match.original.length === 0) {
|
|
138
140
|
continue;
|
|
139
141
|
}
|
|
140
142
|
let canApply = true;
|
|
141
143
|
for (let index = match.start; index <= match.end; index++) {
|
|
142
|
-
if (!processedChars[index] || processedChars[index].isIgnored || processedChars[index].appliedMatchId !==
|
|
144
|
+
if (!processedChars[index] || processedChars[index].isIgnored || processedChars[index].appliedMatchId !== void 0) {
|
|
143
145
|
canApply = false;
|
|
144
146
|
break;
|
|
145
147
|
}
|
|
@@ -160,10 +162,10 @@ const replaceString = (source, searches, ignoreRanges) => {
|
|
|
160
162
|
let currentIndex = 0;
|
|
161
163
|
while (currentIndex < processedChars.length) {
|
|
162
164
|
const pChar = processedChars[currentIndex];
|
|
163
|
-
if (pChar.insertBeforeReplacement !==
|
|
165
|
+
if (pChar.insertBeforeReplacement !== void 0) {
|
|
164
166
|
result += pChar.insertBeforeReplacement;
|
|
165
167
|
}
|
|
166
|
-
if (pChar.isMatchStart && pChar.appliedMatchId !==
|
|
168
|
+
if (pChar.isMatchStart && pChar.appliedMatchId !== void 0) {
|
|
167
169
|
result += pChar.matchReplacement ?? "";
|
|
168
170
|
let matchEndIndex = currentIndex;
|
|
169
171
|
for (let index = currentIndex + 1; index < processedChars.length; index++) {
|
|
@@ -174,7 +176,7 @@ const replaceString = (source, searches, ignoreRanges) => {
|
|
|
174
176
|
}
|
|
175
177
|
}
|
|
176
178
|
currentIndex = matchEndIndex + 1;
|
|
177
|
-
} else if (pChar.appliedMatchId ===
|
|
179
|
+
} else if (pChar.appliedMatchId === void 0) {
|
|
178
180
|
result += pChar.char;
|
|
179
181
|
currentIndex += 1;
|
|
180
182
|
} else {
|
|
@@ -0,0 +1,20 @@
|
|
|
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 };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import replaceString from './replaceString-
|
|
1
|
+
import { H as RE_THAI } from './constants-BsZS5f0z.js';
|
|
2
|
+
import replaceString from './replaceString-Ce8X2ZQ-.js';
|
|
3
3
|
import { findStringOccurrences, hasPunctuationOrSpace, hasChinese } from '../utilities.js';
|
|
4
4
|
|
|
5
5
|
const UNICODE_BLOCK_0000_00FF = [
|
|
@@ -47618,8 +47618,9 @@ const formatReplaceOption = (option) => {
|
|
|
47618
47618
|
return structuredClone(option);
|
|
47619
47619
|
}
|
|
47620
47620
|
const replaceArray = [];
|
|
47621
|
-
|
|
47622
|
-
|
|
47621
|
+
const keys = Object.keys(option);
|
|
47622
|
+
for (const key of keys) {
|
|
47623
|
+
if (Object.hasOwn(option, key)) {
|
|
47623
47624
|
const value = option[key];
|
|
47624
47625
|
if (typeof value === "string") {
|
|
47625
47626
|
replaceArray.push([key, value]);
|
|
@@ -47630,7 +47631,8 @@ const formatReplaceOption = (option) => {
|
|
|
47630
47631
|
};
|
|
47631
47632
|
const applyThaiRomanization = (input) => {
|
|
47632
47633
|
let output = input;
|
|
47633
|
-
for (
|
|
47634
|
+
for (let entryIndex = 0; entryIndex < THAI_REPLACEMENT.length; entryIndex += 1) {
|
|
47635
|
+
const entry = THAI_REPLACEMENT[entryIndex];
|
|
47634
47636
|
const [search, replace, type] = entry;
|
|
47635
47637
|
if (typeof search !== "string" || typeof replace !== "string") {
|
|
47636
47638
|
continue;
|
|
@@ -47687,8 +47689,6 @@ const transliterate = (source, options) => {
|
|
|
47687
47689
|
const codePoint = input.codePointAt(index);
|
|
47688
47690
|
if (codePoint === void 0) {
|
|
47689
47691
|
char = input[index];
|
|
47690
|
-
charLength = 1;
|
|
47691
|
-
s = opt.unknown;
|
|
47692
47692
|
} else {
|
|
47693
47693
|
char = String.fromCodePoint(codePoint);
|
|
47694
47694
|
charLength = char.length;
|
|
@@ -47715,7 +47715,7 @@ const transliterate = (source, options) => {
|
|
|
47715
47715
|
s = opt.unknown;
|
|
47716
47716
|
} else {
|
|
47717
47717
|
const codePointString = String(currentActualCodePoint);
|
|
47718
|
-
const found = Object.
|
|
47718
|
+
const found = Object.hasOwn(currentCharmap, codePointString);
|
|
47719
47719
|
if (found) {
|
|
47720
47720
|
s = currentCharmap[codePointString];
|
|
47721
47721
|
} else if (isCurrentCharChinese) {
|
|
@@ -47724,9 +47724,7 @@ const transliterate = (source, options) => {
|
|
|
47724
47724
|
s = opt.unknown;
|
|
47725
47725
|
}
|
|
47726
47726
|
}
|
|
47727
|
-
|
|
47728
|
-
s = opt.unknown;
|
|
47729
|
-
}
|
|
47727
|
+
s ??= opt.unknown;
|
|
47730
47728
|
}
|
|
47731
47729
|
const determinedCharWasChinese = !isIgnored && isCurrentCharChinese;
|
|
47732
47730
|
if (opt.fixChineseSpacing && !isIgnored) {
|
|
@@ -47738,7 +47736,7 @@ const transliterate = (source, options) => {
|
|
|
47738
47736
|
} else {
|
|
47739
47737
|
lastCharWasChinese = false;
|
|
47740
47738
|
}
|
|
47741
|
-
result += s
|
|
47739
|
+
result += s;
|
|
47742
47740
|
index += charLength;
|
|
47743
47741
|
}
|
|
47744
47742
|
input = result;
|
|
@@ -4,17 +4,16 @@ type SliceStartType<T extends string, StartIndex extends number, Result extends
|
|
|
4
4
|
type InternalEndsWithType<T extends string, S extends string, P extends number> = All<[IsStringLiteral<S>, IsNumberLiteral<P>]> extends true ? Math.IsNegative<P> extends false ? P extends Length<T> ? IsStringLiteral<T> extends true ? S extends Slice<T, Math.Subtract<Length<T>, Length<S>>, Length<T>> ? true : false : EndsWithNoPositionType<Slice<T, 0, P>, S> : EndsWithNoPositionType<Slice<T, 0, P>, S> : false : boolean;
|
|
5
5
|
type EndsWithNoPositionType<T extends string, S extends string> = StartsWith<Reverse<T>, Reverse<S>>;
|
|
6
6
|
declare namespace Math {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
type Subtract<A extends number, B extends number> = number extends A | B ? number : TupleOf<A> extends [...infer U, ...TupleOf<B>] ? U["length"] : 0;
|
|
8
|
+
type IsNegative<T extends number> = number extends T ? boolean : `${T}` extends `-${number}` ? true : false;
|
|
9
|
+
type Abs<T extends number> = `${T}` extends `-${infer U extends number}` ? U : T;
|
|
10
|
+
type GetPositiveIndex<T extends string, I extends number> = IsNegative<I> extends false ? I : Subtract<Length<T>, Abs<I>>;
|
|
11
11
|
}
|
|
12
|
-
|
|
13
12
|
type IsNumberLiteral<T extends number> = [T] extends [number] ? ([number] extends [T] ? false : true) : false;
|
|
14
13
|
type IsBooleanLiteral<T extends boolean> = [T] extends [boolean] ? ([boolean] extends [T] ? false : true) : false;
|
|
15
14
|
type Reverse<T extends string, Accumulator extends string = ""> = T extends `${infer Head}${infer Tail}` ? Reverse<Tail, `${Head}${Accumulator}`> : Accumulator extends "" ? T : `${T}${Accumulator}`;
|
|
16
15
|
type Any<BoolArray extends boolean[]> = BoolArray extends [infer Head extends boolean, ...infer Rest extends boolean[]] ? IsBooleanLiteral<Head> extends true ? Head extends true ? true : Any<Rest> : Any<Rest> : false;
|
|
17
|
-
type All<BoolArray extends boolean[]> = IsBooleanLiteral<BoolArray[number]> extends true ? BoolArray extends [infer Head extends boolean, ...infer Rest extends boolean[]] ? Head extends true ?
|
|
16
|
+
type All<BoolArray extends boolean[]> = IsBooleanLiteral<BoolArray[number]> extends true ? BoolArray extends [infer Head extends boolean, ...infer Rest extends boolean[]] ? Head extends true ? All<Rest> : false : true : false;
|
|
18
17
|
type IsStringLiteral<T extends string> = [T] extends [string] ? [string] extends [T] ? false : Uppercase<T> extends Uppercase<Lowercase<T>> ? Lowercase<T> extends Lowercase<Uppercase<T>> ? true : false : false : false;
|
|
19
18
|
type IsStringLiteralArray<StringArray extends ReadonlyArray<string>> = IsStringLiteral<StringArray[number]> extends true ? true : false;
|
|
20
19
|
type CharAt<T extends string, Index extends number> = All<[IsStringLiteral<T>, IsNumberLiteral<Index>]> extends true ? Split<T>[Index] : string;
|
|
@@ -43,22 +42,20 @@ type OptionReplaceArray = [RegExp | string, string | undefined][];
|
|
|
43
42
|
type OptionReplaceObject = Record<string, string>;
|
|
44
43
|
type OptionReplaceCombined = OptionReplaceArray | OptionReplaceObject;
|
|
45
44
|
interface OptionsTransliterate {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
45
|
+
fixChineseSpacing?: boolean;
|
|
46
|
+
ignore?: string[];
|
|
47
|
+
replaceAfter?: OptionReplaceCombined;
|
|
48
|
+
replaceBefore?: OptionReplaceCombined;
|
|
49
|
+
trim?: boolean;
|
|
50
|
+
unknown?: string;
|
|
52
51
|
}
|
|
53
52
|
type Charmap = Record<string, string | undefined>;
|
|
54
53
|
interface SlugifyOptions extends OptionsTransliterate {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
54
|
+
allowedChars?: string;
|
|
55
|
+
fixChineseSpacing?: boolean;
|
|
56
|
+
lowercase?: boolean;
|
|
57
|
+
separator?: string;
|
|
58
|
+
transliterate?: boolean;
|
|
59
|
+
uppercase?: boolean;
|
|
61
60
|
}
|
|
62
|
-
|
|
63
|
-
export { Math as M };
|
|
64
|
-
export type { All as A, CharAt as C, EndsWith as E, Includes as I, Join as J, Length as L, NodeLocale as N, OptionReplaceArray as O, PadEnd as P, Replace as R, Slice as S, ToLowerCase as T, Concat as a, PadStart as b, ReplaceAll as c, Split as d, StartsWith as e, ToUpperCase as f, Trim as g, TrimEnd as h, TrimStart as i, SlugifyOptions as j, IsStringLiteral as k, IntervalArray as l, OptionsTransliterate as m, Any as n, Charmap as o, Interval as p, IsBooleanLiteral as q, IsNumberLiteral as r, IsStringLiteralArray as s, OptionReplaceCombined as t, OptionReplaceObject as u, Repeat as v, Reverse as w };
|
|
61
|
+
export { All as A, CharAt as C, EndsWith as E, IsStringLiteral as I, Join as J, Length as L, Math as M, NodeLocale as N, OptionReplaceArray as O, PadEnd as P, Repeat as R, SlugifyOptions as S, ToLowerCase as T, IntervalArray as a, OptionsTransliterate as b, Any as c, Charmap as d, Concat as e, Includes as f, Interval as g, IsBooleanLiteral as h, IsNumberLiteral as i, IsStringLiteralArray as j, OptionReplaceCombined as k, OptionReplaceObject as l, PadStart as m, Replace as n, ReplaceAll as o, Reverse as p, Slice as q, Split as r, StartsWith as s, ToUpperCase as t, Trim as u, TrimEnd as v, TrimStart as w };
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { L as LRUCache } from
|
|
3
|
-
|
|
1
|
+
import { I as IsStringLiteral, N as NodeLocale } from "./types.d-BVNv675q.js";
|
|
2
|
+
import { L as LRUCache } from "./lru-cache.d-BsP6kbVJ.js";
|
|
4
3
|
type SplitterCharacter = " " | "_" | "-" | "." | "/";
|
|
5
4
|
type LastOfArray<T extends any[]> = T extends [...any, infer R] ? R : never;
|
|
6
5
|
type RemoveLastOfArray<T extends any[]> = T extends [...infer F, any] ? F : never;
|
|
@@ -10,17 +9,17 @@ type SameLetterCase<X extends string, Y extends string> = IsUpperCase<X> extends
|
|
|
10
9
|
type FirstOfString<S extends string> = S extends `${infer F}${string}` ? F : never;
|
|
11
10
|
type RemoveFirstOfString<S extends string> = S extends `${string}${infer R}` ? R : never;
|
|
12
11
|
interface LocaleOptions {
|
|
13
|
-
|
|
12
|
+
locale?: NodeLocale;
|
|
14
13
|
}
|
|
15
14
|
interface CaseOptions extends LocaleOptions {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
15
|
+
cache?: boolean;
|
|
16
|
+
cacheStore?: LRUCache<string, string>;
|
|
17
|
+
handleAnsi?: boolean;
|
|
18
|
+
handleEmoji?: boolean;
|
|
19
|
+
knownAcronyms?: ReadonlyArray<string>;
|
|
20
|
+
normalize?: boolean;
|
|
21
|
+
stripAnsi?: boolean;
|
|
22
|
+
stripEmoji?: boolean;
|
|
24
23
|
}
|
|
25
24
|
type CamelCase<T extends string> = IsStringLiteral<T> extends true ? T extends `${infer F}_${infer R}` ? `${Lowercase<F>}${Capitalize<CamelCase<R>>}` : T extends `${infer F}-${infer R}` ? `${Lowercase<F>}${Capitalize<CamelCase<R>>}` : T extends `${infer F} ${infer R}` ? `${Lowercase<F>}${Capitalize<CamelCase<R>>}` : Lowercase<T> : string;
|
|
26
25
|
type PascalCase<T extends string> = IsStringLiteral<T> extends true ? Capitalize<CamelCase<T>> : string;
|
|
@@ -33,27 +32,26 @@ type UpperFirst<T extends string> = IsStringLiteral<T> extends true ? (T extends
|
|
|
33
32
|
type LowerFirst<T extends string> = IsStringLiteral<T> extends true ? (T extends `${infer F}${infer R}` ? `${Lowercase<F>}${R}` : T) : string;
|
|
34
33
|
type FlipCase<T extends string> = IsStringLiteral<T> extends true ? T extends `${infer C}${infer Rest}` ? `${C extends Uppercase<C> ? Lowercase<C> : Uppercase<C>}${FlipCase<Rest>}` : T : string;
|
|
35
34
|
type DotCase<T extends string> = T & {
|
|
36
|
-
|
|
35
|
+
__dot_case__: never;
|
|
37
36
|
};
|
|
38
37
|
type PathCase<T extends string> = T & {
|
|
39
|
-
|
|
38
|
+
__path_case__: never;
|
|
40
39
|
};
|
|
41
40
|
type NoCase<T extends string> = T & {
|
|
42
|
-
|
|
41
|
+
__no_case__: never;
|
|
43
42
|
};
|
|
44
43
|
type ConstantCase<T extends string> = T & {
|
|
45
|
-
|
|
44
|
+
__constant_case__: never;
|
|
46
45
|
};
|
|
47
46
|
type CapitalCase<T extends string> = T & {
|
|
48
|
-
|
|
47
|
+
__capital_case__: never;
|
|
49
48
|
};
|
|
50
49
|
type SentenceCase<T extends string> = T & {
|
|
51
|
-
|
|
50
|
+
__sentence_case__: never;
|
|
52
51
|
};
|
|
53
52
|
type PascalSnakeCase<T extends string> = T & {
|
|
54
|
-
|
|
53
|
+
__pascal_snake_case__: never;
|
|
55
54
|
};
|
|
56
55
|
type IdentifyCase<T extends string> = IsStringLiteral<T> extends true ? T extends Lowercase<T> ? T extends `${string}_${string}` ? "snake" : T extends `${string}-${string}` ? "kebab" : T extends `${string}${string}` ? "flat" : "lower" : T extends Uppercase<T> ? "upper" : T extends Capitalize<string> ? T extends `${Uppercase<string>}${string}` ? T extends `${string}-${string}` ? "train" : "pascal" : T extends `${Lowercase<string>}${Capitalize<string>}` ? "camel" : T extends `${Capitalize<string>} ${Lowercase<string>}` ? "title" : "mixed" : "mixed" : string;
|
|
57
56
|
type SplitByCase<T, Separator extends string = SplitterCharacter, Accumulator extends unknown[] = []> = string extends Separator ? string[] : T extends `${infer F}${infer R}` ? [LastOfArray<Accumulator>] extends [never] ? SplitByCase<R, Separator, [F]> : LastOfArray<Accumulator> extends string ? R extends "" ? SplitByCase<R, Separator, [...RemoveLastOfArray<Accumulator>, `${LastOfArray<Accumulator>}${F}`]> : SameLetterCase<F, FirstOfString<R>> extends true ? F extends Separator ? FirstOfString<R> extends Separator ? SplitByCase<R, Separator, [...Accumulator, ""]> : IsUpperCase<FirstOfString<R>> extends true ? SplitByCase<RemoveFirstOfString<R>, Separator, [...Accumulator, FirstOfString<R>]> : SplitByCase<R, Separator, [...Accumulator, ""]> : SplitByCase<R, Separator, [...RemoveLastOfArray<Accumulator>, `${LastOfArray<Accumulator>}${F}`]> : IsLowerCase<F> extends true ? SplitByCase<RemoveFirstOfString<R>, Separator, [...RemoveLastOfArray<Accumulator>, `${LastOfArray<Accumulator>}${F}`, FirstOfString<R>]> : SplitByCase<R, Separator, [...Accumulator, F]> : never : Accumulator extends [] ? T extends "" ? [] : string[] : Accumulator;
|
|
58
|
-
|
|
59
|
-
export type { CaseOptions as C, DotCase as D, FlatCase as F, IdentifyCase as I, KebabCase as K, LocaleOptions as L, NoCase as N, PascalCase as P, SentenceCase as S, TitleCase as T, UpperFirst as U, CamelCase as a, CapitalCase as b, ConstantCase as c, FlipCase as d, LowerFirst as e, PascalSnakeCase as f, PathCase as g, SnakeCase as h, SplitByCase as i, TrainCase as j };
|
|
57
|
+
export { CaseOptions as C, DotCase as D, FlatCase as F, IdentifyCase as I, KebabCase as K, LocaleOptions as L, NoCase as N, PascalCase as P, SentenceCase as S, TitleCase as T, UpperFirst as U, CamelCase as a, CapitalCase as b, ConstantCase as c, FlipCase as d, LowerFirst as e, PascalSnakeCase as f, PathCase as g, SnakeCase as h, SplitByCase as i, TrainCase as j };
|
package/dist/slice.d.ts
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
import { StringWidthOptions } from
|
|
2
|
-
import
|
|
3
|
-
|
|
1
|
+
import { StringWidthOptions } from "./get-string-width.js";
|
|
2
|
+
import "./get-string-truncated-width.js";
|
|
4
3
|
type SliceOptions = {
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
segmenter?: Intl.Segmenter;
|
|
5
|
+
width?: StringWidthOptions;
|
|
7
6
|
};
|
|
8
7
|
declare const slice: (inputString: string, startIndex?: number, endIndex?: number, options?: SliceOptions) => string;
|
|
9
|
-
|
|
10
|
-
export { slice };
|
|
11
|
-
export type { SliceOptions };
|
|
8
|
+
export { SliceOptions, slice };
|
package/dist/slice.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { j as RE_VALID_ANSI_PAIRS, k as RE_VALID_HYPERLINKS, g as RE_ANSI } from './packem_shared/constants-BsZS5f0z.js';
|
|
2
2
|
import { getStringWidth } from './get-string-width.js';
|
|
3
3
|
import LRUCache from './packem_shared/LRUCache-3r3SovvR.js';
|
|
4
4
|
|
|
5
5
|
const segmentCache = new LRUCache(100);
|
|
6
6
|
const defaultSegmenter = new Intl.Segmenter("en", { granularity: "grapheme" });
|
|
7
|
+
const RE_ASCII_ONLY = /^[\u0000-\u007F]*$/;
|
|
7
8
|
const ANSI_RESET_CODES = /* @__PURE__ */ new Set([
|
|
8
9
|
"0",
|
|
9
10
|
// Full reset
|
|
@@ -70,8 +71,8 @@ const FORMAT_STYLES = [
|
|
|
70
71
|
];
|
|
71
72
|
const findFirstPositionOfAny = (input, substrings) => {
|
|
72
73
|
let firstPos = -1;
|
|
73
|
-
for (const
|
|
74
|
-
const pos = input.indexOf(
|
|
74
|
+
for (const sub of substrings) {
|
|
75
|
+
const pos = input.indexOf(sub);
|
|
75
76
|
if (pos !== -1 && (firstPos === -1 || pos < firstPos)) {
|
|
76
77
|
firstPos = pos;
|
|
77
78
|
}
|
|
@@ -271,10 +272,10 @@ const processIntoStyledSegments = (input, options) => {
|
|
|
271
272
|
}
|
|
272
273
|
if (needsForegroundClose && needsBackgroundClose && input.includes("\x1B[39m") && input.includes("\x1B[49m")) {
|
|
273
274
|
if (input.indexOf("\x1B[39m") < input.indexOf("\x1B[49m")) {
|
|
274
|
-
closingParts.length -=
|
|
275
|
+
closingParts.length -= 2;
|
|
275
276
|
closingParts.push("\x1B[39m", "\x1B[49m");
|
|
276
277
|
} else if (input.indexOf("\x1B[49m") < input.indexOf("\x1B[39m")) {
|
|
277
|
-
closingParts.length -=
|
|
278
|
+
closingParts.length -= 2;
|
|
278
279
|
closingParts.push("\x1B[49m", "\x1B[39m");
|
|
279
280
|
}
|
|
280
281
|
}
|
|
@@ -284,7 +285,8 @@ const processIntoStyledSegments = (input, options) => {
|
|
|
284
285
|
style
|
|
285
286
|
};
|
|
286
287
|
}).filter((item) => item.position >= 0).toSorted((a, b) => b.position - a.position);
|
|
287
|
-
for (const
|
|
288
|
+
for (const activeFormatStyle of activeFormatStyles) {
|
|
289
|
+
const item = activeFormatStyle;
|
|
288
290
|
if (closingSequences.includes(item.style.close)) {
|
|
289
291
|
closingParts.push(item.style.close);
|
|
290
292
|
}
|
|
@@ -350,7 +352,7 @@ const slice = (inputString, startIndex = 0, endIndex = Number.MAX_SAFE_INTEGER,
|
|
|
350
352
|
throw new RangeError("Negative indices aren't supported");
|
|
351
353
|
}
|
|
352
354
|
if (!inputString.includes("\x1B")) {
|
|
353
|
-
if (
|
|
355
|
+
if (RE_ASCII_ONLY.test(inputString)) {
|
|
354
356
|
return inputString.slice(startIndex, endIndex);
|
|
355
357
|
}
|
|
356
358
|
return fastSlice(inputString, startIndex, endIndex, config);
|
package/dist/slugify.d.ts
CHANGED
package/dist/slugify.js
CHANGED