string-filters 0.1.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 +40 -16
- package/dist/string-filters.js +53 -30
- package/dist/string-filters.umd.cjs +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -16,8 +16,9 @@ Fast native javascript string filters library.
|
|
|
16
16
|
5. [Pad](#pad)
|
|
17
17
|
6. [Pascal case](#pascal-case)
|
|
18
18
|
7. [Snake case](#snake-case)
|
|
19
|
-
8. [
|
|
20
|
-
9. [
|
|
19
|
+
8. [Title case](#title-case)
|
|
20
|
+
9. [Train case](#train-case)
|
|
21
|
+
10. [Truncate](#truncate)
|
|
21
22
|
4. [Author](#author)
|
|
22
23
|
5. [License](#license)
|
|
23
24
|
|
|
@@ -55,12 +56,12 @@ unzip js-string-filters.zip
|
|
|
55
56
|
import { camelCase } from 'string-filters'
|
|
56
57
|
|
|
57
58
|
let result = ''
|
|
58
|
-
result = camelCase('camel 123
|
|
59
|
-
// Output:
|
|
59
|
+
result = camelCase('camel 123 case')
|
|
60
|
+
// Output: camelCase
|
|
60
61
|
console.log(result)
|
|
61
62
|
|
|
62
|
-
result = camelCase('camel 123
|
|
63
|
-
// Output:
|
|
63
|
+
result = camelCase('camel 123 case', { numbers: true })
|
|
64
|
+
// Output: camel123Case
|
|
64
65
|
console.log(result)
|
|
65
66
|
|
|
66
67
|
result = camelCase('cameL 123 casE', { lower: true })
|
|
@@ -78,8 +79,8 @@ console.log(result)
|
|
|
78
79
|
import { capitalize } from 'string-filters'
|
|
79
80
|
|
|
80
81
|
let result = ''
|
|
81
|
-
result = capitalize('
|
|
82
|
-
// Output:
|
|
82
|
+
result = capitalize('capitalize')
|
|
83
|
+
// Output: Capitalize
|
|
83
84
|
console.log(result)
|
|
84
85
|
|
|
85
86
|
result = capitalize('cApitalizE', true)
|
|
@@ -134,12 +135,12 @@ console.log(result)
|
|
|
134
135
|
import { pascalCase } from 'string-filters'
|
|
135
136
|
|
|
136
137
|
let result = ''
|
|
137
|
-
result = pascalCase('pascal 123
|
|
138
|
-
// Output:
|
|
138
|
+
result = pascalCase('pascal 123 case')
|
|
139
|
+
// Output: PascalCase
|
|
139
140
|
console.log(result)
|
|
140
141
|
|
|
141
|
-
result = pascalCase('pascal 123
|
|
142
|
-
// Output:
|
|
142
|
+
result = pascalCase('pascal 123 case', { numbers: true })
|
|
143
|
+
// Output: Pascal123Case
|
|
143
144
|
console.log(result)
|
|
144
145
|
|
|
145
146
|
result = pascalCase('pascaL 123 casE', { lower: true })
|
|
@@ -166,18 +167,41 @@ result = snakeCase('Snake 123 Case', true)
|
|
|
166
167
|
console.log(result)
|
|
167
168
|
```
|
|
168
169
|
|
|
170
|
+
### Title case
|
|
171
|
+
|
|
172
|
+
```js
|
|
173
|
+
import { titleCase } from 'string-filters'
|
|
174
|
+
|
|
175
|
+
let result = ''
|
|
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 })
|
|
185
|
+
// Output: Title Case
|
|
186
|
+
console.log(result)
|
|
187
|
+
|
|
188
|
+
result = titleCase('titlE 123 casE', { numbers: true, lower: true })
|
|
189
|
+
// Output: Title 123 Case
|
|
190
|
+
console.log(result)
|
|
191
|
+
```
|
|
192
|
+
|
|
169
193
|
### Train case
|
|
170
194
|
|
|
171
195
|
```js
|
|
172
196
|
import { trainCase } from 'string-filters'
|
|
173
197
|
|
|
174
198
|
let result = ''
|
|
175
|
-
result = trainCase('train 123
|
|
176
|
-
// Output: Train-
|
|
199
|
+
result = trainCase('train 123 case')
|
|
200
|
+
// Output: Train-Case
|
|
177
201
|
console.log(result)
|
|
178
202
|
|
|
179
|
-
result = trainCase('train 123
|
|
180
|
-
// Output: Train-123-
|
|
203
|
+
result = trainCase('train 123 case', { numbers: true })
|
|
204
|
+
// Output: Train-123-Case
|
|
181
205
|
console.log(result)
|
|
182
206
|
|
|
183
207
|
result = trainCase('traiN 123 casE', { lower: true })
|
package/dist/string-filters.js
CHANGED
|
@@ -1,49 +1,72 @@
|
|
|
1
|
-
function a(r,
|
|
2
|
-
let n = r.charAt(0).toUpperCase(),
|
|
3
|
-
return
|
|
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 s(r,
|
|
6
|
-
let n =
|
|
7
|
-
|
|
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);
|
|
9
|
+
if (t.length <= 1)
|
|
8
10
|
return null;
|
|
9
|
-
let l =
|
|
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(r,
|
|
13
|
-
let n =
|
|
14
|
-
return
|
|
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 p(r,
|
|
17
|
-
let n =
|
|
18
|
-
return
|
|
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
|
|
21
|
-
const
|
|
22
|
-
return r.padStart(
|
|
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 n =
|
|
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("");
|
|
35
|
+
}
|
|
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("_");
|
|
27
39
|
}
|
|
28
|
-
function
|
|
29
|
-
let n =
|
|
30
|
-
|
|
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(" ");
|
|
31
48
|
}
|
|
32
|
-
function m(r,
|
|
33
|
-
let n =
|
|
34
|
-
|
|
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("-");
|
|
35
57
|
}
|
|
36
|
-
function g(r,
|
|
37
|
-
return r.substring(0,
|
|
58
|
+
function g(r, e = 32, n = "...") {
|
|
59
|
+
return r.substring(0, e) + n;
|
|
38
60
|
}
|
|
39
61
|
export {
|
|
40
62
|
s as camelCase,
|
|
41
63
|
a as capitalize,
|
|
42
64
|
o as flatCase,
|
|
43
65
|
p as kebabCase,
|
|
44
|
-
|
|
45
|
-
|
|
66
|
+
i as pad,
|
|
67
|
+
w as pascalCase,
|
|
46
68
|
c as snakeCase,
|
|
69
|
+
d as titleCase,
|
|
47
70
|
m as trainCase,
|
|
48
71
|
g as truncate
|
|
49
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"})}));
|