@jdsalasc/solvejs-string 1.0.1 → 1.0.2
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/dist/cjs/index.cjs +33 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.d.ts +27 -0
- package/dist/esm/index.js +33 -0
- package/dist/esm/index.js.map +1 -1
- package/package.json +5 -5
package/dist/cjs/index.cjs
CHANGED
|
@@ -4,9 +4,21 @@ exports.toKebabCase = toKebabCase;
|
|
|
4
4
|
exports.toCamelCase = toCamelCase;
|
|
5
5
|
exports.capitalize = capitalize;
|
|
6
6
|
exports.truncate = truncate;
|
|
7
|
+
/**
|
|
8
|
+
* Removes combining marks to normalize accented text.
|
|
9
|
+
*
|
|
10
|
+
* @param value - Raw input string.
|
|
11
|
+
* @returns Normalized string without combining marks.
|
|
12
|
+
*/
|
|
7
13
|
function normalize(value) {
|
|
8
14
|
return value.normalize("NFKD").replace(/[\u0300-\u036f]/g, "");
|
|
9
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* Converts arbitrary text into kebab-case.
|
|
18
|
+
*
|
|
19
|
+
* @param value - Input text.
|
|
20
|
+
* @returns Kebab-cased output.
|
|
21
|
+
*/
|
|
10
22
|
function toKebabCase(value) {
|
|
11
23
|
return normalize(value)
|
|
12
24
|
.replace(/([a-z\d])([A-Z])/g, "$1-$2")
|
|
@@ -14,18 +26,39 @@ function toKebabCase(value) {
|
|
|
14
26
|
.replace(/^-+|-+$/g, "")
|
|
15
27
|
.toLowerCase();
|
|
16
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* Converts arbitrary text into camelCase.
|
|
31
|
+
*
|
|
32
|
+
* @param value - Input text.
|
|
33
|
+
* @returns camelCase output.
|
|
34
|
+
*/
|
|
17
35
|
function toCamelCase(value) {
|
|
18
36
|
const tokens = toKebabCase(value).split("-").filter(Boolean);
|
|
19
37
|
return tokens
|
|
20
38
|
.map((token, index) => (index === 0 ? token : token[0].toUpperCase() + token.slice(1)))
|
|
21
39
|
.join("");
|
|
22
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* Uppercases the first character in a string.
|
|
43
|
+
*
|
|
44
|
+
* @param value - Input text.
|
|
45
|
+
* @returns String with first character uppercased.
|
|
46
|
+
*/
|
|
23
47
|
function capitalize(value) {
|
|
24
48
|
if (value.length === 0) {
|
|
25
49
|
return value;
|
|
26
50
|
}
|
|
27
51
|
return value[0].toUpperCase() + value.slice(1);
|
|
28
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* Truncates text to a fixed size using a suffix.
|
|
55
|
+
*
|
|
56
|
+
* @param value - Input text.
|
|
57
|
+
* @param maxLength - Maximum final string length.
|
|
58
|
+
* @param suffix - Suffix appended to truncated text.
|
|
59
|
+
* @returns Truncated string.
|
|
60
|
+
* @throws {TypeError} If `maxLength` is not a non-negative integer.
|
|
61
|
+
*/
|
|
29
62
|
function truncate(value, maxLength, suffix = "...") {
|
|
30
63
|
if (!Number.isInteger(maxLength) || maxLength < 0) {
|
|
31
64
|
throw new TypeError("Expected maxLength to be a non-negative integer.");
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;AAgBA,kCAMC;AAQD,kCAKC;AAQD,gCAKC;AAWD,4BAWC;AAtED;;;;;GAKG;AACH,SAAS,SAAS,CAAC,KAAa;IAC9B,OAAO,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,kBAAkB,EAAE,EAAE,CAAC,CAAC;AACjE,CAAC;AAED;;;;;GAKG;AACH,SAAgB,WAAW,CAAC,KAAa;IACvC,OAAO,SAAS,CAAC,KAAK,CAAC;SACpB,OAAO,CAAC,mBAAmB,EAAE,OAAO,CAAC;SACrC,OAAO,CAAC,e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AAS,CAAC,CAAC;IACpC,CAAC;IACD,OAAO,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,GAAG,MAAM,EAAE,CAAC;AACjE,CAAC"}
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,4 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts arbitrary text into kebab-case.
|
|
3
|
+
*
|
|
4
|
+
* @param value - Input text.
|
|
5
|
+
* @returns Kebab-cased output.
|
|
6
|
+
*/
|
|
1
7
|
export declare function toKebabCase(value: string): string;
|
|
8
|
+
/**
|
|
9
|
+
* Converts arbitrary text into camelCase.
|
|
10
|
+
*
|
|
11
|
+
* @param value - Input text.
|
|
12
|
+
* @returns camelCase output.
|
|
13
|
+
*/
|
|
2
14
|
export declare function toCamelCase(value: string): string;
|
|
15
|
+
/**
|
|
16
|
+
* Uppercases the first character in a string.
|
|
17
|
+
*
|
|
18
|
+
* @param value - Input text.
|
|
19
|
+
* @returns String with first character uppercased.
|
|
20
|
+
*/
|
|
3
21
|
export declare function capitalize(value: string): string;
|
|
22
|
+
/**
|
|
23
|
+
* Truncates text to a fixed size using a suffix.
|
|
24
|
+
*
|
|
25
|
+
* @param value - Input text.
|
|
26
|
+
* @param maxLength - Maximum final string length.
|
|
27
|
+
* @param suffix - Suffix appended to truncated text.
|
|
28
|
+
* @returns Truncated string.
|
|
29
|
+
* @throws {TypeError} If `maxLength` is not a non-negative integer.
|
|
30
|
+
*/
|
|
4
31
|
export declare function truncate(value: string, maxLength: number, suffix?: string): string;
|
package/dist/esm/index.js
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Removes combining marks to normalize accented text.
|
|
3
|
+
*
|
|
4
|
+
* @param value - Raw input string.
|
|
5
|
+
* @returns Normalized string without combining marks.
|
|
6
|
+
*/
|
|
1
7
|
function normalize(value) {
|
|
2
8
|
return value.normalize("NFKD").replace(/[\u0300-\u036f]/g, "");
|
|
3
9
|
}
|
|
10
|
+
/**
|
|
11
|
+
* Converts arbitrary text into kebab-case.
|
|
12
|
+
*
|
|
13
|
+
* @param value - Input text.
|
|
14
|
+
* @returns Kebab-cased output.
|
|
15
|
+
*/
|
|
4
16
|
export function toKebabCase(value) {
|
|
5
17
|
return normalize(value)
|
|
6
18
|
.replace(/([a-z\d])([A-Z])/g, "$1-$2")
|
|
@@ -8,18 +20,39 @@ export function toKebabCase(value) {
|
|
|
8
20
|
.replace(/^-+|-+$/g, "")
|
|
9
21
|
.toLowerCase();
|
|
10
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* Converts arbitrary text into camelCase.
|
|
25
|
+
*
|
|
26
|
+
* @param value - Input text.
|
|
27
|
+
* @returns camelCase output.
|
|
28
|
+
*/
|
|
11
29
|
export function toCamelCase(value) {
|
|
12
30
|
const tokens = toKebabCase(value).split("-").filter(Boolean);
|
|
13
31
|
return tokens
|
|
14
32
|
.map((token, index) => (index === 0 ? token : token[0].toUpperCase() + token.slice(1)))
|
|
15
33
|
.join("");
|
|
16
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* Uppercases the first character in a string.
|
|
37
|
+
*
|
|
38
|
+
* @param value - Input text.
|
|
39
|
+
* @returns String with first character uppercased.
|
|
40
|
+
*/
|
|
17
41
|
export function capitalize(value) {
|
|
18
42
|
if (value.length === 0) {
|
|
19
43
|
return value;
|
|
20
44
|
}
|
|
21
45
|
return value[0].toUpperCase() + value.slice(1);
|
|
22
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* Truncates text to a fixed size using a suffix.
|
|
49
|
+
*
|
|
50
|
+
* @param value - Input text.
|
|
51
|
+
* @param maxLength - Maximum final string length.
|
|
52
|
+
* @param suffix - Suffix appended to truncated text.
|
|
53
|
+
* @returns Truncated string.
|
|
54
|
+
* @throws {TypeError} If `maxLength` is not a non-negative integer.
|
|
55
|
+
*/
|
|
23
56
|
export function truncate(value, maxLength, suffix = "...") {
|
|
24
57
|
if (!Number.isInteger(maxLength) || maxLength < 0) {
|
|
25
58
|
throw new TypeError("Expected maxLength to be a non-negative integer.");
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,SAAS,SAAS,CAAC,KAAa;IAC9B,OAAO,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,kBAAkB,EAAE,EAAE,CAAC,CAAC;AACjE,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,KAAa;IACvC,OAAO,SAAS,CAAC,KAAK,CAAC;SACpB,OAAO,CAAC,mBAAmB,EAAE,OAAO,CAAC;SACrC,OAAO,CAAC,eAAe,EAAE,GAAG,CAAC;SAC7B,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC;SACvB,WAAW,EAAE,CAAC;AACnB,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,KAAa;IACvC,MAAM,MAAM,GAAG,WAAW,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAC7D,OAAO,MAAM;SACV,GAAG,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;SACtF,IAAI,CAAC,EAAE,CAAC,CAAC;AACd,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,KAAa;IACtC,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACvB,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAA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
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "String utilities for casing,
|
|
3
|
+
"version": "1.0.2",
|
|
4
|
+
"description": "String utilities for casing, normalization, and truncation in JavaScript and TypeScript applications.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"sideEffects": false,
|
|
@@ -43,10 +43,10 @@
|
|
|
43
43
|
"node": ">=18"
|
|
44
44
|
},
|
|
45
45
|
"keywords": [
|
|
46
|
-
"string
|
|
47
|
-
"kebab case",
|
|
46
|
+
"string utilities",
|
|
48
47
|
"camel case",
|
|
49
|
-
"
|
|
48
|
+
"kebab case",
|
|
49
|
+
"truncate string",
|
|
50
50
|
"solvejs"
|
|
51
51
|
]
|
|
52
52
|
}
|