@visulima/string 1.0.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 +5 -0
- package/LICENSE.md +77 -0
- package/README.md +880 -0
- package/dist/case/camel-case.cjs +59 -0
- package/dist/case/camel-case.d.cts +7 -0
- package/dist/case/camel-case.d.mts +7 -0
- package/dist/case/camel-case.d.ts +7 -0
- package/dist/case/camel-case.mjs +57 -0
- package/dist/case/capital-case.cjs +51 -0
- package/dist/case/capital-case.d.cts +7 -0
- package/dist/case/capital-case.d.mts +7 -0
- package/dist/case/capital-case.d.ts +7 -0
- package/dist/case/capital-case.mjs +49 -0
- package/dist/case/constant-case.cjs +11 -0
- package/dist/case/constant-case.d.cts +7 -0
- package/dist/case/constant-case.d.mts +7 -0
- package/dist/case/constant-case.d.ts +7 -0
- package/dist/case/constant-case.mjs +9 -0
- package/dist/case/dot-case.cjs +11 -0
- package/dist/case/dot-case.d.cts +7 -0
- package/dist/case/dot-case.d.mts +7 -0
- package/dist/case/dot-case.d.ts +7 -0
- package/dist/case/dot-case.mjs +9 -0
- package/dist/case/flat-case.cjs +11 -0
- package/dist/case/flat-case.d.cts +7 -0
- package/dist/case/flat-case.d.mts +7 -0
- package/dist/case/flat-case.d.ts +7 -0
- package/dist/case/flat-case.mjs +9 -0
- package/dist/case/flip-case.cjs +61 -0
- package/dist/case/flip-case.d.cts +8 -0
- package/dist/case/flip-case.d.mts +8 -0
- package/dist/case/flip-case.d.ts +8 -0
- package/dist/case/flip-case.mjs +57 -0
- package/dist/case/identify-case.cjs +30 -0
- package/dist/case/identify-case.d.cts +7 -0
- package/dist/case/identify-case.d.mts +7 -0
- package/dist/case/identify-case.d.ts +7 -0
- package/dist/case/identify-case.mjs +28 -0
- package/dist/case/index.cjs +47 -0
- package/dist/case/index.d.cts +26 -0
- package/dist/case/index.d.mts +26 -0
- package/dist/case/index.d.ts +26 -0
- package/dist/case/index.mjs +20 -0
- package/dist/case/kebab-case.cjs +61 -0
- package/dist/case/kebab-case.d.cts +11 -0
- package/dist/case/kebab-case.d.mts +11 -0
- package/dist/case/kebab-case.d.ts +11 -0
- package/dist/case/kebab-case.mjs +57 -0
- package/dist/case/lower-first.cjs +13 -0
- package/dist/case/lower-first.d.cts +7 -0
- package/dist/case/lower-first.d.mts +7 -0
- package/dist/case/lower-first.d.ts +7 -0
- package/dist/case/lower-first.mjs +11 -0
- package/dist/case/no-case.cjs +11 -0
- package/dist/case/no-case.d.cts +7 -0
- package/dist/case/no-case.d.mts +7 -0
- package/dist/case/no-case.d.ts +7 -0
- package/dist/case/no-case.mjs +9 -0
- package/dist/case/pascal-case.cjs +52 -0
- package/dist/case/pascal-case.d.cts +7 -0
- package/dist/case/pascal-case.d.mts +7 -0
- package/dist/case/pascal-case.d.ts +7 -0
- package/dist/case/pascal-case.mjs +50 -0
- package/dist/case/pascal-snake-case.cjs +32 -0
- package/dist/case/pascal-snake-case.d.cts +7 -0
- package/dist/case/pascal-snake-case.d.mts +7 -0
- package/dist/case/pascal-snake-case.d.ts +7 -0
- package/dist/case/pascal-snake-case.mjs +30 -0
- package/dist/case/path-case.cjs +11 -0
- package/dist/case/path-case.d.cts +7 -0
- package/dist/case/path-case.d.mts +7 -0
- package/dist/case/path-case.d.ts +7 -0
- package/dist/case/path-case.mjs +9 -0
- package/dist/case/sentence-case.cjs +58 -0
- package/dist/case/sentence-case.d.cts +7 -0
- package/dist/case/sentence-case.d.mts +7 -0
- package/dist/case/sentence-case.d.ts +7 -0
- package/dist/case/sentence-case.mjs +56 -0
- package/dist/case/snake-case.cjs +11 -0
- package/dist/case/snake-case.d.cts +7 -0
- package/dist/case/snake-case.d.mts +7 -0
- package/dist/case/snake-case.d.ts +7 -0
- package/dist/case/snake-case.mjs +9 -0
- package/dist/case/split-by-case.cjs +638 -0
- package/dist/case/split-by-case.d.cts +16 -0
- package/dist/case/split-by-case.d.mts +16 -0
- package/dist/case/split-by-case.d.ts +16 -0
- package/dist/case/split-by-case.mjs +634 -0
- package/dist/case/title-case.cjs +47 -0
- package/dist/case/title-case.d.cts +7 -0
- package/dist/case/title-case.d.mts +7 -0
- package/dist/case/title-case.d.ts +7 -0
- package/dist/case/title-case.mjs +45 -0
- package/dist/case/train-case.cjs +44 -0
- package/dist/case/train-case.d.cts +7 -0
- package/dist/case/train-case.d.mts +7 -0
- package/dist/case/train-case.d.ts +7 -0
- package/dist/case/train-case.mjs +42 -0
- package/dist/case/upper-first.cjs +13 -0
- package/dist/case/upper-first.d.cts +7 -0
- package/dist/case/upper-first.d.mts +7 -0
- package/dist/case/upper-first.d.ts +7 -0
- package/dist/case/upper-first.mjs +11 -0
- package/dist/get-string-truncated-width.cjs +386 -0
- package/dist/get-string-truncated-width.d.cts +25 -0
- package/dist/get-string-truncated-width.d.mts +25 -0
- package/dist/get-string-truncated-width.d.ts +25 -0
- package/dist/get-string-truncated-width.mjs +382 -0
- package/dist/get-string-width.cjs +11 -0
- package/dist/get-string-width.d.cts +6 -0
- package/dist/get-string-width.d.mts +6 -0
- package/dist/get-string-width.d.ts +6 -0
- package/dist/get-string-width.mjs +7 -0
- package/dist/index.cjs +60 -0
- package/dist/index.d.cts +43 -0
- package/dist/index.d.mts +43 -0
- package/dist/index.d.ts +43 -0
- package/dist/index.mjs +26 -0
- package/dist/native-string-types.d.cts +128 -0
- package/dist/native-string-types.d.mts +128 -0
- package/dist/native-string-types.d.ts +128 -0
- package/dist/outdent.cjs +122 -0
- package/dist/outdent.d.cts +15 -0
- package/dist/outdent.d.mts +15 -0
- package/dist/outdent.d.ts +15 -0
- package/dist/outdent.mjs +118 -0
- package/dist/packem_shared/LRUCache-Crb-m7cw.cjs +53 -0
- package/dist/packem_shared/LRUCache-udNErhWw.mjs +51 -0
- package/dist/packem_shared/WrapMode-BgOOthJV.mjs +545 -0
- package/dist/packem_shared/WrapMode-ZqTeXK8X.cjs +550 -0
- package/dist/packem_shared/constants-BnVGLrDr.mjs +99 -0
- package/dist/packem_shared/constants-HevSYUjU.cjs +149 -0
- package/dist/packem_shared/generate-cache-key-D8f1auDB.cjs +10 -0
- package/dist/packem_shared/generate-cache-key-YSju5pj2.mjs +8 -0
- package/dist/packem_shared/joinSegments-BH1CT4dK.cjs +48 -0
- package/dist/packem_shared/joinSegments-BHY8PPnk.mjs +46 -0
- package/dist/packem_shared/normalize-german-eszett-DJK0S2qj.cjs +11 -0
- package/dist/packem_shared/normalize-german-eszett-fpJ4lZL6.mjs +9 -0
- package/dist/packem_shared/types-BAd3WDHo.d.mts +59 -0
- package/dist/packem_shared/types-BNbQJg02.d.cts +41 -0
- package/dist/packem_shared/types-BNbQJg02.d.mts +41 -0
- package/dist/packem_shared/types-BNbQJg02.d.ts +41 -0
- package/dist/packem_shared/types-BttWSSIk.d.ts +59 -0
- package/dist/packem_shared/types-D2-6p7t1.d.cts +59 -0
- package/dist/slice.cjs +413 -0
- package/dist/slice.d.cts +10 -0
- package/dist/slice.d.mts +10 -0
- package/dist/slice.d.ts +10 -0
- package/dist/slice.mjs +409 -0
- package/dist/test/utils.cjs +77 -0
- package/dist/test/utils.d.cts +30 -0
- package/dist/test/utils.d.mts +30 -0
- package/dist/test/utils.d.ts +30 -0
- package/dist/test/utils.mjs +71 -0
- package/dist/test/vitest.cjs +11 -0
- package/dist/test/vitest.d.cts +8 -0
- package/dist/test/vitest.d.mts +8 -0
- package/dist/test/vitest.d.ts +8 -0
- package/dist/test/vitest.mjs +7 -0
- package/dist/truncate.cjs +90 -0
- package/dist/truncate.d.cts +12 -0
- package/dist/truncate.d.mts +12 -0
- package/dist/truncate.d.ts +12 -0
- package/dist/truncate.mjs +86 -0
- package/dist/utils.cjs +9 -0
- package/dist/utils.d.cts +14 -0
- package/dist/utils.d.mts +14 -0
- package/dist/utils.d.ts +14 -0
- package/dist/utils.mjs +1 -0
- package/package.json +468 -0
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { b as CaseOptions, T as TitleCase } from '../packem_shared/types-BttWSSIk.js';
|
|
2
|
+
import '../packem_shared/types-BNbQJg02.js';
|
|
3
|
+
import '../utils.js';
|
|
4
|
+
|
|
5
|
+
declare function titleCase<T extends string = string>(value?: T, options?: CaseOptions): TitleCase<T>;
|
|
6
|
+
|
|
7
|
+
export = titleCase;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import LRUCache from '../packem_shared/LRUCache-udNErhWw.mjs';
|
|
2
|
+
import { splitByCase } from './split-by-case.mjs';
|
|
3
|
+
import upperFirst from './upper-first.mjs';
|
|
4
|
+
import { g as generateCacheKey } from '../packem_shared/generate-cache-key-YSju5pj2.mjs';
|
|
5
|
+
import { n as normalizeGermanEszett } from '../packem_shared/normalize-german-eszett-fpJ4lZL6.mjs';
|
|
6
|
+
|
|
7
|
+
var __defProp = Object.defineProperty;
|
|
8
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
9
|
+
const defaultCacheStore = new LRUCache(1e3);
|
|
10
|
+
function titleCase(value, options) {
|
|
11
|
+
if (typeof value !== "string") {
|
|
12
|
+
return "";
|
|
13
|
+
}
|
|
14
|
+
const shouldCache = options?.cache ?? false;
|
|
15
|
+
const cacheStore = options?.cacheStore ?? defaultCacheStore;
|
|
16
|
+
let cacheKey;
|
|
17
|
+
if (shouldCache) {
|
|
18
|
+
cacheKey = generateCacheKey(value, options);
|
|
19
|
+
}
|
|
20
|
+
if (shouldCache && cacheKey && cacheStore.has(cacheKey)) {
|
|
21
|
+
return cacheStore.get(cacheKey);
|
|
22
|
+
}
|
|
23
|
+
const result = splitByCase(value, {
|
|
24
|
+
handleAnsi: options?.handleAnsi,
|
|
25
|
+
handleEmoji: options?.handleEmoji,
|
|
26
|
+
knownAcronyms: options?.knownAcronyms,
|
|
27
|
+
locale: options?.locale,
|
|
28
|
+
normalize: options?.normalize,
|
|
29
|
+
separators: void 0,
|
|
30
|
+
stripAnsi: options?.stripAnsi,
|
|
31
|
+
stripEmoji: options?.stripEmoji
|
|
32
|
+
}).map((word) => {
|
|
33
|
+
if (options?.locale?.startsWith("de")) {
|
|
34
|
+
word = normalizeGermanEszett(word);
|
|
35
|
+
}
|
|
36
|
+
return upperFirst(options?.locale ? word.toLocaleLowerCase(options.locale) : word.toLowerCase(), { locale: options?.locale });
|
|
37
|
+
}).join(" ");
|
|
38
|
+
if (shouldCache && cacheKey) {
|
|
39
|
+
cacheStore.set(cacheKey, result);
|
|
40
|
+
}
|
|
41
|
+
return result;
|
|
42
|
+
}
|
|
43
|
+
__name(titleCase, "titleCase");
|
|
44
|
+
|
|
45
|
+
export { titleCase as default };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const LRUCache = require('../packem_shared/LRUCache-Crb-m7cw.cjs');
|
|
4
|
+
const case_splitByCase = require('./split-by-case.cjs');
|
|
5
|
+
const case_upperFirst = require('./upper-first.cjs');
|
|
6
|
+
const generateCacheKey = require('../packem_shared/generate-cache-key-D8f1auDB.cjs');
|
|
7
|
+
const joinSegments = require('../packem_shared/joinSegments-BH1CT4dK.cjs');
|
|
8
|
+
|
|
9
|
+
var __defProp = Object.defineProperty;
|
|
10
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
11
|
+
const defaultCacheStore = new LRUCache(1e3);
|
|
12
|
+
const trainCase = /* @__PURE__ */ __name((value, options) => {
|
|
13
|
+
if (typeof value !== "string") {
|
|
14
|
+
return "";
|
|
15
|
+
}
|
|
16
|
+
const shouldCache = options?.cache ?? false;
|
|
17
|
+
const cacheStore = options?.cacheStore ?? defaultCacheStore;
|
|
18
|
+
let cacheKey;
|
|
19
|
+
if (shouldCache) {
|
|
20
|
+
cacheKey = generateCacheKey.generateCacheKey(value, options);
|
|
21
|
+
}
|
|
22
|
+
if (shouldCache && cacheKey && cacheStore.has(cacheKey)) {
|
|
23
|
+
return cacheStore.get(cacheKey);
|
|
24
|
+
}
|
|
25
|
+
const result = joinSegments(
|
|
26
|
+
case_splitByCase.splitByCase(value, {
|
|
27
|
+
handleAnsi: options?.handleAnsi,
|
|
28
|
+
handleEmoji: options?.handleEmoji,
|
|
29
|
+
knownAcronyms: options?.knownAcronyms,
|
|
30
|
+
locale: options?.locale,
|
|
31
|
+
normalize: options?.normalize,
|
|
32
|
+
separators: void 0,
|
|
33
|
+
stripAnsi: options?.stripAnsi,
|
|
34
|
+
stripEmoji: options?.stripEmoji
|
|
35
|
+
}).map((p) => case_upperFirst(p, { locale: options?.locale })),
|
|
36
|
+
"-"
|
|
37
|
+
);
|
|
38
|
+
if (shouldCache && cacheKey) {
|
|
39
|
+
cacheStore.set(cacheKey, result);
|
|
40
|
+
}
|
|
41
|
+
return result;
|
|
42
|
+
}, "trainCase");
|
|
43
|
+
|
|
44
|
+
module.exports = trainCase;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { b as CaseOptions, j as TrainCase } from '../packem_shared/types-D2-6p7t1.cjs';
|
|
2
|
+
import '../packem_shared/types-BNbQJg02.cjs';
|
|
3
|
+
import '../utils.cjs';
|
|
4
|
+
|
|
5
|
+
declare const trainCase: <T extends string = string>(value?: T, options?: CaseOptions) => TrainCase<T>;
|
|
6
|
+
|
|
7
|
+
export = trainCase;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { b as CaseOptions, j as TrainCase } from '../packem_shared/types-BAd3WDHo.mjs';
|
|
2
|
+
import '../packem_shared/types-BNbQJg02.mjs';
|
|
3
|
+
import '../utils.mjs';
|
|
4
|
+
|
|
5
|
+
declare const trainCase: <T extends string = string>(value?: T, options?: CaseOptions) => TrainCase<T>;
|
|
6
|
+
|
|
7
|
+
export { trainCase as default };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { b as CaseOptions, j as TrainCase } from '../packem_shared/types-BttWSSIk.js';
|
|
2
|
+
import '../packem_shared/types-BNbQJg02.js';
|
|
3
|
+
import '../utils.js';
|
|
4
|
+
|
|
5
|
+
declare const trainCase: <T extends string = string>(value?: T, options?: CaseOptions) => TrainCase<T>;
|
|
6
|
+
|
|
7
|
+
export = trainCase;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import LRUCache from '../packem_shared/LRUCache-udNErhWw.mjs';
|
|
2
|
+
import { splitByCase } from './split-by-case.mjs';
|
|
3
|
+
import upperFirst from './upper-first.mjs';
|
|
4
|
+
import { g as generateCacheKey } from '../packem_shared/generate-cache-key-YSju5pj2.mjs';
|
|
5
|
+
import joinSegments from '../packem_shared/joinSegments-BHY8PPnk.mjs';
|
|
6
|
+
|
|
7
|
+
var __defProp = Object.defineProperty;
|
|
8
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
9
|
+
const defaultCacheStore = new LRUCache(1e3);
|
|
10
|
+
const trainCase = /* @__PURE__ */ __name((value, options) => {
|
|
11
|
+
if (typeof value !== "string") {
|
|
12
|
+
return "";
|
|
13
|
+
}
|
|
14
|
+
const shouldCache = options?.cache ?? false;
|
|
15
|
+
const cacheStore = options?.cacheStore ?? defaultCacheStore;
|
|
16
|
+
let cacheKey;
|
|
17
|
+
if (shouldCache) {
|
|
18
|
+
cacheKey = generateCacheKey(value, options);
|
|
19
|
+
}
|
|
20
|
+
if (shouldCache && cacheKey && cacheStore.has(cacheKey)) {
|
|
21
|
+
return cacheStore.get(cacheKey);
|
|
22
|
+
}
|
|
23
|
+
const result = joinSegments(
|
|
24
|
+
splitByCase(value, {
|
|
25
|
+
handleAnsi: options?.handleAnsi,
|
|
26
|
+
handleEmoji: options?.handleEmoji,
|
|
27
|
+
knownAcronyms: options?.knownAcronyms,
|
|
28
|
+
locale: options?.locale,
|
|
29
|
+
normalize: options?.normalize,
|
|
30
|
+
separators: void 0,
|
|
31
|
+
stripAnsi: options?.stripAnsi,
|
|
32
|
+
stripEmoji: options?.stripEmoji
|
|
33
|
+
}).map((p) => upperFirst(p, { locale: options?.locale })),
|
|
34
|
+
"-"
|
|
35
|
+
);
|
|
36
|
+
if (shouldCache && cacheKey) {
|
|
37
|
+
cacheStore.set(cacheKey, result);
|
|
38
|
+
}
|
|
39
|
+
return result;
|
|
40
|
+
}, "trainCase");
|
|
41
|
+
|
|
42
|
+
export { trainCase as default };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
5
|
+
const upperFirst = /* @__PURE__ */ __name((value, options) => {
|
|
6
|
+
if (typeof value !== "string" || value === "") {
|
|
7
|
+
return "";
|
|
8
|
+
}
|
|
9
|
+
const firstChar = options?.locale ? value[0].toLocaleUpperCase(options.locale) : value[0].toUpperCase();
|
|
10
|
+
return firstChar + value.slice(1);
|
|
11
|
+
}, "upperFirst");
|
|
12
|
+
|
|
13
|
+
module.exports = upperFirst;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { L as LocaleOptions, U as UpperFirst } from '../packem_shared/types-D2-6p7t1.cjs';
|
|
2
|
+
import '../packem_shared/types-BNbQJg02.cjs';
|
|
3
|
+
import '../utils.cjs';
|
|
4
|
+
|
|
5
|
+
declare const upperFirst: <T extends string = string>(value?: T, options?: LocaleOptions) => UpperFirst<T>;
|
|
6
|
+
|
|
7
|
+
export = upperFirst;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { L as LocaleOptions, U as UpperFirst } from '../packem_shared/types-BAd3WDHo.mjs';
|
|
2
|
+
import '../packem_shared/types-BNbQJg02.mjs';
|
|
3
|
+
import '../utils.mjs';
|
|
4
|
+
|
|
5
|
+
declare const upperFirst: <T extends string = string>(value?: T, options?: LocaleOptions) => UpperFirst<T>;
|
|
6
|
+
|
|
7
|
+
export { upperFirst as default };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { L as LocaleOptions, U as UpperFirst } from '../packem_shared/types-BttWSSIk.js';
|
|
2
|
+
import '../packem_shared/types-BNbQJg02.js';
|
|
3
|
+
import '../utils.js';
|
|
4
|
+
|
|
5
|
+
declare const upperFirst: <T extends string = string>(value?: T, options?: LocaleOptions) => UpperFirst<T>;
|
|
6
|
+
|
|
7
|
+
export = upperFirst;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
const upperFirst = /* @__PURE__ */ __name((value, options) => {
|
|
4
|
+
if (typeof value !== "string" || value === "") {
|
|
5
|
+
return "";
|
|
6
|
+
}
|
|
7
|
+
const firstChar = options?.locale ? value[0].toLocaleUpperCase(options.locale) : value[0].toUpperCase();
|
|
8
|
+
return firstChar + value.slice(1);
|
|
9
|
+
}, "upperFirst");
|
|
10
|
+
|
|
11
|
+
export { upperFirst as default };
|
|
@@ -0,0 +1,386 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
|
|
4
|
+
|
|
5
|
+
const constants = require('./packem_shared/constants-HevSYUjU.cjs');
|
|
6
|
+
|
|
7
|
+
var __defProp$2 = Object.defineProperty;
|
|
8
|
+
var __name$2 = (target, value) => __defProp$2(target, "name", { value, configurable: true });
|
|
9
|
+
function isAmbiguous(x) {
|
|
10
|
+
return x === 161 || x === 164 || x === 167 || x === 168 || x === 170 || x === 173 || x === 174 || x >= 176 && x <= 180 || x >= 182 && x <= 186 || x >= 188 && x <= 191 || x === 198 || x === 208 || x === 215 || x === 216 || x >= 222 && x <= 225 || x === 230 || x >= 232 && x <= 234 || x === 236 || x === 237 || x === 240 || x === 242 || x === 243 || x >= 247 && x <= 250 || x === 252 || x === 254 || x === 257 || x === 273 || x === 275 || x === 283 || x === 294 || x === 295 || x === 299 || x >= 305 && x <= 307 || x === 312 || x >= 319 && x <= 322 || x === 324 || x >= 328 && x <= 331 || x === 333 || x === 338 || x === 339 || x === 358 || x === 359 || x === 363 || x === 462 || x === 464 || x === 466 || x === 468 || x === 470 || x === 472 || x === 474 || x === 476 || x === 593 || x === 609 || x === 708 || x === 711 || x >= 713 && x <= 715 || x === 717 || x === 720 || x >= 728 && x <= 731 || x === 733 || x === 735 || x >= 768 && x <= 879 || x >= 913 && x <= 929 || x >= 931 && x <= 937 || x >= 945 && x <= 961 || x >= 963 && x <= 969 || x === 1025 || x >= 1040 && x <= 1103 || x === 1105 || x === 8208 || x >= 8211 && x <= 8214 || x === 8216 || x === 8217 || x === 8220 || x === 8221 || x >= 8224 && x <= 8226 || x >= 8228 && x <= 8231 || x === 8240 || x === 8242 || x === 8243 || x === 8245 || x === 8251 || x === 8254 || x === 8308 || x === 8319 || x >= 8321 && x <= 8324 || x === 8364 || x === 8451 || x === 8453 || x === 8457 || x === 8467 || x === 8470 || x === 8481 || x === 8482 || x === 8486 || x === 8491 || x === 8531 || x === 8532 || x >= 8539 && x <= 8542 || x >= 8544 && x <= 8555 || x >= 8560 && x <= 8569 || x === 8585 || x >= 8592 && x <= 8601 || x === 8632 || x === 8633 || x === 8658 || x === 8660 || x === 8679 || x === 8704 || x === 8706 || x === 8707 || x === 8711 || x === 8712 || x === 8715 || x === 8719 || x === 8721 || x === 8725 || x === 8730 || x >= 8733 && x <= 8736 || x === 8739 || x === 8741 || x >= 8743 && x <= 8748 || x === 8750 || x >= 8756 && x <= 8759 || x === 8764 || x === 8765 || x === 8776 || x === 8780 || x === 8786 || x === 8800 || x === 8801 || x >= 8804 && x <= 8807 || x === 8810 || x === 8811 || x === 8814 || x === 8815 || x === 8834 || x === 8835 || x === 8838 || x === 8839 || x === 8853 || x === 8857 || x === 8869 || x === 8895 || x === 8978 || x >= 9312 && x <= 9449 || x >= 9451 && x <= 9547 || x >= 9552 && x <= 9587 || x >= 9600 && x <= 9615 || x >= 9618 && x <= 9621 || x === 9632 || x === 9633 || x >= 9635 && x <= 9641 || x === 9650 || x === 9651 || x === 9654 || x === 9655 || x === 9660 || x === 9661 || x === 9664 || x === 9665 || x >= 9670 && x <= 9672 || x === 9675 || x >= 9678 && x <= 9681 || x >= 9698 && x <= 9701 || x === 9711 || x === 9733 || x === 9734 || x === 9737 || x === 9742 || x === 9743 || x === 9756 || x === 9758 || x === 9792 || x === 9794 || x === 9824 || x === 9825 || x >= 9827 && x <= 9829 || x >= 9831 && x <= 9834 || x === 9836 || x === 9837 || x === 9839 || x === 9886 || x === 9887 || x === 9919 || x >= 9926 && x <= 9933 || x >= 9935 && x <= 9939 || x >= 9941 && x <= 9953 || x === 9955 || x === 9960 || x === 9961 || x >= 9963 && x <= 9969 || x === 9972 || x >= 9974 && x <= 9977 || x === 9979 || x === 9980 || x === 9982 || x === 9983 || x === 10045 || x >= 10102 && x <= 10111 || x >= 11094 && x <= 11097 || x >= 12872 && x <= 12879 || x >= 57344 && x <= 63743 || x >= 65024 && x <= 65039 || x === 65533 || x >= 127232 && x <= 127242 || x >= 127248 && x <= 127277 || x >= 127280 && x <= 127337 || x >= 127344 && x <= 127373 || x === 127375 || x === 127376 || x >= 127387 && x <= 127404 || x >= 917760 && x <= 917999 || x >= 983040 && x <= 1048573 || x >= 1048576 && x <= 1114109;
|
|
11
|
+
}
|
|
12
|
+
__name$2(isAmbiguous, "isAmbiguous");
|
|
13
|
+
function isFullWidth(x) {
|
|
14
|
+
return x === 12288 || x >= 65281 && x <= 65376 || x >= 65504 && x <= 65510;
|
|
15
|
+
}
|
|
16
|
+
__name$2(isFullWidth, "isFullWidth");
|
|
17
|
+
function isWide(x) {
|
|
18
|
+
return x >= 4352 && x <= 4447 || x === 8986 || x === 8987 || x === 9001 || x === 9002 || x >= 9193 && x <= 9196 || x === 9200 || x === 9203 || x === 9725 || x === 9726 || x === 9748 || x === 9749 || x >= 9776 && x <= 9783 || x >= 9800 && x <= 9811 || x === 9855 || x >= 9866 && x <= 9871 || x === 9875 || x === 9889 || x === 9898 || x === 9899 || x === 9917 || x === 9918 || x === 9924 || x === 9925 || x === 9934 || x === 9940 || x === 9962 || x === 9970 || x === 9971 || x === 9973 || x === 9978 || x === 9981 || x === 9989 || x === 9994 || x === 9995 || x === 10024 || x === 10060 || x === 10062 || x >= 10067 && x <= 10069 || x === 10071 || x >= 10133 && x <= 10135 || x === 10160 || x === 10175 || x === 11035 || x === 11036 || x === 11088 || x === 11093 || x >= 11904 && x <= 11929 || x >= 11931 && x <= 12019 || x >= 12032 && x <= 12245 || x >= 12272 && x <= 12287 || x >= 12289 && x <= 12350 || x >= 12353 && x <= 12438 || x >= 12441 && x <= 12543 || x >= 12549 && x <= 12591 || x >= 12593 && x <= 12686 || x >= 12688 && x <= 12773 || x >= 12783 && x <= 12830 || x >= 12832 && x <= 12871 || x >= 12880 && x <= 42124 || x >= 42128 && x <= 42182 || x >= 43360 && x <= 43388 || x >= 44032 && x <= 55203 || x >= 63744 && x <= 64255 || x >= 65040 && x <= 65049 || x >= 65072 && x <= 65106 || x >= 65108 && x <= 65126 || x >= 65128 && x <= 65131 || x >= 94176 && x <= 94180 || x === 94192 || x === 94193 || x >= 94208 && x <= 100343 || x >= 100352 && x <= 101589 || x >= 101631 && x <= 101640 || x >= 110576 && x <= 110579 || x >= 110581 && x <= 110587 || x === 110589 || x === 110590 || x >= 110592 && x <= 110882 || x === 110898 || x >= 110928 && x <= 110930 || x === 110933 || x >= 110948 && x <= 110951 || x >= 110960 && x <= 111355 || x >= 119552 && x <= 119638 || x >= 119648 && x <= 119670 || x === 126980 || x === 127183 || x === 127374 || x >= 127377 && x <= 127386 || x >= 127488 && x <= 127490 || x >= 127504 && x <= 127547 || x >= 127552 && x <= 127560 || x === 127568 || x === 127569 || x >= 127584 && x <= 127589 || x >= 127744 && x <= 127776 || x >= 127789 && x <= 127797 || x >= 127799 && x <= 127868 || x >= 127870 && x <= 127891 || x >= 127904 && x <= 127946 || x >= 127951 && x <= 127955 || x >= 127968 && x <= 127984 || x === 127988 || x >= 127992 && x <= 128062 || x === 128064 || x >= 128066 && x <= 128252 || x >= 128255 && x <= 128317 || x >= 128331 && x <= 128334 || x >= 128336 && x <= 128359 || x === 128378 || x === 128405 || x === 128406 || x === 128420 || x >= 128507 && x <= 128591 || x >= 128640 && x <= 128709 || x === 128716 || x >= 128720 && x <= 128722 || x >= 128725 && x <= 128727 || x >= 128732 && x <= 128735 || x === 128747 || x === 128748 || x >= 128756 && x <= 128764 || x >= 128992 && x <= 129003 || x === 129008 || x >= 129292 && x <= 129338 || x >= 129340 && x <= 129349 || x >= 129351 && x <= 129535 || x >= 129648 && x <= 129660 || x >= 129664 && x <= 129673 || x >= 129679 && x <= 129734 || x >= 129742 && x <= 129756 || x >= 129759 && x <= 129769 || x >= 129776 && x <= 129784 || x >= 131072 && x <= 196605 || x >= 196608 && x <= 262141;
|
|
19
|
+
}
|
|
20
|
+
__name$2(isWide, "isWide");
|
|
21
|
+
function getCategory(x) {
|
|
22
|
+
if (isAmbiguous(x)) return "ambiguous";
|
|
23
|
+
if (isFullWidth(x)) return "fullwidth";
|
|
24
|
+
if (x === 8361 || x >= 65377 && x <= 65470 || x >= 65474 && x <= 65479 || x >= 65482 && x <= 65487 || x >= 65490 && x <= 65495 || x >= 65498 && x <= 65500 || x >= 65512 && x <= 65518) {
|
|
25
|
+
return "halfwidth";
|
|
26
|
+
}
|
|
27
|
+
if (x >= 32 && x <= 126 || x === 162 || x === 163 || x === 165 || x === 166 || x === 172 || x === 175 || x >= 10214 && x <= 10221 || x === 10629 || x === 10630) {
|
|
28
|
+
return "narrow";
|
|
29
|
+
}
|
|
30
|
+
if (isWide(x)) return "wide";
|
|
31
|
+
return "neutral";
|
|
32
|
+
}
|
|
33
|
+
__name$2(getCategory, "getCategory");
|
|
34
|
+
|
|
35
|
+
var __defProp$1 = Object.defineProperty;
|
|
36
|
+
var __name$1 = (target, value) => __defProp$1(target, "name", { value, configurable: true });
|
|
37
|
+
function validate(codePoint) {
|
|
38
|
+
if (!Number.isSafeInteger(codePoint)) {
|
|
39
|
+
throw new TypeError(`Expected a code point, got \`${typeof codePoint}\`.`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
__name$1(validate, "validate");
|
|
43
|
+
function eastAsianWidthType(codePoint) {
|
|
44
|
+
validate(codePoint);
|
|
45
|
+
return getCategory(codePoint);
|
|
46
|
+
}
|
|
47
|
+
__name$1(eastAsianWidthType, "eastAsianWidthType");
|
|
48
|
+
function eastAsianWidth(codePoint, { ambiguousAsWide = false } = {}) {
|
|
49
|
+
validate(codePoint);
|
|
50
|
+
if (isFullWidth(codePoint) || isWide(codePoint) || ambiguousAsWide && isAmbiguous(codePoint)) {
|
|
51
|
+
return 2;
|
|
52
|
+
}
|
|
53
|
+
return 1;
|
|
54
|
+
}
|
|
55
|
+
__name$1(eastAsianWidth, "eastAsianWidth");
|
|
56
|
+
|
|
57
|
+
var __defProp = Object.defineProperty;
|
|
58
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
59
|
+
const charWidthCache = /* @__PURE__ */ new Map();
|
|
60
|
+
const RE_LATIN_CHARS = /(?:[\u0020-\u007E\u00A0-\u00FF](?!\uFE0F)){1,1000}/y;
|
|
61
|
+
const getCharType = /* @__PURE__ */ __name((codePoint) => {
|
|
62
|
+
if (codePoint >= 32 && codePoint <= 126) {
|
|
63
|
+
return "latin";
|
|
64
|
+
}
|
|
65
|
+
if (codePoint === 8203 || codePoint === 8204 || codePoint === 8205 || codePoint === 8288) {
|
|
66
|
+
return "zero";
|
|
67
|
+
}
|
|
68
|
+
if (codePoint <= 31 || codePoint >= 127 && codePoint <= 159) {
|
|
69
|
+
return "control";
|
|
70
|
+
}
|
|
71
|
+
if (codePoint >= 160 && codePoint <= 255) {
|
|
72
|
+
return "latin";
|
|
73
|
+
}
|
|
74
|
+
if (codePoint >= 4352 && codePoint <= 4607 || // Hangul Jamo
|
|
75
|
+
codePoint >= 11904 && codePoint <= 40959 || // CJK & radicals
|
|
76
|
+
codePoint >= 44032 && codePoint <= 55215 || // Hangul Syllables
|
|
77
|
+
codePoint >= 63744 && codePoint <= 64255 || // CJK Compatibility Ideographs
|
|
78
|
+
codePoint >= 65280 && codePoint <= 65519 && !(codePoint >= 65377 && codePoint <= 65439) || // Full-width Forms (excluding half-width katakana)
|
|
79
|
+
codePoint >= 12352 && codePoint <= 12543) {
|
|
80
|
+
return "wide";
|
|
81
|
+
}
|
|
82
|
+
return "other";
|
|
83
|
+
}, "getCharType");
|
|
84
|
+
const getCachedCharWidth = /* @__PURE__ */ __name((codePoint, config) => {
|
|
85
|
+
const highBits = Math.floor(codePoint / 65536);
|
|
86
|
+
const lowBits = codePoint % 65536;
|
|
87
|
+
let lowMap = charWidthCache.get(highBits);
|
|
88
|
+
if (!lowMap) {
|
|
89
|
+
lowMap = /* @__PURE__ */ new Map();
|
|
90
|
+
charWidthCache.set(highBits, lowMap);
|
|
91
|
+
}
|
|
92
|
+
if (lowMap.has(lowBits)) {
|
|
93
|
+
return lowMap.get(lowBits);
|
|
94
|
+
}
|
|
95
|
+
let width;
|
|
96
|
+
if (getCharType(codePoint) === "latin") {
|
|
97
|
+
width = config.width.regular;
|
|
98
|
+
} else if (getCharType(codePoint) === "control") {
|
|
99
|
+
width = config.width.control;
|
|
100
|
+
} else if (getCharType(codePoint) === "wide") {
|
|
101
|
+
width = config.width.wide;
|
|
102
|
+
} else {
|
|
103
|
+
const eaw = eastAsianWidthType(codePoint);
|
|
104
|
+
switch (eaw) {
|
|
105
|
+
case "fullwidth": {
|
|
106
|
+
width = config.width.fullWidth;
|
|
107
|
+
break;
|
|
108
|
+
}
|
|
109
|
+
case "wide": {
|
|
110
|
+
width = config.width.wide;
|
|
111
|
+
break;
|
|
112
|
+
}
|
|
113
|
+
case "ambiguous": {
|
|
114
|
+
width = config.width.ambiguousIsNarrow ? config.width.regular : config.width.wide;
|
|
115
|
+
break;
|
|
116
|
+
}
|
|
117
|
+
default: {
|
|
118
|
+
width = config.width.regular;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
lowMap.set(lowBits, width);
|
|
123
|
+
return width;
|
|
124
|
+
}, "getCachedCharWidth");
|
|
125
|
+
const isCombiningCharacter = /* @__PURE__ */ __name((codePoint) => {
|
|
126
|
+
if (codePoint >= 768 && codePoint <= 879 || // Combining Diacritical Marks
|
|
127
|
+
codePoint >= 6832 && codePoint <= 6911 || // Combining Diacritical Marks Extended
|
|
128
|
+
codePoint >= 7616 && codePoint <= 7679 || // Combining Diacritical Marks Supplement
|
|
129
|
+
codePoint >= 8400 && codePoint <= 8447 || // Combining Diacritical Marks for Symbols
|
|
130
|
+
codePoint >= 65056 && codePoint <= 65071) {
|
|
131
|
+
return true;
|
|
132
|
+
}
|
|
133
|
+
if (codePoint >= 917760 && codePoint <= 917999 || // Variation Selectors Supplement
|
|
134
|
+
codePoint >= 65024 && codePoint <= 65039) {
|
|
135
|
+
return true;
|
|
136
|
+
}
|
|
137
|
+
if (codePoint >= 3633 && codePoint <= 3642 || // Thai vowel marks and tone marks
|
|
138
|
+
codePoint >= 3655 && codePoint <= 3662 || // Thai diacritics
|
|
139
|
+
codePoint >= 3761 && codePoint <= 3769 || // Lao vowel marks
|
|
140
|
+
codePoint >= 3771 && codePoint <= 3772 || // Lao vowel signs
|
|
141
|
+
codePoint >= 3784 && codePoint <= 3789) {
|
|
142
|
+
return true;
|
|
143
|
+
}
|
|
144
|
+
if (codePoint >= 2304 && codePoint <= 2307 || // Devanagari signs
|
|
145
|
+
codePoint >= 2362 && codePoint <= 2383 || // Devanagari vowel signs and virama
|
|
146
|
+
codePoint >= 2385 && codePoint <= 2391 || // Devanagari stress marks
|
|
147
|
+
codePoint >= 2402 && codePoint <= 2403 || // Devanagari vowel signs
|
|
148
|
+
codePoint >= 2433 && codePoint <= 2435 || // Bengali signs
|
|
149
|
+
codePoint >= 2492 && codePoint <= 2500 || // Bengali vowel signs
|
|
150
|
+
codePoint >= 2509 && codePoint <= 2509 || // Bengali virama
|
|
151
|
+
codePoint >= 2561 && codePoint <= 2563 || // Gurmukhi signs
|
|
152
|
+
codePoint >= 2620 && codePoint <= 2637) {
|
|
153
|
+
return true;
|
|
154
|
+
}
|
|
155
|
+
if (codePoint >= 1611 && codePoint <= 1631 || // Arabic diacritics
|
|
156
|
+
codePoint >= 1648 && codePoint <= 1648 || // Arabic letter superscript alef
|
|
157
|
+
codePoint >= 1750 && codePoint <= 1773 || // Arabic small high signs
|
|
158
|
+
codePoint >= 2276 && codePoint <= 2302) {
|
|
159
|
+
return true;
|
|
160
|
+
}
|
|
161
|
+
if (codePoint >= 1425 && codePoint <= 1469 || // Hebrew points
|
|
162
|
+
codePoint >= 1471 && codePoint <= 1471 || // Hebrew point rafe
|
|
163
|
+
codePoint >= 1473 && codePoint <= 1474 || // Hebrew points
|
|
164
|
+
codePoint >= 1476 && codePoint <= 1477 || // Hebrew marks
|
|
165
|
+
codePoint >= 1479 && codePoint <= 1479) {
|
|
166
|
+
return true;
|
|
167
|
+
}
|
|
168
|
+
if (codePoint >= 3893 && codePoint <= 3893 || // Tibetan mark nada
|
|
169
|
+
codePoint >= 3895 && codePoint <= 3895 || // Tibetan mark nada
|
|
170
|
+
codePoint >= 3897 && codePoint <= 3897 || // Tibetan mark tsa phru
|
|
171
|
+
codePoint >= 3953 && codePoint <= 3966 || // Tibetan vowel signs
|
|
172
|
+
codePoint >= 3968 && codePoint <= 3972 || // Tibetan vowel signs and virama
|
|
173
|
+
codePoint >= 3974 && codePoint <= 3975) {
|
|
174
|
+
return true;
|
|
175
|
+
}
|
|
176
|
+
return codePoint >= 768 && codePoint <= 777 || // Combining diacritical marks used in Vietnamese
|
|
177
|
+
codePoint >= 803 && codePoint <= 803;
|
|
178
|
+
}, "isCombiningCharacter");
|
|
179
|
+
const getStringTruncatedWidth = /* @__PURE__ */ __name((input, options = {}) => {
|
|
180
|
+
if (!input || input.length === 0) {
|
|
181
|
+
return { ellipsed: false, index: 0, truncated: false, width: 0 };
|
|
182
|
+
}
|
|
183
|
+
const config = {
|
|
184
|
+
truncation: {
|
|
185
|
+
ellipsis: options.ellipsis ?? "",
|
|
186
|
+
ellipsisWidth: options.ellipsisWidth ?? (options.ellipsis ? getStringTruncatedWidth(options.ellipsis, {
|
|
187
|
+
...options,
|
|
188
|
+
ellipsis: "",
|
|
189
|
+
ellipsisWidth: 0,
|
|
190
|
+
limit: Number.POSITIVE_INFINITY
|
|
191
|
+
}).width : 0),
|
|
192
|
+
limit: options.limit ?? Number.POSITIVE_INFINITY
|
|
193
|
+
},
|
|
194
|
+
width: {
|
|
195
|
+
ambiguous: options.ambiguousWidth ?? 1,
|
|
196
|
+
ambiguousIsNarrow: options.ambiguousIsNarrow ?? false,
|
|
197
|
+
ansi: options.ansiWidth ?? 0,
|
|
198
|
+
control: options.controlWidth ?? 0,
|
|
199
|
+
emoji: options.emojiWidth ?? 2,
|
|
200
|
+
fullWidth: options.fullWidth ?? 2,
|
|
201
|
+
halfWidth: options.halfWidth ?? 1,
|
|
202
|
+
regular: options.regularWidth ?? 1,
|
|
203
|
+
tab: options.tabWidth ?? 8,
|
|
204
|
+
wide: options.wideWidth ?? 2
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
const truncationLimit = Math.max(0, config.truncation.limit - config.truncation.ellipsisWidth);
|
|
208
|
+
const { length } = input;
|
|
209
|
+
const useCaching = length > 1e4;
|
|
210
|
+
let index = 0;
|
|
211
|
+
let width = 0;
|
|
212
|
+
let truncationIndex = length;
|
|
213
|
+
let truncationEnabled = false;
|
|
214
|
+
const hasAnsi = input.includes("\x1B") || input.includes("");
|
|
215
|
+
while (index < length) {
|
|
216
|
+
if (hasAnsi && (input[index] === "\x1B" || input[index] === "")) {
|
|
217
|
+
constants.RE_ANSI.lastIndex = index;
|
|
218
|
+
if (constants.RE_ANSI.test(input)) {
|
|
219
|
+
const ansiLength = constants.RE_ANSI.lastIndex - index;
|
|
220
|
+
const ansiWidth = options.countAnsiEscapeCodes ? ansiLength : config.width.ansi;
|
|
221
|
+
if (index + 3 < length && input.slice(index, index + 4) === "\x1B]8;") {
|
|
222
|
+
const startPos = constants.RE_ANSI.lastIndex;
|
|
223
|
+
constants.RE_ANSI_LINK_END.lastIndex = startPos;
|
|
224
|
+
if (constants.RE_ANSI_LINK_END.test(input)) {
|
|
225
|
+
const endPos = constants.RE_ANSI_LINK_END.lastIndex;
|
|
226
|
+
const textContent = input.slice(startPos, endPos - 5);
|
|
227
|
+
const textWidth = textContent.length;
|
|
228
|
+
if (width + textWidth > truncationLimit) {
|
|
229
|
+
truncationIndex = Math.min(truncationIndex, startPos);
|
|
230
|
+
if (width + textWidth > config.truncation.limit) {
|
|
231
|
+
truncationEnabled = true;
|
|
232
|
+
break;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
width += textWidth;
|
|
236
|
+
index = endPos;
|
|
237
|
+
continue;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
if (width + ansiWidth > truncationLimit) {
|
|
241
|
+
truncationIndex = Math.min(truncationIndex, index);
|
|
242
|
+
if (width + ansiWidth > config.truncation.limit) {
|
|
243
|
+
truncationEnabled = true;
|
|
244
|
+
break;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
width += ansiWidth;
|
|
248
|
+
index = constants.RE_ANSI.lastIndex;
|
|
249
|
+
continue;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
const charCode = input.codePointAt(index);
|
|
253
|
+
if (charCode === 8203 || charCode === 65279 || charCode >= 8288 && charCode <= 8292) {
|
|
254
|
+
index++;
|
|
255
|
+
continue;
|
|
256
|
+
}
|
|
257
|
+
if (charCode === 9) {
|
|
258
|
+
if (width + config.width.tab > truncationLimit) {
|
|
259
|
+
truncationIndex = Math.min(truncationIndex, index);
|
|
260
|
+
if (width + config.width.tab > config.truncation.limit) {
|
|
261
|
+
truncationEnabled = true;
|
|
262
|
+
break;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
width += config.width.tab;
|
|
266
|
+
index++;
|
|
267
|
+
continue;
|
|
268
|
+
}
|
|
269
|
+
RE_LATIN_CHARS.lastIndex = index;
|
|
270
|
+
if (RE_LATIN_CHARS.test(input)) {
|
|
271
|
+
const latinLength = RE_LATIN_CHARS.lastIndex - index;
|
|
272
|
+
const latinWidth = latinLength * config.width.regular;
|
|
273
|
+
if (width + latinWidth > truncationLimit) {
|
|
274
|
+
const charsToLimit = Math.floor((truncationLimit - width) / config.width.regular);
|
|
275
|
+
truncationIndex = Math.min(truncationIndex, index + charsToLimit);
|
|
276
|
+
if (width + latinWidth > config.truncation.limit) {
|
|
277
|
+
truncationEnabled = true;
|
|
278
|
+
break;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
width += latinWidth;
|
|
282
|
+
index = RE_LATIN_CHARS.lastIndex;
|
|
283
|
+
continue;
|
|
284
|
+
}
|
|
285
|
+
if (charCode <= 31 || charCode >= 127 && charCode <= 159) {
|
|
286
|
+
constants.RE_CONTROL.lastIndex = index;
|
|
287
|
+
if (constants.RE_CONTROL.test(input)) {
|
|
288
|
+
const controlLength = constants.RE_CONTROL.lastIndex - index;
|
|
289
|
+
const controlWidth = controlLength * config.width.control;
|
|
290
|
+
if (width + controlWidth > truncationLimit) {
|
|
291
|
+
truncationIndex = Math.min(truncationIndex, index + Math.floor((truncationLimit - width) / config.width.control));
|
|
292
|
+
if (width + controlWidth > config.truncation.limit) {
|
|
293
|
+
truncationEnabled = true;
|
|
294
|
+
break;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
width += controlWidth;
|
|
298
|
+
index = constants.RE_CONTROL.lastIndex;
|
|
299
|
+
continue;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
constants.RE_EMOJI.lastIndex = index;
|
|
303
|
+
if (constants.RE_EMOJI.test(input)) {
|
|
304
|
+
if (width + config.width.emoji > truncationLimit) {
|
|
305
|
+
truncationIndex = Math.min(truncationIndex, index);
|
|
306
|
+
if (width + config.width.emoji > config.truncation.limit) {
|
|
307
|
+
truncationEnabled = true;
|
|
308
|
+
break;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
width += config.width.emoji;
|
|
312
|
+
index = constants.RE_EMOJI.lastIndex;
|
|
313
|
+
continue;
|
|
314
|
+
}
|
|
315
|
+
const codePoint = input.codePointAt(index) ?? 0;
|
|
316
|
+
if (isCombiningCharacter(codePoint)) {
|
|
317
|
+
index += codePoint > 65535 ? 2 : 1;
|
|
318
|
+
continue;
|
|
319
|
+
}
|
|
320
|
+
let charWidth;
|
|
321
|
+
if (useCaching) {
|
|
322
|
+
charWidth = getCachedCharWidth(codePoint, config);
|
|
323
|
+
} else {
|
|
324
|
+
const charType = getCharType(codePoint);
|
|
325
|
+
switch (charType) {
|
|
326
|
+
case "latin": {
|
|
327
|
+
charWidth = config.width.regular;
|
|
328
|
+
break;
|
|
329
|
+
}
|
|
330
|
+
case "control": {
|
|
331
|
+
charWidth = config.width.control;
|
|
332
|
+
break;
|
|
333
|
+
}
|
|
334
|
+
case "wide": {
|
|
335
|
+
charWidth = config.width.wide;
|
|
336
|
+
break;
|
|
337
|
+
}
|
|
338
|
+
case "zero": {
|
|
339
|
+
charWidth = 0;
|
|
340
|
+
break;
|
|
341
|
+
}
|
|
342
|
+
default: {
|
|
343
|
+
const eaw = eastAsianWidthType(codePoint);
|
|
344
|
+
switch (eaw) {
|
|
345
|
+
case "fullwidth": {
|
|
346
|
+
charWidth = config.width.fullWidth;
|
|
347
|
+
break;
|
|
348
|
+
}
|
|
349
|
+
case "wide": {
|
|
350
|
+
charWidth = config.width.wide;
|
|
351
|
+
break;
|
|
352
|
+
}
|
|
353
|
+
case "ambiguous": {
|
|
354
|
+
charWidth = config.width.ambiguousIsNarrow ? config.width.regular : config.width.wide;
|
|
355
|
+
break;
|
|
356
|
+
}
|
|
357
|
+
default: {
|
|
358
|
+
charWidth = config.width.regular;
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
if (width + charWidth > truncationLimit) {
|
|
365
|
+
truncationIndex = Math.min(truncationIndex, index);
|
|
366
|
+
if (width + charWidth > config.truncation.limit) {
|
|
367
|
+
truncationEnabled = true;
|
|
368
|
+
break;
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
width += charWidth;
|
|
372
|
+
index += codePoint > 65535 ? 2 : 1;
|
|
373
|
+
}
|
|
374
|
+
let finalWidth = width;
|
|
375
|
+
if (truncationEnabled && config.truncation.limit >= config.truncation.ellipsisWidth) {
|
|
376
|
+
finalWidth = Math.min(truncationLimit + config.truncation.ellipsisWidth, config.truncation.limit);
|
|
377
|
+
}
|
|
378
|
+
return {
|
|
379
|
+
ellipsed: truncationEnabled && config.truncation.limit >= config.truncation.ellipsisWidth,
|
|
380
|
+
index: truncationEnabled ? truncationIndex : length,
|
|
381
|
+
truncated: truncationEnabled,
|
|
382
|
+
width: finalWidth
|
|
383
|
+
};
|
|
384
|
+
}, "getStringTruncatedWidth");
|
|
385
|
+
|
|
386
|
+
exports.getStringTruncatedWidth = getStringTruncatedWidth;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
interface StringTruncatedWidthOptions {
|
|
2
|
+
ambiguousIsNarrow?: boolean;
|
|
3
|
+
ambiguousWidth?: number;
|
|
4
|
+
ansiWidth?: number;
|
|
5
|
+
controlWidth?: number;
|
|
6
|
+
countAnsiEscapeCodes?: boolean;
|
|
7
|
+
ellipsis?: string;
|
|
8
|
+
ellipsisWidth?: number;
|
|
9
|
+
emojiWidth?: number;
|
|
10
|
+
fullWidth?: number;
|
|
11
|
+
halfWidth?: number;
|
|
12
|
+
limit?: number;
|
|
13
|
+
regularWidth?: number;
|
|
14
|
+
tabWidth?: number;
|
|
15
|
+
wideWidth?: number;
|
|
16
|
+
}
|
|
17
|
+
interface StringTruncatedWidthResult {
|
|
18
|
+
ellipsed: boolean;
|
|
19
|
+
index: number;
|
|
20
|
+
truncated: boolean;
|
|
21
|
+
width: number;
|
|
22
|
+
}
|
|
23
|
+
declare const getStringTruncatedWidth: (input: string, options?: StringTruncatedWidthOptions) => StringTruncatedWidthResult;
|
|
24
|
+
|
|
25
|
+
export { type StringTruncatedWidthOptions, type StringTruncatedWidthResult, getStringTruncatedWidth };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
interface StringTruncatedWidthOptions {
|
|
2
|
+
ambiguousIsNarrow?: boolean;
|
|
3
|
+
ambiguousWidth?: number;
|
|
4
|
+
ansiWidth?: number;
|
|
5
|
+
controlWidth?: number;
|
|
6
|
+
countAnsiEscapeCodes?: boolean;
|
|
7
|
+
ellipsis?: string;
|
|
8
|
+
ellipsisWidth?: number;
|
|
9
|
+
emojiWidth?: number;
|
|
10
|
+
fullWidth?: number;
|
|
11
|
+
halfWidth?: number;
|
|
12
|
+
limit?: number;
|
|
13
|
+
regularWidth?: number;
|
|
14
|
+
tabWidth?: number;
|
|
15
|
+
wideWidth?: number;
|
|
16
|
+
}
|
|
17
|
+
interface StringTruncatedWidthResult {
|
|
18
|
+
ellipsed: boolean;
|
|
19
|
+
index: number;
|
|
20
|
+
truncated: boolean;
|
|
21
|
+
width: number;
|
|
22
|
+
}
|
|
23
|
+
declare const getStringTruncatedWidth: (input: string, options?: StringTruncatedWidthOptions) => StringTruncatedWidthResult;
|
|
24
|
+
|
|
25
|
+
export { type StringTruncatedWidthOptions, type StringTruncatedWidthResult, getStringTruncatedWidth };
|