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 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. [Train case](#train-case)
20
- 9. [Truncate](#truncate)
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 casE')
59
- // Output: camelCasE
59
+ result = camelCase('camel 123 case')
60
+ // Output: camelCase
60
61
  console.log(result)
61
62
 
62
- result = camelCase('camel 123 casE', { numbers: true })
63
- // Output: camel123CasE
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('capitalizE')
82
- // Output: CapitalizE
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 casE')
138
- // Output: PascalCasE
138
+ result = pascalCase('pascal 123 case')
139
+ // Output: PascalCase
139
140
  console.log(result)
140
141
 
141
- result = pascalCase('pascal 123 casE', { numbers: true })
142
- // Output: Pascal123CasE
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 casE')
176
- // Output: Train-CasE
199
+ result = trainCase('train 123 case')
200
+ // Output: Train-Case
177
201
  console.log(result)
178
202
 
179
- result = trainCase('train 123 casE', { numbers: true })
180
- // Output: Train-123-CasE
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 })
@@ -1,49 +1,72 @@
1
- function a(r, t = !1) {
2
- let n = r.charAt(0).toUpperCase(), e = r.slice(1);
3
- return t && (e = e.toLowerCase()), `${n}${e}`;
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, t = { numbers: !1, lower: !1 }) {
6
- let n = t.numbers ? /[\p{L}\p{N}]+/gu : /[\p{L}]+/gu, e = r.match(n);
7
- if (e.length <= 1)
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 = e.shift();
10
- return t.lower && (l = l.toLowerCase()), e = e.map((u) => a(u, t.lower)), e.unshift(l), e.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(r, t = !1) {
13
- let n = t ? /[\p{L}\p{N}]+/gu : /[\p{L}]+/gu, e = r.match(n);
14
- return e.length <= 1 ? null : e.map((l) => l.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 p(r, t = !1) {
17
- let n = t ? /[\p{L}\p{N}-]+/gu : /[\p{L}-]+/gu, e = r.match(n);
18
- return e.length <= 1 ? null : e.map((l) => l.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 f(r, t, n = " ") {
21
- const e = Math.floor((t - r.length) / 2) + r.length;
22
- return r.padStart(e, n).padEnd(t, n);
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 i(r, t = { numbers: !1, lower: !1 }) {
25
- let n = t.numbers ? /[\p{L}\p{N}]+/gu : /[\p{L}]+/gu, e = r.match(n);
26
- return e.length <= 1 ? null : e.map((l) => a(l, t.lower)).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("");
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 c(r, t = !1) {
29
- let n = t ? /[\p{L}\p{N}_]+/gu : /[\p{L}_]+/gu, e = r.match(n);
30
- return e.length <= 1 ? null : e.map((l) => l.toLowerCase()).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(" ");
31
48
  }
32
- function m(r, t = { numbers: !1, lower: !1 }) {
33
- let n = t.numbers ? /[\p{L}\p{N}-]+/gu : /[\p{L}-]+/gu, e = r.match(n);
34
- return e.length <= 1 ? null : e.map((l) => a(l, t.lower)).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("-");
35
57
  }
36
- function g(r, t = 32, n = "...") {
37
- return r.substring(0, t) + n;
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
- f as pad,
45
- i as pascalCase,
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(l,u){typeof exports=="object"&&typeof module<"u"?u(exports):typeof define=="function"&&define.amd?define(["exports"],u):(l=typeof globalThis<"u"?globalThis:l||self,u(l.StringFilters={}))})(this,(function(l){"use strict";function u(n,t=!1){let a=n.charAt(0).toUpperCase(),e=n.slice(1);return t&&(e=e.toLowerCase()),`${a}${e}`}function f(n,t={numbers:!1,lower:!1}){let a=t.numbers?/[\p{L}\p{N}]+/gu:/[\p{L}]+/gu,e=n.match(a);if(e.length<=1)return null;let r=e.shift();return t.lower&&(r=r.toLowerCase()),e=e.map(g=>u(g,t.lower)),e.unshift(r),e.join("")}function s(n,t=!1){let a=t?/[\p{L}\p{N}]+/gu:/[\p{L}]+/gu,e=n.match(a);return e.length<=1?null:e.map(r=>r.toLowerCase()).join("")}function i(n,t=!1){let a=t?/[\p{L}\p{N}-]+/gu:/[\p{L}-]+/gu,e=n.match(a);return e.length<=1?null:e.map(r=>r.toLowerCase()).join("-")}function o(n,t,a=" "){const e=Math.floor((t-n.length)/2)+n.length;return n.padStart(e,a).padEnd(t,a)}function p(n,t={numbers:!1,lower:!1}){let a=t.numbers?/[\p{L}\p{N}]+/gu:/[\p{L}]+/gu,e=n.match(a);return e.length<=1?null:e.map(r=>u(r,t.lower)).join("")}function c(n,t=!1){let a=t?/[\p{L}\p{N}_]+/gu:/[\p{L}_]+/gu,e=n.match(a);return e.length<=1?null:e.map(r=>r.toLowerCase()).join("_")}function m(n,t={numbers:!1,lower:!1}){let a=t.numbers?/[\p{L}\p{N}-]+/gu:/[\p{L}-]+/gu,e=n.match(a);return e.length<=1?null:e.map(r=>u(r,t.lower)).join("-")}function d(n,t=32,a="..."){return n.substring(0,t)+a}l.camelCase=f,l.capitalize=u,l.flatCase=s,l.kebabCase=i,l.pad=o,l.pascalCase=p,l.snakeCase=c,l.trainCase=m,l.truncate=d,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.1.0",
3
+ "version": "0.3.0",
4
4
  "description": "Fast native javascript string filters library.",
5
5
  "type": "module",
6
6
  "files": [