string-filters 0.2.0 → 0.3.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/README.md +46 -9
- package/dist/string-filters.js +55 -37
- package/dist/string-filters.umd.cjs +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -56,11 +56,19 @@ unzip js-string-filters.zip
|
|
|
56
56
|
import { camelCase } from 'string-filters'
|
|
57
57
|
|
|
58
58
|
let result = ''
|
|
59
|
-
result = camelCase('camel 123
|
|
59
|
+
result = camelCase('camel 123 case')
|
|
60
60
|
// Output: camelCase
|
|
61
61
|
console.log(result)
|
|
62
62
|
|
|
63
|
-
result = camelCase('camel 123
|
|
63
|
+
result = camelCase('camel 123 case', { numbers: true })
|
|
64
|
+
// Output: camel123Case
|
|
65
|
+
console.log(result)
|
|
66
|
+
|
|
67
|
+
result = camelCase('cameL 123 casE', { lower: true })
|
|
68
|
+
// Output: camelCase
|
|
69
|
+
console.log(result)
|
|
70
|
+
|
|
71
|
+
result = camelCase('cameL 123 casE', { numbers: true, lower: true })
|
|
64
72
|
// Output: camel123Case
|
|
65
73
|
console.log(result)
|
|
66
74
|
```
|
|
@@ -70,7 +78,12 @@ console.log(result)
|
|
|
70
78
|
```js
|
|
71
79
|
import { capitalize } from 'string-filters'
|
|
72
80
|
|
|
73
|
-
let result =
|
|
81
|
+
let result = ''
|
|
82
|
+
result = capitalize('capitalize')
|
|
83
|
+
// Output: Capitalize
|
|
84
|
+
console.log(result)
|
|
85
|
+
|
|
86
|
+
result = capitalize('cApitalizE', true)
|
|
74
87
|
// Output: Capitalize
|
|
75
88
|
console.log(result)
|
|
76
89
|
```
|
|
@@ -122,11 +135,19 @@ console.log(result)
|
|
|
122
135
|
import { pascalCase } from 'string-filters'
|
|
123
136
|
|
|
124
137
|
let result = ''
|
|
125
|
-
result = pascalCase('pascal 123
|
|
138
|
+
result = pascalCase('pascal 123 case')
|
|
139
|
+
// Output: PascalCase
|
|
140
|
+
console.log(result)
|
|
141
|
+
|
|
142
|
+
result = pascalCase('pascal 123 case', { numbers: true })
|
|
143
|
+
// Output: Pascal123Case
|
|
144
|
+
console.log(result)
|
|
145
|
+
|
|
146
|
+
result = pascalCase('pascaL 123 casE', { lower: true })
|
|
126
147
|
// Output: PascalCase
|
|
127
148
|
console.log(result)
|
|
128
149
|
|
|
129
|
-
result = pascalCase('
|
|
150
|
+
result = pascalCase('pascaL 123 casE', { numbers: true, lower: true })
|
|
130
151
|
// Output: Pascal123Case
|
|
131
152
|
console.log(result)
|
|
132
153
|
```
|
|
@@ -152,11 +173,19 @@ console.log(result)
|
|
|
152
173
|
import { titleCase } from 'string-filters'
|
|
153
174
|
|
|
154
175
|
let result = ''
|
|
155
|
-
result = titleCase('title 123
|
|
176
|
+
result = titleCase('title 123 case')
|
|
177
|
+
// Output: Title Case
|
|
178
|
+
console.log(result)
|
|
179
|
+
|
|
180
|
+
result = titleCase('title 123 case', { numbers: true })
|
|
181
|
+
// Output: Title 123 Case
|
|
182
|
+
console.log(result)
|
|
183
|
+
|
|
184
|
+
result = titleCase('titlE 123 casE', { lower: true })
|
|
156
185
|
// Output: Title Case
|
|
157
186
|
console.log(result)
|
|
158
187
|
|
|
159
|
-
result = titleCase('
|
|
188
|
+
result = titleCase('titlE 123 casE', { numbers: true, lower: true })
|
|
160
189
|
// Output: Title 123 Case
|
|
161
190
|
console.log(result)
|
|
162
191
|
```
|
|
@@ -167,11 +196,19 @@ console.log(result)
|
|
|
167
196
|
import { trainCase } from 'string-filters'
|
|
168
197
|
|
|
169
198
|
let result = ''
|
|
170
|
-
result = trainCase('train 123
|
|
199
|
+
result = trainCase('train 123 case')
|
|
200
|
+
// Output: Train-Case
|
|
201
|
+
console.log(result)
|
|
202
|
+
|
|
203
|
+
result = trainCase('train 123 case', { numbers: true })
|
|
204
|
+
// Output: Train-123-Case
|
|
205
|
+
console.log(result)
|
|
206
|
+
|
|
207
|
+
result = trainCase('traiN 123 casE', { lower: true })
|
|
171
208
|
// Output: Train-Case
|
|
172
209
|
console.log(result)
|
|
173
210
|
|
|
174
|
-
result = trainCase('
|
|
211
|
+
result = trainCase('traiN 123 casE', { numbers: true, lower: true })
|
|
175
212
|
// Output: Train-123-Case
|
|
176
213
|
console.log(result)
|
|
177
214
|
```
|
package/dist/string-filters.js
CHANGED
|
@@ -1,54 +1,72 @@
|
|
|
1
|
-
function
|
|
2
|
-
let n =
|
|
3
|
-
return `${n}${
|
|
1
|
+
function a(r, e = !1) {
|
|
2
|
+
let n = r.charAt(0).toUpperCase(), t = r.slice(1);
|
|
3
|
+
return e && (t = t.toLowerCase()), `${n}${t}`;
|
|
4
4
|
}
|
|
5
|
-
function
|
|
6
|
-
let
|
|
5
|
+
function s(r, e = { numbers: !1, lower: !1 }) {
|
|
6
|
+
let n = /[\p{L}]+/gu;
|
|
7
|
+
typeof e.numbers < "u" && e.numbers && (n = /[\p{L}\p{N}]+/gu);
|
|
8
|
+
let t = r.match(n);
|
|
7
9
|
if (t.length <= 1)
|
|
8
10
|
return null;
|
|
9
|
-
let
|
|
10
|
-
|
|
11
|
+
let l = t.shift();
|
|
12
|
+
const u = typeof e.lower < "u" ? e.lower : !1;
|
|
13
|
+
return u && (l = l.toLowerCase()), t = t.map((f) => a(f, u)), t.unshift(l), t.join("");
|
|
11
14
|
}
|
|
12
|
-
function o(
|
|
13
|
-
let
|
|
14
|
-
return t.length <= 1 ? null : t.map((
|
|
15
|
+
function o(r, e = !1) {
|
|
16
|
+
let n = e ? /[\p{L}\p{N}]+/gu : /[\p{L}]+/gu, t = r.match(n);
|
|
17
|
+
return t.length <= 1 ? null : t.map((l) => l.toLowerCase()).join("");
|
|
15
18
|
}
|
|
16
|
-
function
|
|
17
|
-
let
|
|
18
|
-
return t.length <= 1 ? null : t.map((
|
|
19
|
+
function p(r, e = !1) {
|
|
20
|
+
let n = e ? /[\p{L}\p{N}-]+/gu : /[\p{L}-]+/gu, t = r.match(n);
|
|
21
|
+
return t.length <= 1 ? null : t.map((l) => l.toLowerCase()).join("-");
|
|
19
22
|
}
|
|
20
|
-
function i(e, n
|
|
21
|
-
const t = Math.floor((
|
|
22
|
-
return
|
|
23
|
+
function i(r, e, n = " ") {
|
|
24
|
+
const t = Math.floor((e - r.length) / 2) + r.length;
|
|
25
|
+
return r.padStart(t, n).padEnd(e, n);
|
|
23
26
|
}
|
|
24
|
-
function
|
|
25
|
-
let
|
|
26
|
-
|
|
27
|
+
function w(r, e = { numbers: !1, lower: !1 }) {
|
|
28
|
+
let n = /[\p{L}]+/gu;
|
|
29
|
+
typeof e.numbers < "u" && e.numbers && (n = /[\p{L}\p{N}]+/gu);
|
|
30
|
+
let t = r.match(n);
|
|
31
|
+
if (t.length <= 1)
|
|
32
|
+
return null;
|
|
33
|
+
const l = typeof e.lower < "u" ? e.lower : !1;
|
|
34
|
+
return t.map((u) => a(u, l)).join("");
|
|
27
35
|
}
|
|
28
|
-
function c(
|
|
29
|
-
let
|
|
30
|
-
return t.length <= 1 ? null : t.map((
|
|
36
|
+
function c(r, e = !1) {
|
|
37
|
+
let n = e ? /[\p{L}\p{N}_]+/gu : /[\p{L}_]+/gu, t = r.match(n);
|
|
38
|
+
return t.length <= 1 ? null : t.map((l) => l.toLowerCase()).join("_");
|
|
31
39
|
}
|
|
32
|
-
function
|
|
33
|
-
let
|
|
34
|
-
|
|
40
|
+
function d(r, e = { numbers: !1, lower: !1 }) {
|
|
41
|
+
let n = /[\p{L}]+/gu;
|
|
42
|
+
typeof e.numbers < "u" && e.numbers && (n = /[\p{L}\p{N}]+/gu);
|
|
43
|
+
let t = r.match(n);
|
|
44
|
+
if (t.length <= 1)
|
|
45
|
+
return null;
|
|
46
|
+
const l = typeof e.lower < "u" ? e.lower : !1;
|
|
47
|
+
return t.map((u) => a(u, l)).join(" ");
|
|
35
48
|
}
|
|
36
|
-
function
|
|
37
|
-
let
|
|
38
|
-
|
|
49
|
+
function m(r, e = { numbers: !1, lower: !1 }) {
|
|
50
|
+
let n = /[\p{L}-]+/gu;
|
|
51
|
+
typeof e.numbers < "u" && e.numbers && (n = /[\p{L}\p{N}-]+/gu);
|
|
52
|
+
let t = r.match(n);
|
|
53
|
+
if (t.length <= 1)
|
|
54
|
+
return null;
|
|
55
|
+
const l = typeof e.lower < "u" ? e.lower : !1;
|
|
56
|
+
return t.map((u) => a(u, l)).join("-");
|
|
39
57
|
}
|
|
40
|
-
function
|
|
41
|
-
return
|
|
58
|
+
function g(r, e = 32, n = "...") {
|
|
59
|
+
return r.substring(0, e) + n;
|
|
42
60
|
}
|
|
43
61
|
export {
|
|
44
|
-
|
|
45
|
-
|
|
62
|
+
s as camelCase,
|
|
63
|
+
a as capitalize,
|
|
46
64
|
o as flatCase,
|
|
47
|
-
|
|
65
|
+
p as kebabCase,
|
|
48
66
|
i as pad,
|
|
49
|
-
|
|
67
|
+
w as pascalCase,
|
|
50
68
|
c as snakeCase,
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
69
|
+
d as titleCase,
|
|
70
|
+
m as trainCase,
|
|
71
|
+
g as truncate
|
|
54
72
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(r,u){typeof exports=="object"&&typeof module<"u"?u(exports):typeof define=="function"&&define.amd?define(["exports"],u):(r=typeof globalThis<"u"?globalThis:r||self,u(r.StringFilters={}))})(this,(function(r){"use strict";function u(l,e=!1){let n=l.charAt(0).toUpperCase(),t=l.slice(1);return e&&(t=t.toLowerCase()),`${n}${t}`}function s(l,e={numbers:!1,lower:!1}){let n=/[\p{L}]+/gu;typeof e.numbers<"u"&&e.numbers&&(n=/[\p{L}\p{N}]+/gu);let t=l.match(n);if(t.length<=1)return null;let a=t.shift();const f=typeof e.lower<"u"?e.lower:!1;return f&&(a=a.toLowerCase()),t=t.map(h=>u(h,f)),t.unshift(a),t.join("")}function i(l,e=!1){let n=e?/[\p{L}\p{N}]+/gu:/[\p{L}]+/gu,t=l.match(n);return t.length<=1?null:t.map(a=>a.toLowerCase()).join("")}function o(l,e=!1){let n=e?/[\p{L}\p{N}-]+/gu:/[\p{L}-]+/gu,t=l.match(n);return t.length<=1?null:t.map(a=>a.toLowerCase()).join("-")}function d(l,e,n=" "){const t=Math.floor((e-l.length)/2)+l.length;return l.padStart(t,n).padEnd(e,n)}function p(l,e={numbers:!1,lower:!1}){let n=/[\p{L}]+/gu;typeof e.numbers<"u"&&e.numbers&&(n=/[\p{L}\p{N}]+/gu);let t=l.match(n);if(t.length<=1)return null;const a=typeof e.lower<"u"?e.lower:!1;return t.map(f=>u(f,a)).join("")}function c(l,e=!1){let n=e?/[\p{L}\p{N}_]+/gu:/[\p{L}_]+/gu,t=l.match(n);return t.length<=1?null:t.map(a=>a.toLowerCase()).join("_")}function m(l,e={numbers:!1,lower:!1}){let n=/[\p{L}]+/gu;typeof e.numbers<"u"&&e.numbers&&(n=/[\p{L}\p{N}]+/gu);let t=l.match(n);if(t.length<=1)return null;const a=typeof e.lower<"u"?e.lower:!1;return t.map(f=>u(f,a)).join(" ")}function w(l,e={numbers:!1,lower:!1}){let n=/[\p{L}-]+/gu;typeof e.numbers<"u"&&e.numbers&&(n=/[\p{L}\p{N}-]+/gu);let t=l.match(n);if(t.length<=1)return null;const a=typeof e.lower<"u"?e.lower:!1;return t.map(f=>u(f,a)).join("-")}function g(l,e=32,n="..."){return l.substring(0,e)+n}r.camelCase=s,r.capitalize=u,r.flatCase=i,r.kebabCase=o,r.pad=d,r.pascalCase=p,r.snakeCase=c,r.titleCase=m,r.trainCase=w,r.truncate=g,Object.defineProperty(r,Symbol.toStringTag,{value:"Module"})}));
|