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 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 casE')
59
+ result = camelCase('camel 123 case')
60
60
  // Output: camelCase
61
61
  console.log(result)
62
62
 
63
- result = camelCase('camel 123 casE', true)
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 = capitalize('capitalizE')
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 casE')
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('pascal 123 casE', true)
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 casE')
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('title 123 casE', true)
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 casE')
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('train 123 casE', true)
211
+ result = trainCase('traiN 123 casE', { numbers: true, lower: true })
175
212
  // Output: Train-123-Case
176
213
  console.log(result)
177
214
  ```
@@ -1,54 +1,72 @@
1
- function l(e) {
2
- let n = e.charAt(0).toUpperCase(), r = e.slice(1).toLowerCase();
3
- return `${n}${r}`;
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 p(e, n = !1) {
6
- let r = n ? /[\p{L}\p{N}]+/gu : /[\p{L}]+/gu, t = e.match(r);
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 a = t.shift();
10
- return a = a.toLowerCase(), t = t.map((u) => l(u)), t.unshift(a), t.join("");
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(e, n = !1) {
13
- let r = n ? /[\p{L}\p{N}]+/gu : /[\p{L}]+/gu, t = e.match(r);
14
- return t.length <= 1 ? null : t.map((a) => a.toLowerCase()).join("");
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 s(e, n = !1) {
17
- let r = n ? /[\p{L}\p{N}-]+/gu : /[\p{L}-]+/gu, t = e.match(r);
18
- return t.length <= 1 ? null : t.map((a) => a.toLowerCase()).join("-");
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, r = " ") {
21
- const t = Math.floor((n - e.length) / 2) + e.length;
22
- return e.padStart(t, r).padEnd(n, r);
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 f(e, n = !1) {
25
- let r = n ? /[\p{L}\p{N}]+/gu : /[\p{L}]+/gu, t = e.match(r);
26
- return t.length <= 1 ? null : t.map((a) => l(a)).join("");
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(e, n = !1) {
29
- let r = n ? /[\p{L}\p{N}_]+/gu : /[\p{L}_]+/gu, t = e.match(r);
30
- return t.length <= 1 ? null : t.map((a) => a.toLowerCase()).join("_");
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 g(e, n = !1) {
33
- let r = n ? /[\p{L}\p{N}]+/gu : /[\p{L}]+/gu, t = e.match(r);
34
- return t.length <= 1 ? null : t.map((a) => l(a)).join(" ");
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 L(e, n = !1) {
37
- let r = n ? /[\p{L}\p{N}-]+/gu : /[\p{L}-]+/gu, t = e.match(r);
38
- return t.length <= 1 ? null : t.map((a) => l(a)).join("-");
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 h(e, n = 32, r = "...") {
41
- return e.substring(0, n) + r;
58
+ function g(r, e = 32, n = "...") {
59
+ return r.substring(0, e) + n;
42
60
  }
43
61
  export {
44
- p as camelCase,
45
- l as capitalize,
62
+ s as camelCase,
63
+ a as capitalize,
46
64
  o as flatCase,
47
- s as kebabCase,
65
+ p as kebabCase,
48
66
  i as pad,
49
- f as pascalCase,
67
+ w as pascalCase,
50
68
  c as snakeCase,
51
- g as titleCase,
52
- L as trainCase,
53
- h as truncate
69
+ d as titleCase,
70
+ m as trainCase,
71
+ g as truncate
54
72
  };
@@ -1 +1 @@
1
- (function(l,r){typeof exports=="object"&&typeof module<"u"?r(exports):typeof define=="function"&&define.amd?define(["exports"],r):(l=typeof globalThis<"u"?globalThis:l||self,r(l.StringFilters={}))})(this,(function(l){"use strict";function r(t){let n=t.charAt(0).toUpperCase(),a=t.slice(1).toLowerCase();return`${n}${a}`}function i(t,n=!1){let a=n?/[\p{L}\p{N}]+/gu:/[\p{L}]+/gu,e=t.match(a);if(e.length<=1)return null;let u=e.shift();return u=u.toLowerCase(),e=e.map(C=>r(C)),e.unshift(u),e.join("")}function f(t,n=!1){let a=n?/[\p{L}\p{N}]+/gu:/[\p{L}]+/gu,e=t.match(a);return e.length<=1?null:e.map(u=>u.toLowerCase()).join("")}function p(t,n=!1){let a=n?/[\p{L}\p{N}-]+/gu:/[\p{L}-]+/gu,e=t.match(a);return e.length<=1?null:e.map(u=>u.toLowerCase()).join("-")}function s(t,n,a=" "){const e=Math.floor((n-t.length)/2)+t.length;return t.padStart(e,a).padEnd(n,a)}function o(t,n=!1){let a=n?/[\p{L}\p{N}]+/gu:/[\p{L}]+/gu,e=t.match(a);return e.length<=1?null:e.map(u=>r(u)).join("")}function c(t,n=!1){let a=n?/[\p{L}\p{N}_]+/gu:/[\p{L}_]+/gu,e=t.match(a);return e.length<=1?null:e.map(u=>u.toLowerCase()).join("_")}function g(t,n=!1){let a=n?/[\p{L}\p{N}]+/gu:/[\p{L}]+/gu,e=t.match(a);return e.length<=1?null:e.map(u=>r(u)).join(" ")}function d(t,n=!1){let a=n?/[\p{L}\p{N}-]+/gu:/[\p{L}-]+/gu,e=t.match(a);return e.length<=1?null:e.map(u=>r(u)).join("-")}function h(t,n=32,a="..."){return t.substring(0,n)+a}l.camelCase=i,l.capitalize=r,l.flatCase=f,l.kebabCase=p,l.pad=s,l.pascalCase=o,l.snakeCase=c,l.titleCase=g,l.trainCase=d,l.truncate=h,Object.defineProperty(l,Symbol.toStringTag,{value:"Module"})}));
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"})}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "string-filters",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Fast native javascript string filters library.",
5
5
  "type": "module",
6
6
  "files": [