@pixpilot/string 2.1.1 → 2.2.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/dist/_virtual/rolldown_runtime.cjs +1 -0
- package/dist/case.cjs +1 -0
- package/dist/case.d.cts +51 -0
- package/dist/case.d.ts +15 -12
- package/dist/case.js +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +5 -0
- package/dist/index.d.ts +5 -4
- package/dist/index.js +1 -1
- package/dist/manipulation.cjs +1 -0
- package/dist/manipulation.d.cts +158 -0
- package/dist/manipulation.d.ts +14 -11
- package/dist/manipulation.js +1 -0
- package/dist/type-guards.cjs +1 -0
- package/dist/type-guards.d.cts +17 -0
- package/dist/type-guards.d.ts +4 -1
- package/dist/type-guards.js +1 -0
- package/dist/validation.cjs +1 -0
- package/dist/validation.d.cts +59 -0
- package/dist/validation.d.ts +7 -4
- package/dist/validation.js +1 -0
- package/package.json +7 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));exports.__toESM=s;
|
package/dist/case.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=require(`./_virtual/rolldown_runtime.cjs`);let t=require(`change-case`);t=e.__toESM(t);function n(e){return(0,t.camelCase)(e)}function r(e){return(0,t.capitalCase)(e)}function i(e){return(0,t.constantCase)(e)}function a(e){return(0,t.dotCase)(e)}function o(e){return(0,t.kebabCase)(e)}function s(e){return(0,t.noCase)(e)}function c(e){return(0,t.pascalCase)(e)}function l(e){return(0,t.pascalSnakeCase)(e)}function u(e){return(0,t.pathCase)(e)}function d(e){return(0,t.sentenceCase)(e)}function f(e){return(0,t.snakeCase)(e)}function p(e){return(0,t.trainCase)(e)}exports.toCamelCase=n,exports.toCapitalCase=r,exports.toConstantCase=i,exports.toDotCase=a,exports.toKebabCase=o,exports.toNoCase=s,exports.toPascalCase=c,exports.toPascalSnakeCase=l,exports.toPathCase=u,exports.toSentenceCase=d,exports.toSnakeCase=f,exports.toTrainCase=p;
|
package/dist/case.d.cts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
//#region src/case.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Convert a string to camel case (`fooBar`).
|
|
4
|
+
*/
|
|
5
|
+
declare function toCamelCase(str: string): string;
|
|
6
|
+
/**
|
|
7
|
+
* Convert a string to capital case (`Foo Bar`).
|
|
8
|
+
*/
|
|
9
|
+
declare function toCapitalCase(str: string): string;
|
|
10
|
+
/**
|
|
11
|
+
* Convert a string to constant case (`CONSTANT_CASE`).
|
|
12
|
+
*/
|
|
13
|
+
declare function toConstantCase(str: string): string;
|
|
14
|
+
/**
|
|
15
|
+
* Convert a string to dot case (`dot.case`).
|
|
16
|
+
*/
|
|
17
|
+
declare function toDotCase(str: string): string;
|
|
18
|
+
/**
|
|
19
|
+
* Convert a string to kebab case (`kebab-case`).
|
|
20
|
+
*/
|
|
21
|
+
declare function toKebabCase(str: string): string;
|
|
22
|
+
/**
|
|
23
|
+
* Convert a string to no case (`no case`).
|
|
24
|
+
*/
|
|
25
|
+
declare function toNoCase(str: string): string;
|
|
26
|
+
/**
|
|
27
|
+
* Convert a string to pascal case (`PascalCase`).
|
|
28
|
+
*/
|
|
29
|
+
declare function toPascalCase(str: string): string;
|
|
30
|
+
/**
|
|
31
|
+
* Convert a string to pascal snake case (`Pascal_Snake_Case`).
|
|
32
|
+
*/
|
|
33
|
+
declare function toPascalSnakeCase(str: string): string;
|
|
34
|
+
/**
|
|
35
|
+
* Convert a string to path case (`path/case`).
|
|
36
|
+
*/
|
|
37
|
+
declare function toPathCase(str: string): string;
|
|
38
|
+
/**
|
|
39
|
+
* Convert a string to sentence case (`Sentence case`).
|
|
40
|
+
*/
|
|
41
|
+
declare function toSentenceCase(str: string): string;
|
|
42
|
+
/**
|
|
43
|
+
* Convert a string to snake case (`snake_case`).
|
|
44
|
+
*/
|
|
45
|
+
declare function toSnakeCase(str: string): string;
|
|
46
|
+
/**
|
|
47
|
+
* Convert a string to train case (`Train-Case`).
|
|
48
|
+
*/
|
|
49
|
+
declare function toTrainCase(str: string): string;
|
|
50
|
+
//#endregion
|
|
51
|
+
export { toCamelCase, toCapitalCase, toConstantCase, toDotCase, toKebabCase, toNoCase, toPascalCase, toPascalSnakeCase, toPathCase, toSentenceCase, toSnakeCase, toTrainCase };
|
package/dist/case.d.ts
CHANGED
|
@@ -1,48 +1,51 @@
|
|
|
1
|
+
//#region src/case.d.ts
|
|
1
2
|
/**
|
|
2
3
|
* Convert a string to camel case (`fooBar`).
|
|
3
4
|
*/
|
|
4
|
-
|
|
5
|
+
declare function toCamelCase(str: string): string;
|
|
5
6
|
/**
|
|
6
7
|
* Convert a string to capital case (`Foo Bar`).
|
|
7
8
|
*/
|
|
8
|
-
|
|
9
|
+
declare function toCapitalCase(str: string): string;
|
|
9
10
|
/**
|
|
10
11
|
* Convert a string to constant case (`CONSTANT_CASE`).
|
|
11
12
|
*/
|
|
12
|
-
|
|
13
|
+
declare function toConstantCase(str: string): string;
|
|
13
14
|
/**
|
|
14
15
|
* Convert a string to dot case (`dot.case`).
|
|
15
16
|
*/
|
|
16
|
-
|
|
17
|
+
declare function toDotCase(str: string): string;
|
|
17
18
|
/**
|
|
18
19
|
* Convert a string to kebab case (`kebab-case`).
|
|
19
20
|
*/
|
|
20
|
-
|
|
21
|
+
declare function toKebabCase(str: string): string;
|
|
21
22
|
/**
|
|
22
23
|
* Convert a string to no case (`no case`).
|
|
23
24
|
*/
|
|
24
|
-
|
|
25
|
+
declare function toNoCase(str: string): string;
|
|
25
26
|
/**
|
|
26
27
|
* Convert a string to pascal case (`PascalCase`).
|
|
27
28
|
*/
|
|
28
|
-
|
|
29
|
+
declare function toPascalCase(str: string): string;
|
|
29
30
|
/**
|
|
30
31
|
* Convert a string to pascal snake case (`Pascal_Snake_Case`).
|
|
31
32
|
*/
|
|
32
|
-
|
|
33
|
+
declare function toPascalSnakeCase(str: string): string;
|
|
33
34
|
/**
|
|
34
35
|
* Convert a string to path case (`path/case`).
|
|
35
36
|
*/
|
|
36
|
-
|
|
37
|
+
declare function toPathCase(str: string): string;
|
|
37
38
|
/**
|
|
38
39
|
* Convert a string to sentence case (`Sentence case`).
|
|
39
40
|
*/
|
|
40
|
-
|
|
41
|
+
declare function toSentenceCase(str: string): string;
|
|
41
42
|
/**
|
|
42
43
|
* Convert a string to snake case (`snake_case`).
|
|
43
44
|
*/
|
|
44
|
-
|
|
45
|
+
declare function toSnakeCase(str: string): string;
|
|
45
46
|
/**
|
|
46
47
|
* Convert a string to train case (`Train-Case`).
|
|
47
48
|
*/
|
|
48
|
-
|
|
49
|
+
declare function toTrainCase(str: string): string;
|
|
50
|
+
//#endregion
|
|
51
|
+
export { toCamelCase, toCapitalCase, toConstantCase, toDotCase, toKebabCase, toNoCase, toPascalCase, toPascalSnakeCase, toPathCase, toSentenceCase, toSnakeCase, toTrainCase };
|
package/dist/case.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{camelCase as e,capitalCase as t,constantCase as n,dotCase as r,kebabCase as i,noCase as a,pascalCase as o,pascalSnakeCase as s,pathCase as c,sentenceCase as l,snakeCase as u,trainCase as d}from"change-case";function f(t){return e(t)}function p(e){return t(e)}function m(e){return n(e)}function h(e){return r(e)}function g(e){return i(e)}function _(e){return a(e)}function v(e){return o(e)}function y(e){return s(e)}function b(e){return c(e)}function x(e){return l(e)}function S(e){return u(e)}function C(e){return d(e)}export{f as toCamelCase,p as toCapitalCase,m as toConstantCase,h as toDotCase,g as toKebabCase,_ as toNoCase,v as toPascalCase,y as toPascalSnakeCase,b as toPathCase,x as toSentenceCase,S as toSnakeCase,C as toTrainCase};
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
const e=require(`./case.cjs`),t=require(`./manipulation.cjs`),n=require(`./type-guards.cjs`),r=require(`./validation.cjs`);exports.capitalize=t.capitalize,exports.capitalizeFirst=t.capitalizeFirst,exports.countOccurrences=t.countOccurrences,exports.isAlphanumeric=r.isAlphanumeric,exports.isEmail=r.isEmail,exports.isEmpty=r.isEmpty,exports.isString=n.isString,exports.isUrl=r.isUrl,exports.normalizeSpaces=t.normalizeSpaces,exports.padEnd=t.padEnd,exports.padStart=t.padStart,exports.removeWhitespace=t.removeWhitespace,exports.repeat=t.repeat,exports.reverse=t.reverse,exports.toCamelCase=e.toCamelCase,exports.toCapitalCase=e.toCapitalCase,exports.toConstantCase=e.toConstantCase,exports.toDotCase=e.toDotCase,exports.toKebabCase=e.toKebabCase,exports.toNoCase=e.toNoCase,exports.toPascalCase=e.toPascalCase,exports.toPascalSnakeCase=e.toPascalSnakeCase,exports.toPathCase=e.toPathCase,exports.toSentenceCase=e.toSentenceCase,exports.toSnakeCase=e.toSnakeCase,exports.toTrainCase=e.toTrainCase,exports.truncate=t.truncate,exports.words=t.words;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { toCamelCase, toCapitalCase, toConstantCase, toDotCase, toKebabCase, toNoCase, toPascalCase, toPascalSnakeCase, toPathCase, toSentenceCase, toSnakeCase, toTrainCase } from "./case.cjs";
|
|
2
|
+
import { capitalize, capitalizeFirst, countOccurrences, normalizeSpaces, padEnd, padStart, removeWhitespace, repeat, reverse, truncate, words } from "./manipulation.cjs";
|
|
3
|
+
import { isString } from "./type-guards.cjs";
|
|
4
|
+
import { isAlphanumeric, isEmail, isEmpty, isUrl } from "./validation.cjs";
|
|
5
|
+
export { capitalize, capitalizeFirst, countOccurrences, isAlphanumeric, isEmail, isEmpty, isString, isUrl, normalizeSpaces, padEnd, padStart, removeWhitespace, repeat, reverse, toCamelCase, toCapitalCase, toConstantCase, toDotCase, toKebabCase, toNoCase, toPascalCase, toPascalSnakeCase, toPathCase, toSentenceCase, toSnakeCase, toTrainCase, truncate, words };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { toCamelCase, toCapitalCase, toConstantCase, toDotCase, toKebabCase, toNoCase, toPascalCase, toPascalSnakeCase, toPathCase, toSentenceCase, toSnakeCase, toTrainCase } from "./case.js";
|
|
2
|
+
import { capitalize, capitalizeFirst, countOccurrences, normalizeSpaces, padEnd, padStart, removeWhitespace, repeat, reverse, truncate, words } from "./manipulation.js";
|
|
3
|
+
import { isString } from "./type-guards.js";
|
|
4
|
+
import { isAlphanumeric, isEmail, isEmpty, isUrl } from "./validation.js";
|
|
5
|
+
export { capitalize, capitalizeFirst, countOccurrences, isAlphanumeric, isEmail, isEmpty, isString, isUrl, normalizeSpaces, padEnd, padStart, removeWhitespace, repeat, reverse, toCamelCase, toCapitalCase, toConstantCase, toDotCase, toKebabCase, toNoCase, toPascalCase, toPascalSnakeCase, toPathCase, toSentenceCase, toSnakeCase, toTrainCase, truncate, words };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{toCamelCase as e,toCapitalCase as t,toConstantCase as n,toDotCase as r,toKebabCase as i,toNoCase as a,toPascalCase as o,toPascalSnakeCase as s,toPathCase as c,toSentenceCase as l,toSnakeCase as u,toTrainCase as d}from"./case.js";import{capitalize as f,capitalizeFirst as p,countOccurrences as m,normalizeSpaces as h,padEnd as g,padStart as _,removeWhitespace as v,repeat as y,reverse as b,truncate as x,words as S}from"./manipulation.js";import{isString as C}from"./type-guards.js";import{isAlphanumeric as w,isEmail as T,isEmpty as E,isUrl as D}from"./validation.js";export{f as capitalize,p as capitalizeFirst,m as countOccurrences,w as isAlphanumeric,T as isEmail,E as isEmpty,C as isString,D as isUrl,h as normalizeSpaces,g as padEnd,_ as padStart,v as removeWhitespace,y as repeat,b as reverse,e as toCamelCase,t as toCapitalCase,n as toConstantCase,r as toDotCase,i as toKebabCase,a as toNoCase,o as toPascalCase,s as toPascalSnakeCase,c as toPathCase,l as toSentenceCase,u as toSnakeCase,d as toTrainCase,x as truncate,S as words};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function e(e,t,n=`...`){return e.length<=t?e:e.slice(0,t)+n}function t(e){return e.length===0?e:e.charAt(0).toUpperCase()+e.slice(1)}function n(e){return e.length===0?e:e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()}function r(e){return e.split(``).reverse().join(``)}function i(e){return e.replace(/\s+/gu,``)}function a(e){return e.replace(/\s+/gu,` `).trim()}function o(e,t,n=` `){return e.padStart(t,n)}function s(e,t,n=` `){return e.padEnd(t,n)}function c(e,t){return e.repeat(t)}function l(e,t,n=!0){if(t.length===0)return 0;let r=n?e:e.toLowerCase(),i=n?t:t.toLowerCase(),a=0,o=0;for(;;){let e=r.indexOf(i,o);if(e===-1)break;a++,o=e+1}return a}function u(e){return e.match(/[A-Z]?[a-z]+|[A-Z]+(?![a-z])|\d+/gu)||[]}exports.capitalize=t,exports.capitalizeFirst=n,exports.countOccurrences=l,exports.normalizeSpaces=a,exports.padEnd=s,exports.padStart=o,exports.removeWhitespace=i,exports.repeat=c,exports.reverse=r,exports.truncate=e,exports.words=u;
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
//#region src/manipulation.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Truncate a string to a specified length, adding an ellipsis if truncated.
|
|
4
|
+
*
|
|
5
|
+
* @param str - The string to truncate
|
|
6
|
+
* @param maxLength - The maximum length of the string
|
|
7
|
+
* @param ellipsis - The ellipsis to append (default: '...')
|
|
8
|
+
* @returns The truncated string
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* truncate('Hello World', 5); // 'Hello...'
|
|
13
|
+
* truncate('Hello', 10); // 'Hello'
|
|
14
|
+
* truncate('Hello World', 5, '…'); // 'Hello…'
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
declare function truncate(str: string, maxLength: number, ellipsis?: string): string;
|
|
18
|
+
/**
|
|
19
|
+
* Capitalize the first letter of a string.
|
|
20
|
+
*
|
|
21
|
+
* @param str - The string to capitalize
|
|
22
|
+
* @returns The capitalized string
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* capitalize('hello'); // 'Hello'
|
|
27
|
+
* capitalize('WORLD'); // 'WORLD'
|
|
28
|
+
* capitalize(''); // ''
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
declare function capitalize(str: string): string;
|
|
32
|
+
/**
|
|
33
|
+
* Capitalize the first letter of a string and lowercase the rest.
|
|
34
|
+
*
|
|
35
|
+
* @param str - The string to capitalize
|
|
36
|
+
* @returns The capitalized string
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```typescript
|
|
40
|
+
* capitalizeFirst('hello'); // 'Hello'
|
|
41
|
+
* capitalizeFirst('WORLD'); // 'World'
|
|
42
|
+
* capitalizeFirst('hELLO wORLD'); // 'Hello world'
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
declare function capitalizeFirst(str: string): string;
|
|
46
|
+
/**
|
|
47
|
+
* Reverse a string.
|
|
48
|
+
*
|
|
49
|
+
* @param str - The string to reverse
|
|
50
|
+
* @returns The reversed string
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```typescript
|
|
54
|
+
* reverse('hello'); // 'olleh'
|
|
55
|
+
* reverse('abc123'); // '321cba'
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
declare function reverse(str: string): string;
|
|
59
|
+
/**
|
|
60
|
+
* Remove all whitespace from a string.
|
|
61
|
+
*
|
|
62
|
+
* @param str - The string to process
|
|
63
|
+
* @returns The string without whitespace
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```typescript
|
|
67
|
+
* removeWhitespace('hello world'); // 'helloworld'
|
|
68
|
+
* removeWhitespace(' a b c '); // 'abc'
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
declare function removeWhitespace(str: string): string;
|
|
72
|
+
/**
|
|
73
|
+
* Replace multiple consecutive spaces with a single space.
|
|
74
|
+
*
|
|
75
|
+
* @param str - The string to process
|
|
76
|
+
* @returns The string with normalized spaces
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```typescript
|
|
80
|
+
* normalizeSpaces('hello world'); // 'hello world'
|
|
81
|
+
* normalizeSpaces('a b c'); // 'a b c'
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
declare function normalizeSpaces(str: string): string;
|
|
85
|
+
/**
|
|
86
|
+
* Pad a string to a specified length from the start.
|
|
87
|
+
*
|
|
88
|
+
* @param str - The string to pad
|
|
89
|
+
* @param targetLength - The target length
|
|
90
|
+
* @param padString - The string to pad with (default: ' ')
|
|
91
|
+
* @returns The padded string
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```typescript
|
|
95
|
+
* padStart('5', 3, '0'); // '005'
|
|
96
|
+
* padStart('hello', 10); // ' hello'
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
declare function padStart(str: string, targetLength: number, padString?: string): string;
|
|
100
|
+
/**
|
|
101
|
+
* Pad a string to a specified length from the end.
|
|
102
|
+
*
|
|
103
|
+
* @param str - The string to pad
|
|
104
|
+
* @param targetLength - The target length
|
|
105
|
+
* @param padString - The string to pad with (default: ' ')
|
|
106
|
+
* @returns The padded string
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* ```typescript
|
|
110
|
+
* padEnd('5', 3, '0'); // '500'
|
|
111
|
+
* padEnd('hello', 10); // 'hello '
|
|
112
|
+
* ```
|
|
113
|
+
*/
|
|
114
|
+
declare function padEnd(str: string, targetLength: number, padString?: string): string;
|
|
115
|
+
/**
|
|
116
|
+
* Repeat a string a specified number of times.
|
|
117
|
+
*
|
|
118
|
+
* @param str - The string to repeat
|
|
119
|
+
* @param count - The number of times to repeat
|
|
120
|
+
* @returns The repeated string
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* ```typescript
|
|
124
|
+
* repeat('ha', 3); // 'hahaha'
|
|
125
|
+
* repeat('*', 5); // '*****'
|
|
126
|
+
* ```
|
|
127
|
+
*/
|
|
128
|
+
declare function repeat(str: string, count: number): string;
|
|
129
|
+
/**
|
|
130
|
+
* Count the occurrences of a substring in a string.
|
|
131
|
+
*
|
|
132
|
+
* @param str - The string to search in
|
|
133
|
+
* @param searchValue - The substring to count
|
|
134
|
+
* @param caseSensitive - Whether the search is case-sensitive (default: true)
|
|
135
|
+
* @returns The number of occurrences
|
|
136
|
+
*
|
|
137
|
+
* @example
|
|
138
|
+
* ```typescript
|
|
139
|
+
* countOccurrences('hello world hello', 'hello'); // 2
|
|
140
|
+
* countOccurrences('Hello HELLO hello', 'hello', false); // 3
|
|
141
|
+
* ```
|
|
142
|
+
*/
|
|
143
|
+
declare function countOccurrences(str: string, searchValue: string, caseSensitive?: boolean): number;
|
|
144
|
+
/**
|
|
145
|
+
* Extract words from a string.
|
|
146
|
+
*
|
|
147
|
+
* @param str - The string to extract words from
|
|
148
|
+
* @returns An array of words
|
|
149
|
+
*
|
|
150
|
+
* @example
|
|
151
|
+
* ```typescript
|
|
152
|
+
* words('hello world'); // ['hello', 'world']
|
|
153
|
+
* words('one-two_three'); // ['one', 'two', 'three']
|
|
154
|
+
* ```
|
|
155
|
+
*/
|
|
156
|
+
declare function words(str: string): string[];
|
|
157
|
+
//#endregion
|
|
158
|
+
export { capitalize, capitalizeFirst, countOccurrences, normalizeSpaces, padEnd, padStart, removeWhitespace, repeat, reverse, truncate, words };
|
package/dist/manipulation.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
//#region src/manipulation.d.ts
|
|
1
2
|
/**
|
|
2
3
|
* Truncate a string to a specified length, adding an ellipsis if truncated.
|
|
3
4
|
*
|
|
@@ -13,7 +14,7 @@
|
|
|
13
14
|
* truncate('Hello World', 5, '…'); // 'Hello…'
|
|
14
15
|
* ```
|
|
15
16
|
*/
|
|
16
|
-
|
|
17
|
+
declare function truncate(str: string, maxLength: number, ellipsis?: string): string;
|
|
17
18
|
/**
|
|
18
19
|
* Capitalize the first letter of a string.
|
|
19
20
|
*
|
|
@@ -27,7 +28,7 @@ export declare function truncate(str: string, maxLength: number, ellipsis?: stri
|
|
|
27
28
|
* capitalize(''); // ''
|
|
28
29
|
* ```
|
|
29
30
|
*/
|
|
30
|
-
|
|
31
|
+
declare function capitalize(str: string): string;
|
|
31
32
|
/**
|
|
32
33
|
* Capitalize the first letter of a string and lowercase the rest.
|
|
33
34
|
*
|
|
@@ -41,7 +42,7 @@ export declare function capitalize(str: string): string;
|
|
|
41
42
|
* capitalizeFirst('hELLO wORLD'); // 'Hello world'
|
|
42
43
|
* ```
|
|
43
44
|
*/
|
|
44
|
-
|
|
45
|
+
declare function capitalizeFirst(str: string): string;
|
|
45
46
|
/**
|
|
46
47
|
* Reverse a string.
|
|
47
48
|
*
|
|
@@ -54,7 +55,7 @@ export declare function capitalizeFirst(str: string): string;
|
|
|
54
55
|
* reverse('abc123'); // '321cba'
|
|
55
56
|
* ```
|
|
56
57
|
*/
|
|
57
|
-
|
|
58
|
+
declare function reverse(str: string): string;
|
|
58
59
|
/**
|
|
59
60
|
* Remove all whitespace from a string.
|
|
60
61
|
*
|
|
@@ -67,7 +68,7 @@ export declare function reverse(str: string): string;
|
|
|
67
68
|
* removeWhitespace(' a b c '); // 'abc'
|
|
68
69
|
* ```
|
|
69
70
|
*/
|
|
70
|
-
|
|
71
|
+
declare function removeWhitespace(str: string): string;
|
|
71
72
|
/**
|
|
72
73
|
* Replace multiple consecutive spaces with a single space.
|
|
73
74
|
*
|
|
@@ -80,7 +81,7 @@ export declare function removeWhitespace(str: string): string;
|
|
|
80
81
|
* normalizeSpaces('a b c'); // 'a b c'
|
|
81
82
|
* ```
|
|
82
83
|
*/
|
|
83
|
-
|
|
84
|
+
declare function normalizeSpaces(str: string): string;
|
|
84
85
|
/**
|
|
85
86
|
* Pad a string to a specified length from the start.
|
|
86
87
|
*
|
|
@@ -95,7 +96,7 @@ export declare function normalizeSpaces(str: string): string;
|
|
|
95
96
|
* padStart('hello', 10); // ' hello'
|
|
96
97
|
* ```
|
|
97
98
|
*/
|
|
98
|
-
|
|
99
|
+
declare function padStart(str: string, targetLength: number, padString?: string): string;
|
|
99
100
|
/**
|
|
100
101
|
* Pad a string to a specified length from the end.
|
|
101
102
|
*
|
|
@@ -110,7 +111,7 @@ export declare function padStart(str: string, targetLength: number, padString?:
|
|
|
110
111
|
* padEnd('hello', 10); // 'hello '
|
|
111
112
|
* ```
|
|
112
113
|
*/
|
|
113
|
-
|
|
114
|
+
declare function padEnd(str: string, targetLength: number, padString?: string): string;
|
|
114
115
|
/**
|
|
115
116
|
* Repeat a string a specified number of times.
|
|
116
117
|
*
|
|
@@ -124,7 +125,7 @@ export declare function padEnd(str: string, targetLength: number, padString?: st
|
|
|
124
125
|
* repeat('*', 5); // '*****'
|
|
125
126
|
* ```
|
|
126
127
|
*/
|
|
127
|
-
|
|
128
|
+
declare function repeat(str: string, count: number): string;
|
|
128
129
|
/**
|
|
129
130
|
* Count the occurrences of a substring in a string.
|
|
130
131
|
*
|
|
@@ -139,7 +140,7 @@ export declare function repeat(str: string, count: number): string;
|
|
|
139
140
|
* countOccurrences('Hello HELLO hello', 'hello', false); // 3
|
|
140
141
|
* ```
|
|
141
142
|
*/
|
|
142
|
-
|
|
143
|
+
declare function countOccurrences(str: string, searchValue: string, caseSensitive?: boolean): number;
|
|
143
144
|
/**
|
|
144
145
|
* Extract words from a string.
|
|
145
146
|
*
|
|
@@ -152,4 +153,6 @@ export declare function countOccurrences(str: string, searchValue: string, caseS
|
|
|
152
153
|
* words('one-two_three'); // ['one', 'two', 'three']
|
|
153
154
|
* ```
|
|
154
155
|
*/
|
|
155
|
-
|
|
156
|
+
declare function words(str: string): string[];
|
|
157
|
+
//#endregion
|
|
158
|
+
export { capitalize, capitalizeFirst, countOccurrences, normalizeSpaces, padEnd, padStart, removeWhitespace, repeat, reverse, truncate, words };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function e(e,t,n=`...`){return e.length<=t?e:e.slice(0,t)+n}function t(e){return e.length===0?e:e.charAt(0).toUpperCase()+e.slice(1)}function n(e){return e.length===0?e:e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()}function r(e){return e.split(``).reverse().join(``)}function i(e){return e.replace(/\s+/gu,``)}function a(e){return e.replace(/\s+/gu,` `).trim()}function o(e,t,n=` `){return e.padStart(t,n)}function s(e,t,n=` `){return e.padEnd(t,n)}function c(e,t){return e.repeat(t)}function l(e,t,n=!0){if(t.length===0)return 0;let r=n?e:e.toLowerCase(),i=n?t:t.toLowerCase(),a=0,o=0;for(;;){let e=r.indexOf(i,o);if(e===-1)break;a++,o=e+1}return a}function u(e){return e.match(/[A-Z]?[a-z]+|[A-Z]+(?![a-z])|\d+/gu)||[]}export{t as capitalize,n as capitalizeFirst,l as countOccurrences,a as normalizeSpaces,s as padEnd,o as padStart,i as removeWhitespace,c as repeat,r as reverse,e as truncate,u as words};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function e(e){return typeof e==`string`}exports.isString=e;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
//#region src/type-guards.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Type guard to check if a value is a string.
|
|
4
|
+
*
|
|
5
|
+
* @param value - The value to check
|
|
6
|
+
* @returns True if the value is a string, false otherwise
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* isString('hello'); // true
|
|
11
|
+
* isString(123); // false
|
|
12
|
+
* isString(null); // false
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
declare function isString(value: unknown): value is string;
|
|
16
|
+
//#endregion
|
|
17
|
+
export { isString };
|
package/dist/type-guards.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
//#region src/type-guards.d.ts
|
|
1
2
|
/**
|
|
2
3
|
* Type guard to check if a value is a string.
|
|
3
4
|
*
|
|
@@ -11,4 +12,6 @@
|
|
|
11
12
|
* isString(null); // false
|
|
12
13
|
* ```
|
|
13
14
|
*/
|
|
14
|
-
|
|
15
|
+
declare function isString(value: unknown): value is string;
|
|
16
|
+
//#endregion
|
|
17
|
+
export { isString };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function e(e){return typeof e==`string`}export{e as isString};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function e(e,t=!0){return t?e.trim().length===0:e.length===0}function t(e){return/^[\da-z]+$/iu.test(e)}function n(e){return/^[^\s@]+@[^\s@][^\s.@]*\.[^\s@]+$/u.test(e)}function r(e){try{return!!new URL(e)}catch{return!1}}exports.isAlphanumeric=t,exports.isEmail=n,exports.isEmpty=e,exports.isUrl=r;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
//#region src/validation.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Check if a string is empty (zero length or only whitespace).
|
|
4
|
+
*
|
|
5
|
+
* @param str - The string to check
|
|
6
|
+
* @param trimWhitespace - If true, treats whitespace-only strings as empty (default: true)
|
|
7
|
+
* @returns True if the string is empty, false otherwise
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* isEmpty(''); // true
|
|
12
|
+
* isEmpty(' '); // true
|
|
13
|
+
* isEmpty(' ', false); // false
|
|
14
|
+
* isEmpty('hello'); // false
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
declare function isEmpty(str: string, trimWhitespace?: boolean): boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Check if a string contains only alphanumeric characters.
|
|
20
|
+
*
|
|
21
|
+
* @param str - The string to check
|
|
22
|
+
* @returns True if the string contains only alphanumeric characters, false otherwise
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* isAlphanumeric('abc123'); // true
|
|
27
|
+
* isAlphanumeric('abc-123'); // false
|
|
28
|
+
* isAlphanumeric(''); // false
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
declare function isAlphanumeric(str: string): boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Check if a string is a valid email address.
|
|
34
|
+
*
|
|
35
|
+
* @param str - The string to check
|
|
36
|
+
* @returns True if the string is a valid email address, false otherwise
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```typescript
|
|
40
|
+
* isEmail('test@example.com'); // true
|
|
41
|
+
* isEmail('invalid-email'); // false
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
declare function isEmail(str: string): boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Check if a string is a valid URL.
|
|
47
|
+
*
|
|
48
|
+
* @param str - The string to check
|
|
49
|
+
* @returns True if the string is a valid URL, false otherwise
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```typescript
|
|
53
|
+
* isUrl('https://example.com'); // true
|
|
54
|
+
* isUrl('not a url'); // false
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
declare function isUrl(str: string): boolean;
|
|
58
|
+
//#endregion
|
|
59
|
+
export { isAlphanumeric, isEmail, isEmpty, isUrl };
|
package/dist/validation.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
//#region src/validation.d.ts
|
|
1
2
|
/**
|
|
2
3
|
* Check if a string is empty (zero length or only whitespace).
|
|
3
4
|
*
|
|
@@ -13,7 +14,7 @@
|
|
|
13
14
|
* isEmpty('hello'); // false
|
|
14
15
|
* ```
|
|
15
16
|
*/
|
|
16
|
-
|
|
17
|
+
declare function isEmpty(str: string, trimWhitespace?: boolean): boolean;
|
|
17
18
|
/**
|
|
18
19
|
* Check if a string contains only alphanumeric characters.
|
|
19
20
|
*
|
|
@@ -27,7 +28,7 @@ export declare function isEmpty(str: string, trimWhitespace?: boolean): boolean;
|
|
|
27
28
|
* isAlphanumeric(''); // false
|
|
28
29
|
* ```
|
|
29
30
|
*/
|
|
30
|
-
|
|
31
|
+
declare function isAlphanumeric(str: string): boolean;
|
|
31
32
|
/**
|
|
32
33
|
* Check if a string is a valid email address.
|
|
33
34
|
*
|
|
@@ -40,7 +41,7 @@ export declare function isAlphanumeric(str: string): boolean;
|
|
|
40
41
|
* isEmail('invalid-email'); // false
|
|
41
42
|
* ```
|
|
42
43
|
*/
|
|
43
|
-
|
|
44
|
+
declare function isEmail(str: string): boolean;
|
|
44
45
|
/**
|
|
45
46
|
* Check if a string is a valid URL.
|
|
46
47
|
*
|
|
@@ -53,4 +54,6 @@ export declare function isEmail(str: string): boolean;
|
|
|
53
54
|
* isUrl('not a url'); // false
|
|
54
55
|
* ```
|
|
55
56
|
*/
|
|
56
|
-
|
|
57
|
+
declare function isUrl(str: string): boolean;
|
|
58
|
+
//#endregion
|
|
59
|
+
export { isAlphanumeric, isEmail, isEmpty, isUrl };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function e(e,t=!0){return t?e.trim().length===0:e.length===0}function t(e){return/^[\da-z]+$/iu.test(e)}function n(e){return/^[^\s@]+@[^\s@][^\s.@]*\.[^\s@]+$/u.test(e)}function r(e){try{return!!new URL(e)}catch{return!1}}export{t as isAlphanumeric,n as isEmail,e as isEmpty,r as isUrl};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pixpilot/string",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "2.2.0",
|
|
5
5
|
"description": "A collection of utility functions for string manipulation and validation.",
|
|
6
6
|
"author": "Pixpilot <m.doaie@hotmail.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -30,19 +30,22 @@
|
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@types/node": "^22.18.10",
|
|
32
32
|
"eslint": "^9.37.0",
|
|
33
|
-
"
|
|
33
|
+
"tsdown": "^0.15.8",
|
|
34
34
|
"typescript": "^5.9.3",
|
|
35
35
|
"@internal/eslint-config": "0.3.0",
|
|
36
36
|
"@internal/prettier-config": "0.0.1",
|
|
37
|
-
"@internal/rollup-config": "0.1.0",
|
|
38
37
|
"@internal/tsconfig": "0.1.0",
|
|
38
|
+
"@internal/tsdown-config": "0.1.0",
|
|
39
39
|
"@internal/vitest-config": "0.1.0"
|
|
40
40
|
},
|
|
41
41
|
"prettier": "@internal/prettier-config",
|
|
42
42
|
"scripts": {
|
|
43
|
+
"@internal/tsdown-config": "workspace:*",
|
|
44
|
+
"tsdown": "catalog:dev",
|
|
43
45
|
"clean": "git clean -xdf .cache .turbo dist",
|
|
44
46
|
"clean:all": "git clean -xdf .cache .turbo dist node_modules",
|
|
45
|
-
"build": "
|
|
47
|
+
"build": "tsdown",
|
|
48
|
+
"buld:watch": "tsdown --watch",
|
|
46
49
|
"test": "vitest --run --passWithNoTests",
|
|
47
50
|
"test:watch": "vitest --watch",
|
|
48
51
|
"test:ui": "vitest --ui",
|