@visulima/string 3.0.0-alpha.9 → 3.1.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/CHANGELOG.md +305 -0
- package/LICENSE.md +68 -3
- package/README.md +80 -2
- package/dist/align-text.d.ts +35 -0
- package/dist/align-text.js +2 -34
- package/dist/case/camel-case.d.ts +17 -3
- package/dist/case/camel-case.js +1 -55
- package/dist/case/capital-case.d.ts +14 -3
- package/dist/case/capital-case.js +1 -47
- package/dist/case/constant-case.d.ts +14 -3
- package/dist/case/constant-case.js +1 -7
- package/dist/case/dot-case.d.ts +14 -3
- package/dist/case/dot-case.js +1 -7
- package/dist/case/flat-case.d.ts +12 -3
- package/dist/case/flat-case.js +1 -7
- package/dist/case/flip-case.d.ts +16 -3
- package/dist/case/flip-case.js +1 -82
- package/dist/case/identify-case.d.ts +15 -3
- package/dist/case/identify-case.js +1 -66
- package/dist/case/index.d.ts +8 -3
- package/dist/case/index.js +1 -20
- package/dist/case/kebab-case.d.ts +25 -3
- package/dist/case/kebab-case.js +1 -55
- package/dist/case/lower-first.d.ts +13 -3
- package/dist/case/lower-first.js +1 -9
- package/dist/case/no-case.d.ts +14 -3
- package/dist/case/no-case.js +1 -7
- package/dist/case/pascal-case.d.ts +17 -3
- package/dist/case/pascal-case.js +1 -48
- package/dist/case/pascal-snake-case.d.ts +14 -3
- package/dist/case/pascal-snake-case.js +1 -28
- package/dist/case/path-case.d.ts +14 -3
- package/dist/case/path-case.js +1 -7
- package/dist/case/sentence-case.d.ts +14 -3
- package/dist/case/sentence-case.js +1 -54
- package/dist/case/snake-case.d.ts +14 -3
- package/dist/case/snake-case.js +1 -7
- package/dist/case/split-by-case.d.ts +29 -3
- package/dist/case/split-by-case.js +1 -763
- package/dist/case/title-case.d.ts +12 -3
- package/dist/case/title-case.js +1 -40
- package/dist/case/train-case.d.ts +14 -3
- package/dist/case/train-case.js +1 -40
- package/dist/case/upper-first.d.ts +13 -3
- 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 +37 -0
- package/dist/compare-similarity.js +1 -12
- package/dist/count-occurrences.d.ts +9 -0
- package/dist/count-occurrences.js +1 -0
- package/dist/direction.d.ts +7 -0
- package/dist/direction.js +1 -0
- package/dist/east-asian-width.d.ts +58 -0
- package/dist/east-asian-width.js +1 -0
- package/dist/excerpt.d.ts +25 -0
- package/dist/excerpt.js +53 -0
- 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/indent.d.ts +88 -0
- package/dist/indent.js +1 -0
- package/dist/index.d.ts +12 -20
- package/dist/index.js +1 -44
- package/dist/is-fullwidth-code-point.d.ts +7 -0
- package/dist/is-fullwidth-code-point.js +1 -0
- package/dist/levenshtein.d.ts +25 -0
- package/dist/levenshtein.js +1 -0
- package/dist/native-string-types.d.ts +241 -18
- package/dist/outdent.d.ts +74 -0
- package/dist/outdent.js +1 -109
- package/dist/packem_shared/_isFullWidth-Dqc3MWgl.js +1 -0
- package/dist/packem_shared/closest-C6YDQs4m.js +1 -0
- package/dist/packem_shared/constants-aPzGW29R.js +1 -0
- package/dist/packem_shared/dedent-CPjAYUXh.js +1 -0
- package/dist/packem_shared/eastAsianWidth-DJV8Kqd-.js +1 -0
- package/dist/packem_shared/generate-cache-key-B_0X7MKm.js +1 -0
- package/dist/packem_shared/indent-cz8WMI0e.js +1 -0
- package/dist/packem_shared/joinSegments-CaHT-45s.js +1 -0
- package/dist/packem_shared/lru-cache-BtMSrYQJ.js +1 -0
- package/dist/packem_shared/normalize-german-eszett-hNMwtGjd.js +1 -0
- package/dist/packem_shared/redent-ByOoJ6fN.js +1 -0
- package/dist/packem_shared/strip-vt-control-characters-BW1RglLp.js +1 -0
- package/dist/packem_shared/types.d-CMNqA5bi.d.ts +402 -0
- package/dist/packem_shared/types.d-LgsTR37y.d.ts +360 -0
- package/dist/replace-string.d.ts +10 -0
- package/dist/replace-string.js +1 -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/transliterate.d.ts +10 -0
- package/dist/transliterate.js +5 -0
- package/dist/truncate.d.ts +43 -0
- package/dist/truncate.js +1 -112
- package/dist/utilities.d.ts +28 -2
- 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 +70 -36
- 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/lru-cache.d-BsP6kbVJ.d.ts +0 -13
- 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,332 +1 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { g as RE_ANSI, h as RE_CONTROL, i as RE_EMOJI } from './packem_shared/constants-BsZS5f0z.js';
|
|
3
|
-
|
|
4
|
-
const charWidthCache = /* @__PURE__ */ new Map();
|
|
5
|
-
const RE_LATIN_CHARS = /(?:[\u0020-\u007E\u00A0-\u00FF](?!\uFE0F)){1,1000}/y;
|
|
6
|
-
const getCharType = (codePoint) => {
|
|
7
|
-
if (codePoint >= 32 && codePoint <= 126) {
|
|
8
|
-
return "latin";
|
|
9
|
-
}
|
|
10
|
-
if (codePoint === 8203 || codePoint === 8204 || codePoint === 8205 || codePoint === 8288) {
|
|
11
|
-
return "zero";
|
|
12
|
-
}
|
|
13
|
-
if (codePoint <= 31 || codePoint >= 127 && codePoint <= 159) {
|
|
14
|
-
return "control";
|
|
15
|
-
}
|
|
16
|
-
if (codePoint >= 160 && codePoint <= 255) {
|
|
17
|
-
return "latin";
|
|
18
|
-
}
|
|
19
|
-
if (codePoint >= 9472 && codePoint <= 9599) {
|
|
20
|
-
return "latin";
|
|
21
|
-
}
|
|
22
|
-
if (codePoint >= 4352 && codePoint <= 4607 || codePoint >= 11904 && codePoint <= 40959 || codePoint >= 44032 && codePoint <= 55215 || codePoint >= 63744 && codePoint <= 64255 || codePoint >= 65280 && codePoint <= 65519 && !(codePoint >= 65377 && codePoint <= 65439) || codePoint >= 12352 && codePoint <= 12543) {
|
|
23
|
-
return "wide";
|
|
24
|
-
}
|
|
25
|
-
if (codePoint === 8230) {
|
|
26
|
-
return "latin";
|
|
27
|
-
}
|
|
28
|
-
return "other";
|
|
29
|
-
};
|
|
30
|
-
const getCachedCharWidth = (codePoint, config) => {
|
|
31
|
-
const highBits = Math.floor(codePoint / 65536);
|
|
32
|
-
const lowBits = codePoint % 65536;
|
|
33
|
-
let lowMap = charWidthCache.get(highBits);
|
|
34
|
-
if (!lowMap) {
|
|
35
|
-
lowMap = /* @__PURE__ */ new Map();
|
|
36
|
-
charWidthCache.set(highBits, lowMap);
|
|
37
|
-
}
|
|
38
|
-
if (lowMap.has(lowBits)) {
|
|
39
|
-
return lowMap.get(lowBits);
|
|
40
|
-
}
|
|
41
|
-
let width;
|
|
42
|
-
if (getCharType(codePoint) === "latin") {
|
|
43
|
-
width = config.width.regular;
|
|
44
|
-
} else if (getCharType(codePoint) === "control") {
|
|
45
|
-
width = config.width.control;
|
|
46
|
-
} else if (getCharType(codePoint) === "wide") {
|
|
47
|
-
width = config.width.wide;
|
|
48
|
-
} else {
|
|
49
|
-
const eaw = eastAsianWidthType(codePoint);
|
|
50
|
-
switch (eaw) {
|
|
51
|
-
case "ambiguous": {
|
|
52
|
-
width = config.width.ambiguousIsNarrow ? config.width.regular : config.width.wide;
|
|
53
|
-
break;
|
|
54
|
-
}
|
|
55
|
-
case "fullwidth": {
|
|
56
|
-
width = config.width.fullWidth;
|
|
57
|
-
break;
|
|
58
|
-
}
|
|
59
|
-
case "wide": {
|
|
60
|
-
width = config.width.wide;
|
|
61
|
-
break;
|
|
62
|
-
}
|
|
63
|
-
default: {
|
|
64
|
-
width = config.width.regular;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
lowMap.set(lowBits, width);
|
|
69
|
-
return width;
|
|
70
|
-
};
|
|
71
|
-
const isCombiningCharacter = (codePoint) => {
|
|
72
|
-
if (codePoint >= 768 && codePoint <= 879 || codePoint >= 6832 && codePoint <= 6911 || codePoint >= 7616 && codePoint <= 7679 || codePoint >= 8400 && codePoint <= 8447 || codePoint >= 65056 && codePoint <= 65071) {
|
|
73
|
-
return true;
|
|
74
|
-
}
|
|
75
|
-
if (codePoint >= 917760 && codePoint <= 917999 || codePoint >= 65024 && codePoint <= 65039) {
|
|
76
|
-
return true;
|
|
77
|
-
}
|
|
78
|
-
if (codePoint >= 3633 && codePoint <= 3642 || codePoint >= 3655 && codePoint <= 3662 || codePoint >= 3761 && codePoint <= 3769 || codePoint >= 3771 && codePoint <= 3772 || codePoint >= 3784 && codePoint <= 3789) {
|
|
79
|
-
return true;
|
|
80
|
-
}
|
|
81
|
-
if (codePoint >= 2304 && codePoint <= 2307 || codePoint >= 2362 && codePoint <= 2383 || codePoint >= 2385 && codePoint <= 2391 || codePoint >= 2402 && codePoint <= 2403 || codePoint >= 2433 && codePoint <= 2435 || codePoint >= 2492 && codePoint <= 2500 || codePoint >= 2509 && codePoint <= 2509 || codePoint >= 2561 && codePoint <= 2563 || codePoint >= 2620 && codePoint <= 2637) {
|
|
82
|
-
return true;
|
|
83
|
-
}
|
|
84
|
-
if (codePoint >= 1611 && codePoint <= 1631 || codePoint >= 1648 && codePoint <= 1648 || codePoint >= 1750 && codePoint <= 1773 || codePoint >= 2276 && codePoint <= 2302) {
|
|
85
|
-
return true;
|
|
86
|
-
}
|
|
87
|
-
if (codePoint >= 1425 && codePoint <= 1469 || codePoint >= 1471 && codePoint <= 1471 || codePoint >= 1473 && codePoint <= 1474 || codePoint >= 1476 && codePoint <= 1477 || codePoint >= 1479 && codePoint <= 1479) {
|
|
88
|
-
return true;
|
|
89
|
-
}
|
|
90
|
-
if (codePoint >= 3893 && codePoint <= 3893 || codePoint >= 3895 && codePoint <= 3895 || codePoint >= 3897 && codePoint <= 3897 || codePoint >= 3953 && codePoint <= 3966 || codePoint >= 3968 && codePoint <= 3972 || codePoint >= 3974 && codePoint <= 3975) {
|
|
91
|
-
return true;
|
|
92
|
-
}
|
|
93
|
-
return codePoint >= 768 && codePoint <= 777 || codePoint >= 803 && codePoint <= 803;
|
|
94
|
-
};
|
|
95
|
-
const getStringTruncatedWidth = (input, options = {}) => {
|
|
96
|
-
if (!input || input.length === 0) {
|
|
97
|
-
return { ellipsed: false, index: 0, truncated: false, width: 0 };
|
|
98
|
-
}
|
|
99
|
-
const config = {
|
|
100
|
-
truncation: {
|
|
101
|
-
countAnsiEscapeCodes: options.countAnsiEscapeCodes ?? false,
|
|
102
|
-
ellipsis: options.ellipsis ?? "",
|
|
103
|
-
ellipsisWidth: options.ellipsisWidth ?? (options.ellipsis ? getStringTruncatedWidth(options.ellipsis, {
|
|
104
|
-
...options,
|
|
105
|
-
ellipsis: "",
|
|
106
|
-
ellipsisWidth: 0,
|
|
107
|
-
limit: Number.POSITIVE_INFINITY
|
|
108
|
-
}).width : 0),
|
|
109
|
-
limit: options.limit ?? Number.POSITIVE_INFINITY
|
|
110
|
-
},
|
|
111
|
-
width: {
|
|
112
|
-
ambiguousIsNarrow: options.ambiguousIsNarrow ?? false,
|
|
113
|
-
ansi: options.ansiWidth ?? 0,
|
|
114
|
-
control: options.controlWidth ?? 0,
|
|
115
|
-
emoji: options.emojiWidth ?? 2,
|
|
116
|
-
fullWidth: options.fullWidth ?? 2,
|
|
117
|
-
halfWidth: options.halfWidth ?? 1,
|
|
118
|
-
regular: options.regularWidth ?? 1,
|
|
119
|
-
tab: options.tabWidth ?? 8,
|
|
120
|
-
wide: options.wideWidth ?? 2
|
|
121
|
-
}
|
|
122
|
-
};
|
|
123
|
-
const truncationLimit = Math.max(0, config.truncation.limit - config.truncation.ellipsisWidth);
|
|
124
|
-
const { length } = input;
|
|
125
|
-
const useCaching = length > 1e4;
|
|
126
|
-
let index = 0;
|
|
127
|
-
let width = 0;
|
|
128
|
-
let truncationIndex = length;
|
|
129
|
-
let truncationEnabled = false;
|
|
130
|
-
const hasAnsi = input.includes("\x1B") || input.includes("");
|
|
131
|
-
while (index < length) {
|
|
132
|
-
if (hasAnsi && (input[index] === "\x1B" || input[index] === "")) {
|
|
133
|
-
if (input.startsWith("\x1B]8;;", index)) {
|
|
134
|
-
const BELL = "\x07";
|
|
135
|
-
const OSC8_CLOSER = `\x1B]8;;${BELL}`;
|
|
136
|
-
const OSC8_CLOSER_LEN = OSC8_CLOSER.length;
|
|
137
|
-
const endOfParametersIndex = input.indexOf(BELL, index + 5);
|
|
138
|
-
if (endOfParametersIndex === -1) ; else {
|
|
139
|
-
const startOfCloserIndex = input.indexOf(OSC8_CLOSER, endOfParametersIndex + 1);
|
|
140
|
-
if (startOfCloserIndex === -1) ; else {
|
|
141
|
-
const endOfSequenceIndex = startOfCloserIndex + OSC8_CLOSER_LEN;
|
|
142
|
-
const linkText = input.slice(endOfParametersIndex + 1, startOfCloserIndex);
|
|
143
|
-
const strippedLinkText = linkText.replace(RE_ANSI, "");
|
|
144
|
-
const linkTextWidthResult = getStringTruncatedWidth(strippedLinkText, {
|
|
145
|
-
ambiguousIsNarrow: config.width.ambiguousIsNarrow,
|
|
146
|
-
ansiWidth: config.width.ansi,
|
|
147
|
-
controlWidth: config.width.control,
|
|
148
|
-
countAnsiEscapeCodes: false,
|
|
149
|
-
// Never count ANSI in link text width
|
|
150
|
-
ellipsis: config.truncation.ellipsis,
|
|
151
|
-
ellipsisWidth: config.truncation.ellipsisWidth,
|
|
152
|
-
emojiWidth: config.width.emoji,
|
|
153
|
-
fullWidth: config.width.fullWidth,
|
|
154
|
-
halfWidth: config.width.halfWidth,
|
|
155
|
-
limit: Math.max(0, truncationLimit - width),
|
|
156
|
-
regularWidth: config.width.regular,
|
|
157
|
-
tabWidth: config.width.tab,
|
|
158
|
-
wideWidth: config.width.wide
|
|
159
|
-
});
|
|
160
|
-
const textWidth = linkTextWidthResult.width;
|
|
161
|
-
if (linkTextWidthResult.truncated) {
|
|
162
|
-
truncationEnabled = true;
|
|
163
|
-
truncationIndex = Math.min(truncationIndex, index);
|
|
164
|
-
} else if (width + textWidth > truncationLimit) {
|
|
165
|
-
truncationIndex = Math.min(truncationIndex, index);
|
|
166
|
-
truncationEnabled = true;
|
|
167
|
-
if (width + textWidth > config.truncation.limit) {
|
|
168
|
-
break;
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
width += textWidth;
|
|
172
|
-
index = endOfSequenceIndex;
|
|
173
|
-
if (truncationEnabled && width >= config.truncation.limit) {
|
|
174
|
-
break;
|
|
175
|
-
}
|
|
176
|
-
continue;
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
RE_ANSI.lastIndex = index;
|
|
181
|
-
if (RE_ANSI.test(input)) {
|
|
182
|
-
const ansiLength = RE_ANSI.lastIndex - index;
|
|
183
|
-
const ansiWidth = config.truncation.countAnsiEscapeCodes ? ansiLength : config.width.ansi;
|
|
184
|
-
if (width + ansiWidth > truncationLimit) {
|
|
185
|
-
truncationIndex = Math.min(truncationIndex, index);
|
|
186
|
-
if (width + ansiWidth > config.truncation.limit) {
|
|
187
|
-
truncationEnabled = true;
|
|
188
|
-
break;
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
width += ansiWidth;
|
|
192
|
-
index = RE_ANSI.lastIndex;
|
|
193
|
-
continue;
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
const charCode = input.codePointAt(index);
|
|
197
|
-
if (charCode === 8203 || charCode === 65279 || charCode >= 8288 && charCode <= 8292) {
|
|
198
|
-
index += 1;
|
|
199
|
-
continue;
|
|
200
|
-
}
|
|
201
|
-
if (charCode === 9) {
|
|
202
|
-
if (width + config.width.tab > truncationLimit) {
|
|
203
|
-
truncationIndex = Math.min(truncationIndex, index);
|
|
204
|
-
if (width + config.width.tab > config.truncation.limit) {
|
|
205
|
-
truncationEnabled = true;
|
|
206
|
-
break;
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
width += config.width.tab;
|
|
210
|
-
index += 1;
|
|
211
|
-
continue;
|
|
212
|
-
}
|
|
213
|
-
RE_LATIN_CHARS.lastIndex = index;
|
|
214
|
-
if (RE_LATIN_CHARS.test(input)) {
|
|
215
|
-
const latinLength = RE_LATIN_CHARS.lastIndex - index;
|
|
216
|
-
const latinWidth = latinLength * config.width.regular;
|
|
217
|
-
if (width + latinWidth > truncationLimit) {
|
|
218
|
-
const charsToLimit = Math.floor((truncationLimit - width) / config.width.regular);
|
|
219
|
-
truncationIndex = Math.min(truncationIndex, index + charsToLimit);
|
|
220
|
-
if (width + latinWidth > config.truncation.limit) {
|
|
221
|
-
truncationEnabled = true;
|
|
222
|
-
break;
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
width += latinWidth;
|
|
226
|
-
index = RE_LATIN_CHARS.lastIndex;
|
|
227
|
-
continue;
|
|
228
|
-
}
|
|
229
|
-
if (charCode <= 31 || charCode >= 127 && charCode <= 159) {
|
|
230
|
-
RE_CONTROL.lastIndex = index;
|
|
231
|
-
if (RE_CONTROL.test(input)) {
|
|
232
|
-
const controlLength = RE_CONTROL.lastIndex - index;
|
|
233
|
-
const controlWidth = controlLength * config.width.control;
|
|
234
|
-
if (width + controlWidth > truncationLimit) {
|
|
235
|
-
truncationIndex = Math.min(truncationIndex, index + Math.floor((truncationLimit - width) / config.width.control));
|
|
236
|
-
if (width + controlWidth > config.truncation.limit) {
|
|
237
|
-
truncationEnabled = true;
|
|
238
|
-
break;
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
width += controlWidth;
|
|
242
|
-
index = RE_CONTROL.lastIndex;
|
|
243
|
-
continue;
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
RE_EMOJI.lastIndex = index;
|
|
247
|
-
if (RE_EMOJI.test(input)) {
|
|
248
|
-
if (width + config.width.emoji > truncationLimit) {
|
|
249
|
-
truncationIndex = Math.min(truncationIndex, index);
|
|
250
|
-
if (width + config.width.emoji > config.truncation.limit) {
|
|
251
|
-
truncationEnabled = true;
|
|
252
|
-
break;
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
width += config.width.emoji;
|
|
256
|
-
index = RE_EMOJI.lastIndex;
|
|
257
|
-
continue;
|
|
258
|
-
}
|
|
259
|
-
const codePoint = input.codePointAt(index) ?? 0;
|
|
260
|
-
if (isCombiningCharacter(codePoint)) {
|
|
261
|
-
index += codePoint > 65535 ? 2 : 1;
|
|
262
|
-
continue;
|
|
263
|
-
}
|
|
264
|
-
let charWidth;
|
|
265
|
-
if (useCaching) {
|
|
266
|
-
charWidth = getCachedCharWidth(codePoint, config);
|
|
267
|
-
} else {
|
|
268
|
-
const charType = getCharType(codePoint);
|
|
269
|
-
switch (charType) {
|
|
270
|
-
case "control": {
|
|
271
|
-
charWidth = config.width.control;
|
|
272
|
-
break;
|
|
273
|
-
}
|
|
274
|
-
case "latin": {
|
|
275
|
-
charWidth = config.width.regular;
|
|
276
|
-
break;
|
|
277
|
-
}
|
|
278
|
-
case "wide": {
|
|
279
|
-
charWidth = config.width.wide;
|
|
280
|
-
break;
|
|
281
|
-
}
|
|
282
|
-
case "zero": {
|
|
283
|
-
charWidth = 0;
|
|
284
|
-
break;
|
|
285
|
-
}
|
|
286
|
-
default: {
|
|
287
|
-
const eaw = eastAsianWidthType(codePoint);
|
|
288
|
-
switch (eaw) {
|
|
289
|
-
case "ambiguous": {
|
|
290
|
-
charWidth = config.width.ambiguousIsNarrow ? config.width.regular : config.width.wide;
|
|
291
|
-
break;
|
|
292
|
-
}
|
|
293
|
-
case "fullwidth": {
|
|
294
|
-
charWidth = config.width.fullWidth;
|
|
295
|
-
break;
|
|
296
|
-
}
|
|
297
|
-
case "wide": {
|
|
298
|
-
charWidth = config.width.wide;
|
|
299
|
-
break;
|
|
300
|
-
}
|
|
301
|
-
default: {
|
|
302
|
-
charWidth = config.width.regular;
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
if (width + charWidth > truncationLimit) {
|
|
309
|
-
truncationIndex = Math.min(truncationIndex, index);
|
|
310
|
-
if (width + charWidth > config.truncation.limit) {
|
|
311
|
-
truncationEnabled = true;
|
|
312
|
-
break;
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
width += charWidth;
|
|
316
|
-
index += codePoint > 65535 ? 2 : 1;
|
|
317
|
-
}
|
|
318
|
-
let finalWidth = width;
|
|
319
|
-
let ellipsed = false;
|
|
320
|
-
if (truncationEnabled && config.truncation.limit >= config.truncation.ellipsisWidth) {
|
|
321
|
-
finalWidth = config.truncation.limit;
|
|
322
|
-
ellipsed = true;
|
|
323
|
-
}
|
|
324
|
-
return {
|
|
325
|
-
ellipsed,
|
|
326
|
-
index: truncationEnabled ? truncationIndex : length,
|
|
327
|
-
truncated: truncationEnabled,
|
|
328
|
-
width: finalWidth
|
|
329
|
-
};
|
|
330
|
-
};
|
|
331
|
-
|
|
332
|
-
export { getStringTruncatedWidth };
|
|
1
|
+
import{eastAsianWidthType as j}from"./packem_shared/eastAsianWidth-DJV8Kqd-.js";import{R as O,a as m,b as _}from"./packem_shared/constants-aPzGW29R.js";const E=new Map,y=i=>[i.ambiguousIsNarrow?1:0,i.control,i.fullWidth,i.regular,i.wide].join("|"),z=i=>{const t=y(i.width);let e=E.get(t);return e||(e=new Map,E.set(t,e)),e},b=new RegExp(O.source,"y"),x=new RegExp(_.source,"uy"),g=/(?:[\u0020-\u007E\u00A0-\u00FF](?!\uFE0F)){1,1000}/y,R=i=>i>=32&&i<=126?"latin":i===8203||i===8204||i===8205||i===8288?"zero":i<=31||i>=127&&i<=159?"control":i>=160&&i<=255||i>=9472&&i<=9599?"latin":i>=4352&&i<=4607||i>=11904&&i<=40959||i>=44032&&i<=55215||i>=63744&&i<=64255||i>=65280&&i<=65519&&!(i>=65377&&i<=65439)||i>=12352&&i<=12543?"wide":i===8230?"latin":"other",B=(i,t)=>{const e=z(t),s=Math.floor(i/65536),u=i%65536;let c=e.get(s);if(c||(c=new Map,e.set(s,c)),c.has(u))return c.get(u);let a;switch(R(i)){case"control":{a=t.width.control;break}case"latin":{a=t.width.regular;break}case"wide":{a=t.width.wide;break}case"zero":{a=0;break}default:switch(j(i)){case"ambiguous":{a=t.width.ambiguousIsNarrow?t.width.regular:t.width.wide;break}case"fullwidth":{a=t.width.fullWidth;break}case"wide":{a=t.width.wide;break}default:a=t.width.regular}}return c.set(u,a),a},P=i=>i>=768&&i<=879||i>=6832&&i<=6911||i>=7616&&i<=7679||i>=8400&&i<=8447||i>=65056&&i<=65071||i>=917760&&i<=917999||i>=65024&&i<=65039||i>=3633&&i<=3642||i>=3655&&i<=3662||i>=3761&&i<=3769||i>=3771&&i<=3772||i>=3784&&i<=3789||i>=2304&&i<=2307||i>=2362&&i<=2383||i>=2385&&i<=2391||i>=2402&&i<=2403||i>=2433&&i<=2435||i>=2492&&i<=2500||i>=2509&&i<=2509||i>=2561&&i<=2563||i>=2620&&i<=2637||i>=1611&&i<=1631||i>=1648&&i<=1648||i>=1750&&i<=1773||i>=2276&&i<=2302||i>=1425&&i<=1469||i>=1471&&i<=1471||i>=1473&&i<=1474||i>=1476&&i<=1477||i>=1479&&i<=1479||i>=3893&&i<=3893||i>=3895&&i<=3895||i>=3897&&i<=3897||i>=3953&&i<=3966||i>=3968&&i<=3972||i>=3974&&i<=3975?!0:i>=768&&i<=777||i>=803&&i<=803,A=(i,t={})=>{if(!i||i.length===0)return{ellipsed:!1,index:0,truncated:!1,width:0};const e={truncation:{countAnsiEscapeCodes:t.countAnsiEscapeCodes??!1,ellipsis:t.ellipsis??"",ellipsisWidth:t.ellipsisWidth??(t.ellipsis?A(t.ellipsis,{...t,ellipsis:"",ellipsisWidth:0,limit:Number.POSITIVE_INFINITY}).width:0),limit:t.limit??Number.POSITIVE_INFINITY},width:{ambiguousIsNarrow:t.ambiguousIsNarrow??!1,ansi:t.ansiWidth??0,control:t.controlWidth??0,emoji:t.emojiWidth??2,fullWidth:t.fullWidth??2,halfWidth:t.halfWidth??1,regular:t.regularWidth??1,tab:t.tabWidth??8,wide:t.wideWidth??2}},s=Math.max(0,e.truncation.limit-e.truncation.ellipsisWidth),{length:u}=i,c=u>1e4;let a=0,n=0,l=u,r=!1;const T=i.includes("\x1B")||i.includes("");for(;a<u;){if(T&&(i[a]==="\x1B"||i[a]==="")){if(i.startsWith("\x1B]8;;",a)){const o="\x1B]8;;\x07",h=o.length,W=i.indexOf("\x07",a+5);if(W!==-1){const p=i.indexOf(o,W+1);if(p!==-1){const F=p+h,C=i.slice(W+1,p).replace(O,""),N=A(C,{ambiguousIsNarrow:e.width.ambiguousIsNarrow,ansiWidth:e.width.ansi,controlWidth:e.width.control,countAnsiEscapeCodes:!1,ellipsis:e.truncation.ellipsis,ellipsisWidth:e.truncation.ellipsisWidth,emojiWidth:e.width.emoji,fullWidth:e.width.fullWidth,halfWidth:e.width.halfWidth,limit:Math.max(0,s-n),regularWidth:e.width.regular,tabWidth:e.width.tab,wideWidth:e.width.wide}),I=N.width;if(N.truncated)r=!0,l=Math.min(l,a);else if(n+I>s&&(l=Math.min(l,a),r=!0,n+I>e.truncation.limit))break;if(n+=I,a=F,r&&n>=e.truncation.limit)break;continue}}}if(b.lastIndex=a,b.test(i)){const o=b.lastIndex-a,h=e.truncation.countAnsiEscapeCodes?o:e.width.ansi;if(n+h>s&&(l=Math.min(l,a),n+h>e.truncation.limit)){r=!0;break}n+=h,a=b.lastIndex;continue}}const w=i.codePointAt(a);if(w===8203||w===65279||w>=8288&&w<=8292){a+=1;continue}if(w===9){if(n+e.width.tab>s&&(l=Math.min(l,a),n+e.width.tab>e.truncation.limit)){r=!0;break}n+=e.width.tab,a+=1;continue}if(g.lastIndex=a,g.test(i)){const o=(g.lastIndex-a)*e.width.regular;if(n+o>s){const h=e.width.regular>0?Math.floor((s-n)/e.width.regular):0;if(l=Math.min(l,a+h),n+o>e.truncation.limit){r=!0;break}}n+=o,a=g.lastIndex;continue}if((w<=31||w>=127&&w<=159)&&(m.lastIndex=a,m.test(i))){const o=(m.lastIndex-a)*e.width.control;if(n+o>s){const h=e.width.control>0?Math.floor((s-n)/e.width.control):0;if(l=Math.min(l,a+h),n+o>e.truncation.limit){r=!0;break}}n+=o,a=m.lastIndex;continue}if(x.lastIndex=a,x.test(i)){if(n+e.width.emoji>s&&(l=Math.min(l,a),n+e.width.emoji>e.truncation.limit)){r=!0;break}n+=e.width.emoji,a=x.lastIndex;continue}const f=i.codePointAt(a)??0;if(P(f)){a+=f>65535?2:1;continue}let d;if(c)d=B(f,e);else switch(R(f)){case"control":{d=e.width.control;break}case"latin":{d=e.width.regular;break}case"wide":{d=e.width.wide;break}case"zero":{d=0;break}default:switch(j(f)){case"ambiguous":{d=e.width.ambiguousIsNarrow?e.width.regular:e.width.wide;break}case"fullwidth":{d=e.width.fullWidth;break}case"wide":{d=e.width.wide;break}default:d=e.width.regular}}if(n+d>s&&(l=Math.min(l,a),n+d>e.truncation.limit)){r=!0;break}n+=d,a+=f>65535?2:1}let k=n,M=!1;return r&&e.truncation.limit>=e.truncation.ellipsisWidth&&(k=e.truncation.limit,M=!0),{ellipsed:M,index:r?l:u,truncated:r,width:k}};export{A as getStringTruncatedWidth};
|
|
@@ -1,4 +1,62 @@
|
|
|
1
1
|
import { StringTruncatedWidthOptions } from "./get-string-truncated-width.js";
|
|
2
|
+
/**
|
|
3
|
+
* Configuration options for string width calculation without truncation support.
|
|
4
|
+
* This type excludes truncation-related options from StringTruncatedWidthOptions.
|
|
5
|
+
* @example
|
|
6
|
+
* ```typescript
|
|
7
|
+
* // Basic usage with defaults
|
|
8
|
+
* const options: StringWidthOptions = {};
|
|
9
|
+
*
|
|
10
|
+
* // Custom character widths
|
|
11
|
+
* const options: StringWidthOptions = {
|
|
12
|
+
* regularWidth: 2,
|
|
13
|
+
* emojiWidth: 3,
|
|
14
|
+
* tabWidth: 4
|
|
15
|
+
* };
|
|
16
|
+
*
|
|
17
|
+
* // Unicode handling options
|
|
18
|
+
* const options: StringWidthOptions = {
|
|
19
|
+
* ambiguousIsNarrow: true,
|
|
20
|
+
* fullWidth: 2,
|
|
21
|
+
* wideWidth: 2
|
|
22
|
+
* };
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
2
25
|
type StringWidthOptions = Omit<StringTruncatedWidthOptions, "ellipsis" | "ellipsisWidth" | "limit">;
|
|
26
|
+
/**
|
|
27
|
+
* Calculate the visual width of a string, taking into account Unicode characters, emojis, and ANSI escape codes.
|
|
28
|
+
* @example
|
|
29
|
+
* ```typescript
|
|
30
|
+
* // Basic usage
|
|
31
|
+
* getStringWidth('hello');
|
|
32
|
+
* // => 5
|
|
33
|
+
*
|
|
34
|
+
* getStringWidth('👋 hello');
|
|
35
|
+
* // => 7
|
|
36
|
+
*
|
|
37
|
+
* // With custom character widths
|
|
38
|
+
* getStringWidth('hello', { regularWidth: 2 });
|
|
39
|
+
* // => 10
|
|
40
|
+
*
|
|
41
|
+
* getStringWidth('あいう', { ambiguousIsNarrow: true });
|
|
42
|
+
* // => 3
|
|
43
|
+
*
|
|
44
|
+
* // With combining characters
|
|
45
|
+
* getStringWidth('e\u0301'); // Latin e with acute
|
|
46
|
+
* // => 1
|
|
47
|
+
*
|
|
48
|
+
* getStringWidth('\u0e01\u0e31'); // Thai character with vowel mark
|
|
49
|
+
* // => 1
|
|
50
|
+
* ```
|
|
51
|
+
*
|
|
52
|
+
* Features:
|
|
53
|
+
* - Full Unicode support including combining marks
|
|
54
|
+
* - Accurate width calculation for emoji sequences
|
|
55
|
+
* - ANSI escape code handling
|
|
56
|
+
* - Customizable character widths
|
|
57
|
+
* @param input The string to calculate the width for
|
|
58
|
+
* @param options Configuration options for width calculation
|
|
59
|
+
* @returns The calculated visual width of the string
|
|
60
|
+
*/
|
|
3
61
|
declare const getStringWidth: (input: string, options?: StringWidthOptions) => number;
|
|
4
62
|
export { StringWidthOptions, getStringWidth };
|
package/dist/get-string-width.js
CHANGED
|
@@ -1,5 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
const getStringWidth = (input, options = {}) => getStringTruncatedWidth(input, { ...options, ellipsis: "", ellipsisWidth: 0, limit: Number.POSITIVE_INFINITY }).width;
|
|
4
|
-
|
|
5
|
-
export { getStringWidth };
|
|
1
|
+
import{getStringTruncatedWidth as e}from"./get-string-truncated-width.js";const d=(i,t={})=>e(i,{...t,ellipsis:"",ellipsisWidth:0,limit:Number.POSITIVE_INFINITY}).width;export{d as getStringWidth};
|
package/dist/indent.d.ts
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
interface Options {
|
|
2
|
+
/**
|
|
3
|
+
The string to use for the indent.
|
|
4
|
+
|
|
5
|
+
@default ' '
|
|
6
|
+
*/
|
|
7
|
+
readonly indent?: string;
|
|
8
|
+
/**
|
|
9
|
+
Also indent empty lines.
|
|
10
|
+
|
|
11
|
+
@default false
|
|
12
|
+
*/
|
|
13
|
+
readonly includeEmptyLines?: boolean;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
Indent each line in a string.
|
|
17
|
+
|
|
18
|
+
@param string - The string to indent.
|
|
19
|
+
@param count - How many times you want `options.indent` repeated. Default: `1`.
|
|
20
|
+
|
|
21
|
+
@example
|
|
22
|
+
```
|
|
23
|
+
import indentString from 'indent-string';
|
|
24
|
+
|
|
25
|
+
indentString('Unicorns\nRainbows', 4);
|
|
26
|
+
//=> ' Unicorns\n Rainbows'
|
|
27
|
+
|
|
28
|
+
indentString('Unicorns\nRainbows', 4, {indent: '♥'});
|
|
29
|
+
//=> '♥♥♥♥Unicorns\n♥♥♥♥Rainbows'
|
|
30
|
+
```
|
|
31
|
+
*/
|
|
32
|
+
declare function indentString(string: string, count?: number, options?: Options): string;
|
|
33
|
+
/**
|
|
34
|
+
[Strip redundant indentation](https://github.com/sindresorhus/strip-indent) and [indent the string](https://github.com/sindresorhus/indent-string).
|
|
35
|
+
|
|
36
|
+
@param string - The string to normalize indentation.
|
|
37
|
+
@param count - How many times you want `options.indent` repeated. Default: `0`.
|
|
38
|
+
|
|
39
|
+
@example
|
|
40
|
+
```
|
|
41
|
+
import redent from 'redent';
|
|
42
|
+
|
|
43
|
+
redent('\n foo\n bar\n', 1);
|
|
44
|
+
//=> '\n foo\n bar\n'
|
|
45
|
+
```
|
|
46
|
+
*/
|
|
47
|
+
declare function redent(string: string, count?: number, options?: Options): string;
|
|
48
|
+
/**
|
|
49
|
+
Strip leading whitespace from each line in a string.
|
|
50
|
+
|
|
51
|
+
The line with the least number of leading whitespace, ignoring empty lines, determines the number to remove.
|
|
52
|
+
|
|
53
|
+
@example
|
|
54
|
+
```
|
|
55
|
+
import stripIndent from 'strip-indent';
|
|
56
|
+
|
|
57
|
+
const string = '\tunicorn\n\t\tcake';
|
|
58
|
+
// unicorn
|
|
59
|
+
// cake
|
|
60
|
+
|
|
61
|
+
stripIndent(string);
|
|
62
|
+
//unicorn
|
|
63
|
+
// cake
|
|
64
|
+
```
|
|
65
|
+
*/
|
|
66
|
+
declare function stripIndent(string: string): string;
|
|
67
|
+
/**
|
|
68
|
+
Strip leading whitespace from each line in a string and remove surrounding blank lines.
|
|
69
|
+
|
|
70
|
+
The line with the least number of leading whitespace, ignoring empty lines, determines the number to remove.
|
|
71
|
+
Leading and trailing lines that contain only whitespace are removed.
|
|
72
|
+
|
|
73
|
+
Useful for template literals and multi-line strings where you want clean boundaries.
|
|
74
|
+
|
|
75
|
+
@example
|
|
76
|
+
```
|
|
77
|
+
import {dedent} from 'strip-indent';
|
|
78
|
+
|
|
79
|
+
dedent(`
|
|
80
|
+
unicorn
|
|
81
|
+
cake
|
|
82
|
+
`);
|
|
83
|
+
//unicorn
|
|
84
|
+
// cake
|
|
85
|
+
```
|
|
86
|
+
*/
|
|
87
|
+
declare function dedent(string: string): string;
|
|
88
|
+
export { type Options as IndentOptions, dedent, indentString as indent, redent, stripIndent };
|
package/dist/indent.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{default as d}from"./packem_shared/indent-cz8WMI0e.js";import{default as a}from"./packem_shared/redent-ByOoJ6fN.js";import{dedent as n,default as o}from"./packem_shared/dedent-CPjAYUXh.js";export{n as dedent,d as indent,a as redent,o as stripIndent};
|
package/dist/index.d.ts
CHANGED
|
@@ -17,35 +17,27 @@ export { default as snakeCase } from "./case/snake-case.js";
|
|
|
17
17
|
export { type SplitOptions, splitByCase } from "./case/split-by-case.js";
|
|
18
18
|
export { default as titleCase } from "./case/title-case.js";
|
|
19
19
|
export { default as trainCase } from "./case/train-case.js";
|
|
20
|
-
export {
|
|
20
|
+
export type { C as CamelCase, a as CapitalCase, b as CaseOptions, c as ConstantCase, D as DotCase, F as FlatCase, d as FlipCase, I as IdentifyCase, K as KebabCase, L as LocaleOptions, e as LowerFirst, N as NoCase, P as PascalCase, f as PascalSnakeCase, g as PathCase, S as SentenceCase, h as SnakeCase, i as SplitByCase, T as TitleCase, j as TrainCase, U as UpperFirst } from "./packem_shared/types.d-CMNqA5bi.js";
|
|
21
21
|
export { default as upperFirst } from "./case/upper-first.js";
|
|
22
22
|
export { joinSegments } from "./case/index.js";
|
|
23
23
|
export { type ClosestStringOptions, closestString } from "./closest-string.js";
|
|
24
24
|
export { type CompareSimilarityOptions, compareSimilarity } from "./compare-similarity.js";
|
|
25
|
-
export {
|
|
26
|
-
|
|
27
|
-
export {
|
|
25
|
+
export { countOccurrences } from "./count-occurrences.js";
|
|
26
|
+
export { direction } from "./direction.js";
|
|
27
|
+
export { type EastAsianWidthOptions, type EastAsianWidthType, eastAsianWidth, eastAsianWidthType } from "./east-asian-width.js";
|
|
28
|
+
export { type ExcerptOptions, excerpt } from "./excerpt.js";
|
|
28
29
|
export { type StringTruncatedWidthOptions, type StringTruncatedWidthResult, getStringTruncatedWidth } from "./get-string-truncated-width.js";
|
|
29
30
|
export { type StringWidthOptions, getStringWidth } from "./get-string-width.js";
|
|
30
|
-
export { type
|
|
31
|
-
export { default as
|
|
32
|
-
export {
|
|
31
|
+
export { type IndentOptions, dedent, indent, redent, stripIndent } from "./indent.js";
|
|
32
|
+
export { default as isFullwidthCodePoint } from "./is-fullwidth-code-point.js";
|
|
33
|
+
export { closest, closestN, distance, similarity } from "./levenshtein.js";
|
|
33
34
|
export { type Outdent, type Options as OutdentOptions, outdent } from "./outdent.js";
|
|
34
|
-
|
|
35
|
-
export { type A as All, type c as Any, type C as CharAt, type d as Charmap, type e as Concat, type E as EndsWith, type f as Includes, type g as Interval, type h as IsBooleanLiteral, type i as IsNumberLiteral, type I as IsStringLiteral, type j as IsStringLiteralArray, type J as Join, type L as Length, type M as Math, type N as NodeLocale, type k as OptionReplaceCombined, type l as OptionReplaceObject, type P as PadEnd, type m as PadStart, type R as Repeat, type n as Replace, type o as ReplaceAll, type p as Reverse, type q as Slice, type S as SlugifyOptions, type r as Split, type s as StartsWith, type T as ToLowerCase, type t as ToUpperCase, type u as Trim, type v as TrimEnd, type w as TrimStart } from "./packem_shared/types.d-BVNv675q.js";
|
|
35
|
+
export { default as replaceString } from "./replace-string.js";
|
|
36
36
|
export { type SliceOptions, slice } from "./slice.js";
|
|
37
37
|
export { default as slugify } from "./slugify.js";
|
|
38
|
+
export { default as transliterate } from "./transliterate.js";
|
|
39
|
+
export { type TruncateOptions, truncate } from "./truncate.js";
|
|
40
|
+
export type { A as All, a as Any, C as CharAt, b as Charmap, c as Concat, E as EndsWith, I as Includes, d as Interval, e as IntervalArray, f as IsBooleanLiteral, g as IsNumberLiteral, h as IsStringLiteral, i as IsStringLiteralArray, J as Join, L as Length, M as Math, N as NodeLocale, O as OptionReplaceArray, j as OptionReplaceCombined, k as OptionReplaceObject, l as OptionsTransliterate, P as PadEnd, m as PadStart, R as Repeat, n as Replace, o as ReplaceAll, p as Reverse, S as Slice, q as SlugifyOptions, r as Split, s as StartsWith, T as ToLowerCase, t as ToUpperCase, u as Trim, v as TrimEnd, w as TrimStart } from "./packem_shared/types.d-LgsTR37y.js";
|
|
38
41
|
export { escapeRegExp, findStringOccurrences, hasChinese, hasPunctuationOrSpace, inRange } from "./utilities.js";
|
|
39
42
|
export { type WordSimilaritySortOptions, wordSimilaritySort } from "./word-similarity-sort.js";
|
|
40
43
|
export { type WordWrapOptions, WrapMode, wordWrap } from "./word-wrap.js";
|
|
41
|
-
export { closest, distance } from 'fastest-levenshtein';
|
|
42
|
-
import "./packem_shared/lru-cache.d-BsP6kbVJ.js";
|
|
43
|
-
declare const countOccurrences: (value: string, substring: string) => number;
|
|
44
|
-
declare const direction: (value?: string) => "rtl" | "ltr" | "neutral";
|
|
45
|
-
declare const excerpt: (html: string, limit: number, options?: ExcerptOptions) => string;
|
|
46
|
-
type ExcerptOptions = Omit<TruncateOptions, "position">;
|
|
47
|
-
declare const isFullwidthCodePoint: (codePoint: number) => boolean;
|
|
48
|
-
declare const closestN: (string_: string, array: ReadonlyArray<string>, n: number) => (string | undefined)[];
|
|
49
|
-
declare const replaceString: (source: string, searches: OptionReplaceArray, ignoreRanges: IntervalArray) => string;
|
|
50
|
-
declare const transliterate: (source: string, options?: OptionsTransliterate) => string;
|
|
51
|
-
export { type ExcerptOptions, type IntervalArray, type OptionReplaceArray, type OptionsTransliterate, type TruncateOptions, closestN, countOccurrences, direction, excerpt, isFullwidthCodePoint, replaceString, transliterate };
|
package/dist/index.js
CHANGED
|
@@ -1,44 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export { default as camelCase } from './case/camel-case.js';
|
|
3
|
-
export { default as capitalCase } from './case/capital-case.js';
|
|
4
|
-
export { default as constantCase } from './case/constant-case.js';
|
|
5
|
-
export { default as dotCase } from './case/dot-case.js';
|
|
6
|
-
export { default as flatCase } from './case/flat-case.js';
|
|
7
|
-
export { flipCase } from './case/flip-case.js';
|
|
8
|
-
export { default as identifyCase } from './case/identify-case.js';
|
|
9
|
-
export { kebabCase } from './case/kebab-case.js';
|
|
10
|
-
export { default as lowerFirst } from './case/lower-first.js';
|
|
11
|
-
export { default as noCase } from './case/no-case.js';
|
|
12
|
-
export { default as pascalCase } from './case/pascal-case.js';
|
|
13
|
-
export { default as pascalSnakeCase } from './case/pascal-snake-case.js';
|
|
14
|
-
export { default as pathCase } from './case/path-case.js';
|
|
15
|
-
export { default as sentenceCase } from './case/sentence-case.js';
|
|
16
|
-
export { default as snakeCase } from './case/snake-case.js';
|
|
17
|
-
export { splitByCase } from './case/split-by-case.js';
|
|
18
|
-
export { default as titleCase } from './case/title-case.js';
|
|
19
|
-
export { default as trainCase } from './case/train-case.js';
|
|
20
|
-
export { default as upperFirst } from './case/upper-first.js';
|
|
21
|
-
export { default as joinSegments } from './packem_shared/joinSegments-CvxSgKz0.js';
|
|
22
|
-
export { closestString } from './closest-string.js';
|
|
23
|
-
export { compareSimilarity } from './compare-similarity.js';
|
|
24
|
-
export { countOccurrences } from './packem_shared/countOccurrences-CS9XprQN.js';
|
|
25
|
-
export { direction } from './packem_shared/direction-C9gfWWTK.js';
|
|
26
|
-
export { excerpt } from './packem_shared/excerpt-COsVNttN.js';
|
|
27
|
-
export { getStringTruncatedWidth } from './get-string-truncated-width.js';
|
|
28
|
-
export { getStringWidth } from './get-string-width.js';
|
|
29
|
-
export { default as isFullwidthCodePoint } from './packem_shared/isFullwidthCodePoint-IFXZxNjq.js';
|
|
30
|
-
export { closestN } from './packem_shared/closestN-DUsjgiXb.js';
|
|
31
|
-
export { outdent } from './outdent.js';
|
|
32
|
-
export { default as replaceString } from './packem_shared/replaceString-Ce8X2ZQ-.js';
|
|
33
|
-
export { slice } from './slice.js';
|
|
34
|
-
export { default as slugify } from './slugify.js';
|
|
35
|
-
export { default as transliterate } from './packem_shared/transliterate-CKt9VK7D.js';
|
|
36
|
-
export { truncate } from './truncate.js';
|
|
37
|
-
export { escapeRegExp, findStringOccurrences, hasChinese, hasPunctuationOrSpace, inRange } from './utilities.js';
|
|
38
|
-
export { wordSimilaritySort } from './word-similarity-sort.js';
|
|
39
|
-
export { WrapMode, wordWrap } from './word-wrap.js';
|
|
40
|
-
export { default as indent } from './packem_shared/indent-D3DSCa6s.js';
|
|
41
|
-
export { default as redent } from './packem_shared/redent-DSb1IJWn.js';
|
|
42
|
-
export { dedent, default as stripIndent } from './packem_shared/stripIndent-D_TRjxZ_.js';
|
|
43
|
-
export { closest, distance } from './packem_shared/closest-IHuSvnSn.js';
|
|
44
|
-
export { eastAsianWidth, eastAsianWidthType } from './packem_shared/eastAsianWidthType-SD3YniiT.js';
|
|
1
|
+
import{alignText as r}from"./align-text.js";import{default as a}from"./case/camel-case.js";import{default as s}from"./case/capital-case.js";import{default as m}from"./case/constant-case.js";import{default as i}from"./case/dot-case.js";import{default as d}from"./case/flat-case.js";import{flipCase as u}from"./case/flip-case.js";import{default as C}from"./case/identify-case.js";import{kebabCase as S}from"./case/kebab-case.js";import{default as y}from"./case/lower-first.js";import{default as w}from"./case/no-case.js";import{default as F}from"./case/pascal-case.js";import{default as T}from"./case/pascal-snake-case.js";import{default as A}from"./case/path-case.js";import{default as R}from"./case/sentence-case.js";import{default as B}from"./case/snake-case.js";import{splitByCase as I}from"./case/split-by-case.js";import{default as N}from"./case/title-case.js";import{default as v}from"./case/train-case.js";import{default as D}from"./case/upper-first.js";import{default as H}from"./packem_shared/joinSegments-CaHT-45s.js";import{closestString as K}from"./closest-string.js";import{compareSimilarity as Q}from"./compare-similarity.js";import{countOccurrences as V}from"./count-occurrences.js";import{direction as Y}from"./direction.js";import{excerpt as _}from"./excerpt.js";import{getStringTruncatedWidth as ee}from"./get-string-truncated-width.js";import{getStringWidth as re}from"./get-string-width.js";import{default as ae}from"./is-fullwidth-code-point.js";import{closestN as se,similarity as pe}from"./levenshtein.js";import{outdent as xe}from"./outdent.js";import{default as le}from"./replace-string.js";import{slice as ne}from"./slice.js";import{default as ce}from"./slugify.js";import{default as ge}from"./transliterate.js";import{truncate as he}from"./truncate.js";import{escapeRegExp as We,findStringOccurrences as we,hasChinese as ke,hasPunctuationOrSpace as Fe,inRange as Oe}from"./utilities.js";import{wordSimilaritySort as be}from"./word-similarity-sort.js";import{WrapMode as Pe,wordWrap as Re}from"./word-wrap.js";import{default as Be}from"./packem_shared/indent-cz8WMI0e.js";import{default as Ie}from"./packem_shared/redent-ByOoJ6fN.js";import{dedent as Ne,default as qe}from"./packem_shared/dedent-CPjAYUXh.js";import{closest as ze,distance as De}from"./packem_shared/closest-C6YDQs4m.js";import{eastAsianWidth as He,eastAsianWidthType as Je}from"./packem_shared/eastAsianWidth-DJV8Kqd-.js";export{Pe as WrapMode,r as alignText,a as camelCase,s as capitalCase,ze as closest,se as closestN,K as closestString,Q as compareSimilarity,m as constantCase,V as countOccurrences,Ne as dedent,Y as direction,De as distance,i as dotCase,He as eastAsianWidth,Je as eastAsianWidthType,We as escapeRegExp,_ as excerpt,we as findStringOccurrences,d as flatCase,u as flipCase,ee as getStringTruncatedWidth,re as getStringWidth,ke as hasChinese,Fe as hasPunctuationOrSpace,C as identifyCase,Oe as inRange,Be as indent,ae as isFullwidthCodePoint,H as joinSegments,S as kebabCase,y as lowerFirst,w as noCase,xe as outdent,F as pascalCase,T as pascalSnakeCase,A as pathCase,Ie as redent,le as replaceString,R as sentenceCase,pe as similarity,ne as slice,ce as slugify,B as snakeCase,I as splitByCase,qe as stripIndent,N as titleCase,v as trainCase,ge as transliterate,he as truncate,D as upperFirst,be as wordSimilaritySort,Re as wordWrap};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Check if the given code point is a fullwidth character.
|
|
3
|
+
* @param codePoint The code point to check.
|
|
4
|
+
* @returns Whether the code point is a fullwidth character.
|
|
5
|
+
*/
|
|
6
|
+
declare const isFullwidthCodePoint: (codePoint: number) => boolean;
|
|
7
|
+
export { isFullwidthCodePoint as default };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{isFullWidth as i,isWide as t}from"./packem_shared/_isFullWidth-Dqc3MWgl.js";const r=s=>Number.isInteger(s)?i(s)||t(s):!1;export{r as default};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
declare const distance: (a: string, b: string) => number;
|
|
2
|
+
declare const closest: (str: string, arr: readonly string[]) => string;
|
|
3
|
+
declare const closestN: (string_: string, array: ReadonlyArray<string>, n: number) => (string | undefined)[];
|
|
4
|
+
/**
|
|
5
|
+
* Computes a normalized similarity score between two strings in the range `[0, 1]`,
|
|
6
|
+
* where `1` means the strings are identical and `0` means maximally different.
|
|
7
|
+
*
|
|
8
|
+
* The score is derived from the Levenshtein edit distance, normalized by the
|
|
9
|
+
* length of the longer string: `1 - distance(a, b) / max(a.length, b.length)`.
|
|
10
|
+
* Two empty strings are considered identical (`1`).
|
|
11
|
+
*
|
|
12
|
+
* This is convenient for threshold-based "did you mean?" UX, complementing the
|
|
13
|
+
* raw {@link distance} and the sort-based helpers.
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* similarity("kitten", "sitting"); // => ~0.571
|
|
17
|
+
* similarity("foo", "foo"); // => 1
|
|
18
|
+
* similarity("", ""); // => 1
|
|
19
|
+
* ```
|
|
20
|
+
* @param a The first string.
|
|
21
|
+
* @param b The second string.
|
|
22
|
+
* @returns A similarity score between 0 and 1 (inclusive).
|
|
23
|
+
*/
|
|
24
|
+
declare const similarity: (a: string, b: string) => number;
|
|
25
|
+
export { closest, closestN, distance, similarity };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{distance as c}from"./packem_shared/closest-C6YDQs4m.js";import{closest as y}from"./packem_shared/closest-C6YDQs4m.js";const u=(r,s,o)=>{const e=Array.from({length:o}).fill(1/0),n=Array.from({length:o}).fill(void 0);for(const a of s){const f=a;let l=c(r,f),i=f;for(let t=0;t<o;t+=1)if(l<e[t]){const m=e[t],h=n[t];e[t]=l,n[t]=i,l=m,i=h}}return n},d=(r,s)=>{if(r===s)return 1;const o=Math.max(r.length,s.length);return o===0?1:1-c(r,s)/o};export{y as closest,u as closestN,c as distance,d as similarity};
|