@visulima/string 2.0.3 → 2.0.4
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 +15 -0
- package/dist/align-text.js +32 -2
- package/dist/case/camel-case.js +55 -1
- package/dist/case/capital-case.js +47 -1
- package/dist/case/constant-case.js +7 -1
- package/dist/case/dot-case.js +7 -1
- package/dist/case/flat-case.js +7 -1
- package/dist/case/flip-case.js +76 -1
- package/dist/case/identify-case.js +65 -1
- package/dist/case/index.js +20 -1
- package/dist/case/kebab-case.js +55 -1
- package/dist/case/lower-first.js +9 -1
- package/dist/case/no-case.js +7 -1
- package/dist/case/pascal-case.js +48 -1
- package/dist/case/pascal-snake-case.js +28 -1
- package/dist/case/path-case.js +7 -1
- package/dist/case/sentence-case.js +54 -1
- package/dist/case/snake-case.js +7 -1
- package/dist/case/split-by-case.js +644 -1
- package/dist/case/title-case.js +42 -1
- package/dist/case/train-case.js +40 -1
- package/dist/case/upper-first.js +9 -1
- package/dist/closest-string.js +25 -1
- package/dist/compare-similarity.js +12 -1
- package/dist/get-string-truncated-width.js +363 -1
- package/dist/get-string-width.js +5 -1
- package/dist/index.js +36 -1
- package/dist/outdent.js +118 -1
- package/dist/packem_shared/LRUCache-3r3SovvR.js +46 -0
- package/dist/packem_shared/closest-IHuSvnSn.js +139 -0
- package/dist/packem_shared/closestN-BREy4E7C.js +19 -0
- package/dist/packem_shared/constants-CTzC6Gjg.js +95 -0
- package/dist/packem_shared/generate-cache-key-DdayDfjV.js +6 -0
- package/dist/packem_shared/joinSegments-CuU8RGpP.js +44 -0
- package/dist/packem_shared/normalize-german-eszett-DEB8-ZPT.js +7 -0
- package/dist/packem_shared/replaceString-vYvRBMfC.js +190 -0
- package/dist/packem_shared/transliterate-CUF6Ggy_.js +47776 -0
- package/dist/slice.js +413 -1
- package/dist/slugify.js +46 -1
- package/dist/test/utils.js +88 -13
- package/dist/test/vitest.js +5 -1
- package/dist/truncate.js +89 -1
- package/dist/utilities.js +54 -1
- package/dist/word-similarity-sort.js +22 -1
- package/dist/word-wrap.js +637 -8
- package/package.json +1 -1
- package/dist/packem_shared/LRUCache-Bjo6gsbC.js +0 -1
- package/dist/packem_shared/closest-uarbVSbs.js +0 -1
- package/dist/packem_shared/closestN-DjNxwK0t.js +0 -1
- package/dist/packem_shared/constants-CDcaCZKC.js +0 -1
- package/dist/packem_shared/generate-cache-key-DPByFaMH.js +0 -1
- package/dist/packem_shared/joinSegments-DTGeJBZG.js +0 -1
- package/dist/packem_shared/normalize-german-eszett-4k1qRtEP.js +0 -1
- package/dist/packem_shared/replaceString-DwIZyvoL.js +0 -1
- package/dist/packem_shared/transliterate-CxVHmZUa.js +0 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,18 @@
|
|
|
1
|
+
## @visulima/string [2.0.4](https://github.com/visulima/visulima/compare/@visulima/string@2.0.3...@visulima/string@2.0.4) (2025-11-07)
|
|
2
|
+
|
|
3
|
+
### Bug Fixes
|
|
4
|
+
|
|
5
|
+
* update TypeScript configurations and improve linting across multiple packages ([6f25ec7](https://github.com/visulima/visulima/commit/6f25ec7841da7246f8f9166efc5292a7089d37ee))
|
|
6
|
+
|
|
7
|
+
### Miscellaneous Chores
|
|
8
|
+
|
|
9
|
+
* update npm and pnpm configurations for monorepo optimization ([#564](https://github.com/visulima/visulima/issues/564)) ([5512b42](https://github.com/visulima/visulima/commit/5512b42f672c216b6a3c9e39035199a4ebd9a4b8))
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
### Dependencies
|
|
13
|
+
|
|
14
|
+
* **@visulima/colorize:** upgraded to 1.4.27
|
|
15
|
+
|
|
1
16
|
## @visulima/string [2.0.3](https://github.com/visulima/visulima/compare/@visulima/string@2.0.2...@visulima/string@2.0.3) (2025-11-05)
|
|
2
17
|
|
|
3
18
|
### Bug Fixes
|
package/dist/align-text.js
CHANGED
|
@@ -1,2 +1,32 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { getStringWidth } from './get-string-width.js';
|
|
2
|
+
|
|
3
|
+
const halfDiff = (maxWidth, currentWidth) => Math.floor((maxWidth - currentWidth) / 2);
|
|
4
|
+
const fullDiff = (maxWidth, currentWidth) => maxWidth - currentWidth;
|
|
5
|
+
const alignText = (text, options = {}) => {
|
|
6
|
+
const align = options.align ?? "center";
|
|
7
|
+
if (align === "left") {
|
|
8
|
+
return text;
|
|
9
|
+
}
|
|
10
|
+
const split = options.split ?? "\n";
|
|
11
|
+
const pad = options.pad ?? " ";
|
|
12
|
+
const widthDiffFunction = align === "right" ? fullDiff : halfDiff;
|
|
13
|
+
let returnString = false;
|
|
14
|
+
if (!Array.isArray(text)) {
|
|
15
|
+
returnString = true;
|
|
16
|
+
text = String(text).split(split);
|
|
17
|
+
}
|
|
18
|
+
let width;
|
|
19
|
+
let maxWidth = 0;
|
|
20
|
+
text = text.map((input) => {
|
|
21
|
+
input = String(input);
|
|
22
|
+
width = getStringWidth(input, options.stringWidthOptions);
|
|
23
|
+
maxWidth = Math.max(width, maxWidth);
|
|
24
|
+
return {
|
|
25
|
+
str: input,
|
|
26
|
+
width
|
|
27
|
+
};
|
|
28
|
+
}).map((object) => Array.from({ length: widthDiffFunction(maxWidth, object.width) + 1 }).join(pad) + object.str);
|
|
29
|
+
return returnString ? text.join(split) : text;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export { alignText };
|
package/dist/case/camel-case.js
CHANGED
|
@@ -1 +1,55 @@
|
|
|
1
|
-
|
|
1
|
+
import { R as RE_FAST_ANSI } from '../packem_shared/constants-CTzC6Gjg.js';
|
|
2
|
+
import LRUCache from '../packem_shared/LRUCache-3r3SovvR.js';
|
|
3
|
+
import lowerFirst from './lower-first.js';
|
|
4
|
+
import { splitByCase } from './split-by-case.js';
|
|
5
|
+
import upperFirst from './upper-first.js';
|
|
6
|
+
import { g as generateCacheKey } from '../packem_shared/generate-cache-key-DdayDfjV.js';
|
|
7
|
+
import joinSegments from '../packem_shared/joinSegments-CuU8RGpP.js';
|
|
8
|
+
import { n as normalizeGermanEszett } from '../packem_shared/normalize-german-eszett-DEB8-ZPT.js';
|
|
9
|
+
|
|
10
|
+
const defaultCacheStore = new LRUCache(1e3);
|
|
11
|
+
const camelCase = (value, options) => {
|
|
12
|
+
if (typeof value !== "string" || !value) {
|
|
13
|
+
return "";
|
|
14
|
+
}
|
|
15
|
+
const shouldCache = options?.cache ?? false;
|
|
16
|
+
const cacheStore = options?.cacheStore ?? defaultCacheStore;
|
|
17
|
+
let cacheKey;
|
|
18
|
+
if (shouldCache) {
|
|
19
|
+
cacheKey = generateCacheKey(value, options);
|
|
20
|
+
}
|
|
21
|
+
if (shouldCache && cacheKey && cacheStore.has(cacheKey)) {
|
|
22
|
+
return cacheStore.get(cacheKey);
|
|
23
|
+
}
|
|
24
|
+
let firstWord = true;
|
|
25
|
+
const result = joinSegments(
|
|
26
|
+
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((word) => {
|
|
36
|
+
if (options?.handleAnsi && RE_FAST_ANSI.test(word)) {
|
|
37
|
+
return word;
|
|
38
|
+
}
|
|
39
|
+
word = options?.locale?.startsWith("de") ? normalizeGermanEszett(word) : word;
|
|
40
|
+
word = options?.locale ? word.toLocaleLowerCase(options.locale) : word.toLowerCase();
|
|
41
|
+
if (firstWord) {
|
|
42
|
+
firstWord = false;
|
|
43
|
+
return lowerFirst(word, options);
|
|
44
|
+
}
|
|
45
|
+
return upperFirst(word, options);
|
|
46
|
+
}),
|
|
47
|
+
""
|
|
48
|
+
);
|
|
49
|
+
if (shouldCache && cacheKey) {
|
|
50
|
+
cacheStore.set(cacheKey, result);
|
|
51
|
+
}
|
|
52
|
+
return result;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export { camelCase as default };
|
|
@@ -1 +1,47 @@
|
|
|
1
|
-
|
|
1
|
+
import { R as RE_FAST_ANSI } from '../packem_shared/constants-CTzC6Gjg.js';
|
|
2
|
+
import LRUCache from '../packem_shared/LRUCache-3r3SovvR.js';
|
|
3
|
+
import { splitByCase } from './split-by-case.js';
|
|
4
|
+
import upperFirst from './upper-first.js';
|
|
5
|
+
import { g as generateCacheKey } from '../packem_shared/generate-cache-key-DdayDfjV.js';
|
|
6
|
+
import joinSegments from '../packem_shared/joinSegments-CuU8RGpP.js';
|
|
7
|
+
import { n as normalizeGermanEszett } from '../packem_shared/normalize-german-eszett-DEB8-ZPT.js';
|
|
8
|
+
|
|
9
|
+
const defaultCacheStore = new LRUCache(1e3);
|
|
10
|
+
const capitalCase = (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 words = 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
|
+
});
|
|
33
|
+
const processed = words.map((word) => {
|
|
34
|
+
if (RE_FAST_ANSI.test(word)) {
|
|
35
|
+
return word;
|
|
36
|
+
}
|
|
37
|
+
const split = options?.locale?.startsWith("de") ? normalizeGermanEszett(word) : word;
|
|
38
|
+
return upperFirst(options?.locale ? split.toLocaleLowerCase(options.locale) : split.toLocaleLowerCase(), options);
|
|
39
|
+
});
|
|
40
|
+
const result = joinSegments(processed, " ");
|
|
41
|
+
if (shouldCache && cacheKey) {
|
|
42
|
+
cacheStore.set(cacheKey, result);
|
|
43
|
+
}
|
|
44
|
+
return result;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export { capitalCase as default };
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import LRUCache from '../packem_shared/LRUCache-3r3SovvR.js';
|
|
2
|
+
import { kebabCase } from './kebab-case.js';
|
|
3
|
+
|
|
4
|
+
const defaultCacheStore = new LRUCache(1e3);
|
|
5
|
+
const constantCase = (value, options) => kebabCase(value, { cacheStore: defaultCacheStore, ...options, joiner: "_", toUpperCase: true });
|
|
6
|
+
|
|
7
|
+
export { constantCase as default };
|
package/dist/case/dot-case.js
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import LRUCache from '../packem_shared/LRUCache-3r3SovvR.js';
|
|
2
|
+
import { kebabCase } from './kebab-case.js';
|
|
3
|
+
|
|
4
|
+
const defaultCacheStore = new LRUCache(1e3);
|
|
5
|
+
const dotCase = (value, options) => kebabCase(value, { cacheStore: defaultCacheStore, ...options, joiner: "." });
|
|
6
|
+
|
|
7
|
+
export { dotCase as default };
|
package/dist/case/flat-case.js
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import LRUCache from '../packem_shared/LRUCache-3r3SovvR.js';
|
|
2
|
+
import { kebabCase } from './kebab-case.js';
|
|
3
|
+
|
|
4
|
+
const defaultCacheStore = new LRUCache(1e3);
|
|
5
|
+
const flatCase = (value, options) => kebabCase(value, { cacheStore: defaultCacheStore, ...options, joiner: "" });
|
|
6
|
+
|
|
7
|
+
export { flatCase as default };
|
package/dist/case/flip-case.js
CHANGED
|
@@ -1 +1,76 @@
|
|
|
1
|
-
|
|
1
|
+
import { createRequire as __cjs_createRequire } from "node:module";
|
|
2
|
+
|
|
3
|
+
const __cjs_require = __cjs_createRequire(import.meta.url);
|
|
4
|
+
|
|
5
|
+
const __cjs_getProcess = typeof globalThis !== "undefined" && typeof globalThis.process !== "undefined" ? globalThis.process : process;
|
|
6
|
+
|
|
7
|
+
const __cjs_getBuiltinModule = (module) => {
|
|
8
|
+
// Check if we're in Node.js and version supports getBuiltinModule
|
|
9
|
+
if (typeof __cjs_getProcess !== "undefined" && __cjs_getProcess.versions && __cjs_getProcess.versions.node) {
|
|
10
|
+
const [major, minor] = __cjs_getProcess.versions.node.split(".").map(Number);
|
|
11
|
+
// Node.js 20.16.0+ and 22.3.0+
|
|
12
|
+
if (major > 22 || (major === 22 && minor >= 3) || (major === 20 && minor >= 16)) {
|
|
13
|
+
return __cjs_getProcess.getBuiltinModule(module);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
// Fallback to createRequire
|
|
17
|
+
return __cjs_require(module);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const {
|
|
21
|
+
stripVTControlCharacters
|
|
22
|
+
} = __cjs_getBuiltinModule("node:util");
|
|
23
|
+
import { s as stripEmoji } from '../packem_shared/constants-CTzC6Gjg.js';
|
|
24
|
+
import LRUCache from '../packem_shared/LRUCache-3r3SovvR.js';
|
|
25
|
+
import { g as generateCacheKey } from '../packem_shared/generate-cache-key-DdayDfjV.js';
|
|
26
|
+
|
|
27
|
+
const defaultCacheStore = new LRUCache(1e3);
|
|
28
|
+
const flipCase = (value, options) => {
|
|
29
|
+
if (typeof value !== "string" || value.length === 0) {
|
|
30
|
+
return "";
|
|
31
|
+
}
|
|
32
|
+
const shouldCache = options?.cache ?? false;
|
|
33
|
+
const cacheStore = options?.cacheStore ?? defaultCacheStore;
|
|
34
|
+
let cacheKey;
|
|
35
|
+
if (shouldCache) {
|
|
36
|
+
cacheKey = generateCacheKey(value, options);
|
|
37
|
+
}
|
|
38
|
+
if (shouldCache && cacheKey && cacheStore.has(cacheKey)) {
|
|
39
|
+
return cacheStore.get(cacheKey);
|
|
40
|
+
}
|
|
41
|
+
let processedValue = value;
|
|
42
|
+
if (options?.stripEmoji) {
|
|
43
|
+
processedValue = stripEmoji(processedValue);
|
|
44
|
+
}
|
|
45
|
+
if (options?.stripAnsi) {
|
|
46
|
+
processedValue = stripVTControlCharacters(processedValue);
|
|
47
|
+
}
|
|
48
|
+
let result = "";
|
|
49
|
+
let index = 0;
|
|
50
|
+
while (index < processedValue.length) {
|
|
51
|
+
if (options?.handleAnsi && processedValue[index] === "\x1B") {
|
|
52
|
+
let ansiSequence = processedValue[index];
|
|
53
|
+
index += 1;
|
|
54
|
+
while (index < processedValue.length && processedValue[index] !== "m") {
|
|
55
|
+
ansiSequence += processedValue[index];
|
|
56
|
+
index += 1;
|
|
57
|
+
}
|
|
58
|
+
if (index < processedValue.length) {
|
|
59
|
+
ansiSequence += processedValue[index];
|
|
60
|
+
result += ansiSequence;
|
|
61
|
+
}
|
|
62
|
+
index += 1;
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
const char = processedValue[index];
|
|
66
|
+
const lowerChar = options?.locale ? char.toLocaleLowerCase(options.locale) : char.toLowerCase();
|
|
67
|
+
result += char === lowerChar ? options?.locale ? char.toLocaleUpperCase(options.locale) : char.toUpperCase() : lowerChar;
|
|
68
|
+
index += 1;
|
|
69
|
+
}
|
|
70
|
+
if (shouldCache && cacheKey) {
|
|
71
|
+
cacheStore.set(cacheKey, result);
|
|
72
|
+
}
|
|
73
|
+
return result;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
export { flipCase };
|
|
@@ -1 +1,65 @@
|
|
|
1
|
-
|
|
1
|
+
const IS_PASCAL_CASE = /^([A-Z][a-z]*)+$/;
|
|
2
|
+
const CONTAINS_LETTER_CASE_INSENSITIVE = /[a-z]/i;
|
|
3
|
+
const IS_UPPER_SNAKE_CASE = /^[A-Z0-9_]+$/;
|
|
4
|
+
const IS_LOWER_SNAKE_CASE = /^[a-z0-9_]+$/;
|
|
5
|
+
const IS_KEBAB_CASE = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;
|
|
6
|
+
const IS_LOWERCASE_WITH_SPACE = /^[a-z ]+$/;
|
|
7
|
+
const IS_UPPERCASE = /^[A-Z][A-Z0-9]*$/;
|
|
8
|
+
const WHITESPACE_REGEX = /\s+/;
|
|
9
|
+
const IS_NUMERIC = /^\d+$/;
|
|
10
|
+
const IS_CAMEL_CASE_LIKE = /^[a-z][a-z0-9]*(?:[A-Z][a-z0-9]*)+$/;
|
|
11
|
+
const CONTAINS_PUNCTUATION_MID_WORD = /[.!?;:,](?!\s|$)/;
|
|
12
|
+
const identifyCase = (value) => {
|
|
13
|
+
if (typeof value !== "string") {
|
|
14
|
+
throw new TypeError("Expected input to be a string");
|
|
15
|
+
}
|
|
16
|
+
if (!value) {
|
|
17
|
+
return "unknown";
|
|
18
|
+
}
|
|
19
|
+
if (!CONTAINS_LETTER_CASE_INSENSITIVE.test(value)) {
|
|
20
|
+
return "unknown";
|
|
21
|
+
}
|
|
22
|
+
if (value.includes("_")) {
|
|
23
|
+
if (IS_UPPER_SNAKE_CASE.test(value)) {
|
|
24
|
+
return "upper_snake";
|
|
25
|
+
}
|
|
26
|
+
if (IS_LOWER_SNAKE_CASE.test(value)) {
|
|
27
|
+
return "snake";
|
|
28
|
+
}
|
|
29
|
+
return "mixed";
|
|
30
|
+
}
|
|
31
|
+
if (value.includes("-")) {
|
|
32
|
+
if (IS_KEBAB_CASE.test(value)) {
|
|
33
|
+
return "kebab";
|
|
34
|
+
}
|
|
35
|
+
return "mixed";
|
|
36
|
+
}
|
|
37
|
+
if (IS_LOWERCASE_WITH_SPACE.test(value)) {
|
|
38
|
+
return "lower";
|
|
39
|
+
}
|
|
40
|
+
if (IS_UPPERCASE.test(value)) {
|
|
41
|
+
return "upper";
|
|
42
|
+
}
|
|
43
|
+
const words = value.split(WHITESPACE_REGEX);
|
|
44
|
+
if (words.length > 1 && words.every((word) => IS_PASCAL_CASE.test(word))) {
|
|
45
|
+
return "title";
|
|
46
|
+
}
|
|
47
|
+
if (words.length > 1 && IS_NUMERIC.test(words[0]) && IS_PASCAL_CASE.test(words[1])) {
|
|
48
|
+
return "title";
|
|
49
|
+
}
|
|
50
|
+
if (words.length > 1 && IS_PASCAL_CASE.test(words[0]) && /^[a-z]/.test(words[1])) {
|
|
51
|
+
return "sentence";
|
|
52
|
+
}
|
|
53
|
+
if (IS_PASCAL_CASE.test(value)) {
|
|
54
|
+
return "pascal";
|
|
55
|
+
}
|
|
56
|
+
if (IS_CAMEL_CASE_LIKE.test(value)) {
|
|
57
|
+
return "camel";
|
|
58
|
+
}
|
|
59
|
+
if (CONTAINS_PUNCTUATION_MID_WORD.test(value)) {
|
|
60
|
+
return "unknown";
|
|
61
|
+
}
|
|
62
|
+
return "mixed";
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export { identifyCase as default };
|
package/dist/case/index.js
CHANGED
|
@@ -1 +1,20 @@
|
|
|
1
|
-
|
|
1
|
+
export { default as camelCase } from './camel-case.js';
|
|
2
|
+
export { default as capitalCase } from './capital-case.js';
|
|
3
|
+
export { default as constantCase } from './constant-case.js';
|
|
4
|
+
export { default as dotCase } from './dot-case.js';
|
|
5
|
+
export { default as flatCase } from './flat-case.js';
|
|
6
|
+
export { flipCase } from './flip-case.js';
|
|
7
|
+
export { default as identifyCase } from './identify-case.js';
|
|
8
|
+
export { kebabCase } from './kebab-case.js';
|
|
9
|
+
export { default as lowerFirst } from './lower-first.js';
|
|
10
|
+
export { default as noCase } from './no-case.js';
|
|
11
|
+
export { default as pascalCase } from './pascal-case.js';
|
|
12
|
+
export { default as pascalSnakeCase } from './pascal-snake-case.js';
|
|
13
|
+
export { default as pathCase } from './path-case.js';
|
|
14
|
+
export { default as sentenceCase } from './sentence-case.js';
|
|
15
|
+
export { default as snakeCase } from './snake-case.js';
|
|
16
|
+
export { splitByCase } from './split-by-case.js';
|
|
17
|
+
export { default as titleCase } from './title-case.js';
|
|
18
|
+
export { default as trainCase } from './train-case.js';
|
|
19
|
+
export { default as upperFirst } from './upper-first.js';
|
|
20
|
+
export { default as joinSegments } from '../packem_shared/joinSegments-CuU8RGpP.js';
|
package/dist/case/kebab-case.js
CHANGED
|
@@ -1 +1,55 @@
|
|
|
1
|
-
|
|
1
|
+
import { R as RE_FAST_ANSI } from '../packem_shared/constants-CTzC6Gjg.js';
|
|
2
|
+
import LRUCache from '../packem_shared/LRUCache-3r3SovvR.js';
|
|
3
|
+
import { splitByCase } from './split-by-case.js';
|
|
4
|
+
import { g as generateCacheKey } from '../packem_shared/generate-cache-key-DdayDfjV.js';
|
|
5
|
+
import joinSegments from '../packem_shared/joinSegments-CuU8RGpP.js';
|
|
6
|
+
import { n as normalizeGermanEszett } from '../packem_shared/normalize-german-eszett-DEB8-ZPT.js';
|
|
7
|
+
|
|
8
|
+
const defaultCacheStore = new LRUCache(1e3);
|
|
9
|
+
const kebabCase = (value, options) => {
|
|
10
|
+
if (typeof value !== "string") {
|
|
11
|
+
return "";
|
|
12
|
+
}
|
|
13
|
+
const shouldCache = options?.cache ?? false;
|
|
14
|
+
const cacheStore = options?.cacheStore ?? defaultCacheStore;
|
|
15
|
+
let cacheKey;
|
|
16
|
+
if (shouldCache) {
|
|
17
|
+
cacheKey = generateCacheKey(value, options);
|
|
18
|
+
}
|
|
19
|
+
if (shouldCache && cacheKey && cacheStore.has(cacheKey)) {
|
|
20
|
+
return cacheStore.get(cacheKey);
|
|
21
|
+
}
|
|
22
|
+
const words = splitByCase(value, {
|
|
23
|
+
handleAnsi: options?.handleAnsi,
|
|
24
|
+
handleEmoji: options?.handleEmoji,
|
|
25
|
+
knownAcronyms: options?.knownAcronyms,
|
|
26
|
+
locale: options?.locale,
|
|
27
|
+
normalize: options?.normalize,
|
|
28
|
+
separators: void 0,
|
|
29
|
+
stripAnsi: options?.stripAnsi,
|
|
30
|
+
stripEmoji: options?.stripEmoji
|
|
31
|
+
});
|
|
32
|
+
const processed = words.map((word) => {
|
|
33
|
+
if (options?.handleAnsi && RE_FAST_ANSI.test(word)) {
|
|
34
|
+
return word;
|
|
35
|
+
}
|
|
36
|
+
if (options?.toUpperCase) {
|
|
37
|
+
if (options.locale) {
|
|
38
|
+
return word.toLocaleUpperCase(options.locale);
|
|
39
|
+
}
|
|
40
|
+
return word.toUpperCase();
|
|
41
|
+
}
|
|
42
|
+
const split = options?.locale?.startsWith("de") ? normalizeGermanEszett(word) : word;
|
|
43
|
+
if (options?.locale) {
|
|
44
|
+
return split.toLocaleLowerCase(options.locale);
|
|
45
|
+
}
|
|
46
|
+
return split.toLowerCase();
|
|
47
|
+
});
|
|
48
|
+
const result = joinSegments(processed, options?.joiner ?? "-");
|
|
49
|
+
if (shouldCache && cacheKey) {
|
|
50
|
+
cacheStore.set(cacheKey, result);
|
|
51
|
+
}
|
|
52
|
+
return result;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export { kebabCase };
|
package/dist/case/lower-first.js
CHANGED
|
@@ -1 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
const lowerFirst = (value, options) => {
|
|
2
|
+
if (typeof value !== "string" || value === "") {
|
|
3
|
+
return "";
|
|
4
|
+
}
|
|
5
|
+
const firstChar = options?.locale ? value[0].toLocaleLowerCase(options.locale) : value[0].toLowerCase();
|
|
6
|
+
return firstChar + value.slice(1);
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export { lowerFirst as default };
|
package/dist/case/no-case.js
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import LRUCache from '../packem_shared/LRUCache-3r3SovvR.js';
|
|
2
|
+
import { kebabCase } from './kebab-case.js';
|
|
3
|
+
|
|
4
|
+
const defaultCacheStore = new LRUCache(1e3);
|
|
5
|
+
const noCase = (value, options) => kebabCase(value, { cacheStore: defaultCacheStore, ...options, joiner: " " });
|
|
6
|
+
|
|
7
|
+
export { noCase as default };
|
package/dist/case/pascal-case.js
CHANGED
|
@@ -1 +1,48 @@
|
|
|
1
|
-
|
|
1
|
+
import { R as RE_FAST_ANSI } from '../packem_shared/constants-CTzC6Gjg.js';
|
|
2
|
+
import LRUCache from '../packem_shared/LRUCache-3r3SovvR.js';
|
|
3
|
+
import { splitByCase } from './split-by-case.js';
|
|
4
|
+
import upperFirst from './upper-first.js';
|
|
5
|
+
import { g as generateCacheKey } from '../packem_shared/generate-cache-key-DdayDfjV.js';
|
|
6
|
+
import joinSegments from '../packem_shared/joinSegments-CuU8RGpP.js';
|
|
7
|
+
import { n as normalizeGermanEszett } from '../packem_shared/normalize-german-eszett-DEB8-ZPT.js';
|
|
8
|
+
|
|
9
|
+
const defaultCacheStore = new LRUCache(1e3);
|
|
10
|
+
const pascalCase = (value, options) => {
|
|
11
|
+
if (typeof value !== "string" || !value) {
|
|
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((word) => {
|
|
34
|
+
if (options?.handleAnsi && RE_FAST_ANSI.test(word)) {
|
|
35
|
+
return word;
|
|
36
|
+
}
|
|
37
|
+
const split = options?.locale?.startsWith("de") ? normalizeGermanEszett(word) : word;
|
|
38
|
+
return upperFirst(options?.locale ? split.toLocaleLowerCase(options.locale) : split.toLowerCase(), { locale: options?.locale });
|
|
39
|
+
}),
|
|
40
|
+
""
|
|
41
|
+
);
|
|
42
|
+
if (shouldCache && cacheKey) {
|
|
43
|
+
cacheStore.set(cacheKey, result);
|
|
44
|
+
}
|
|
45
|
+
return result;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export { pascalCase as default };
|
|
@@ -1 +1,28 @@
|
|
|
1
|
-
|
|
1
|
+
import LRUCache from '../packem_shared/LRUCache-3r3SovvR.js';
|
|
2
|
+
import noCase from './no-case.js';
|
|
3
|
+
import upperFirst from './upper-first.js';
|
|
4
|
+
import { g as generateCacheKey } from '../packem_shared/generate-cache-key-DdayDfjV.js';
|
|
5
|
+
|
|
6
|
+
const defaultCacheStore = new LRUCache(1e3);
|
|
7
|
+
const pascalSnakeCase = (value, options) => {
|
|
8
|
+
if (typeof value !== "string") {
|
|
9
|
+
return "";
|
|
10
|
+
}
|
|
11
|
+
const shouldCache = options?.cache ?? false;
|
|
12
|
+
const cacheStore = options?.cacheStore ?? defaultCacheStore;
|
|
13
|
+
let cacheKey;
|
|
14
|
+
if (shouldCache) {
|
|
15
|
+
cacheKey = generateCacheKey(value, options);
|
|
16
|
+
}
|
|
17
|
+
if (shouldCache && cacheKey && cacheStore.has(cacheKey)) {
|
|
18
|
+
return cacheStore.get(cacheKey);
|
|
19
|
+
}
|
|
20
|
+
const words = noCase(value, { ...options, cache: false }).split(" ");
|
|
21
|
+
const result = words.map((word) => upperFirst(word, { locale: options?.locale })).join("_");
|
|
22
|
+
if (shouldCache && cacheKey) {
|
|
23
|
+
cacheStore.set(cacheKey, result);
|
|
24
|
+
}
|
|
25
|
+
return result;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export { pascalSnakeCase as default };
|
package/dist/case/path-case.js
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import LRUCache from '../packem_shared/LRUCache-3r3SovvR.js';
|
|
2
|
+
import { kebabCase } from './kebab-case.js';
|
|
3
|
+
|
|
4
|
+
const defaultCacheStore = new LRUCache(1e3);
|
|
5
|
+
const pathCase = (value, options) => kebabCase(value, { cacheStore: defaultCacheStore, ...options, joiner: "/" });
|
|
6
|
+
|
|
7
|
+
export { pathCase as default };
|
|
@@ -1 +1,54 @@
|
|
|
1
|
-
|
|
1
|
+
import { R as RE_FAST_ANSI } from '../packem_shared/constants-CTzC6Gjg.js';
|
|
2
|
+
import LRUCache from '../packem_shared/LRUCache-3r3SovvR.js';
|
|
3
|
+
import { splitByCase } from './split-by-case.js';
|
|
4
|
+
import upperFirst from './upper-first.js';
|
|
5
|
+
import { g as generateCacheKey } from '../packem_shared/generate-cache-key-DdayDfjV.js';
|
|
6
|
+
import joinSegments from '../packem_shared/joinSegments-CuU8RGpP.js';
|
|
7
|
+
import { n as normalizeGermanEszett } from '../packem_shared/normalize-german-eszett-DEB8-ZPT.js';
|
|
8
|
+
|
|
9
|
+
const defaultCacheStore = new LRUCache(1e3);
|
|
10
|
+
const sentenceCase = (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
|
+
let firstWord = true;
|
|
24
|
+
const result = joinSegments(
|
|
25
|
+
splitByCase(value, {
|
|
26
|
+
handleAnsi: options?.handleAnsi,
|
|
27
|
+
handleEmoji: options?.handleEmoji,
|
|
28
|
+
knownAcronyms: options?.knownAcronyms,
|
|
29
|
+
locale: options?.locale,
|
|
30
|
+
normalize: options?.normalize,
|
|
31
|
+
separators: void 0,
|
|
32
|
+
stripAnsi: options?.stripAnsi,
|
|
33
|
+
stripEmoji: options?.stripEmoji
|
|
34
|
+
}).map((word) => {
|
|
35
|
+
if (options?.handleAnsi && RE_FAST_ANSI.test(word)) {
|
|
36
|
+
return word;
|
|
37
|
+
}
|
|
38
|
+
word = options?.locale?.startsWith("de") ? normalizeGermanEszett(word) : word;
|
|
39
|
+
word = options?.locale ? word.toLocaleLowerCase(options.locale) : word.toLowerCase();
|
|
40
|
+
if (firstWord) {
|
|
41
|
+
firstWord = false;
|
|
42
|
+
return upperFirst(word, options);
|
|
43
|
+
}
|
|
44
|
+
return word;
|
|
45
|
+
}),
|
|
46
|
+
" "
|
|
47
|
+
);
|
|
48
|
+
if (shouldCache && cacheKey) {
|
|
49
|
+
cacheStore.set(cacheKey, result);
|
|
50
|
+
}
|
|
51
|
+
return result;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export { sentenceCase as default };
|
package/dist/case/snake-case.js
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import LRUCache from '../packem_shared/LRUCache-3r3SovvR.js';
|
|
2
|
+
import { kebabCase } from './kebab-case.js';
|
|
3
|
+
|
|
4
|
+
const defaultCacheStore = new LRUCache(1e3);
|
|
5
|
+
const snakeCase = (value, options) => kebabCase(value, { cacheStore: defaultCacheStore, ...options, joiner: "_" });
|
|
6
|
+
|
|
7
|
+
export { snakeCase as default };
|