string-filters
Advanced tools
+40
-35
@@ -1,49 +0,54 @@ | ||
| function a(r, t = !1) { | ||
| let n = r.charAt(0).toUpperCase(), e = r.slice(1); | ||
| return t && (e = e.toLowerCase()), `${n}${e}`; | ||
| function l(e) { | ||
| let n = e.charAt(0).toUpperCase(), r = e.slice(1).toLowerCase(); | ||
| return `${n}${r}`; | ||
| } | ||
| function s(r, t = { numbers: !1, lower: !1 }) { | ||
| let n = t.numbers ? /[\p{L}\p{N}]+/gu : /[\p{L}]+/gu, e = r.match(n); | ||
| if (e.length <= 1) | ||
| function p(e, n = !1) { | ||
| let r = n ? /[\p{L}\p{N}]+/gu : /[\p{L}]+/gu, t = e.match(r); | ||
| if (t.length <= 1) | ||
| return null; | ||
| let l = e.shift(); | ||
| return t.lower && (l = l.toLowerCase()), e = e.map((u) => a(u, t.lower)), e.unshift(l), e.join(""); | ||
| let a = t.shift(); | ||
| return a = a.toLowerCase(), t = t.map((u) => l(u)), t.unshift(a), t.join(""); | ||
| } | ||
| function o(r, t = !1) { | ||
| let n = t ? /[\p{L}\p{N}]+/gu : /[\p{L}]+/gu, e = r.match(n); | ||
| return e.length <= 1 ? null : e.map((l) => l.toLowerCase()).join(""); | ||
| function o(e, n = !1) { | ||
| let r = n ? /[\p{L}\p{N}]+/gu : /[\p{L}]+/gu, t = e.match(r); | ||
| return t.length <= 1 ? null : t.map((a) => a.toLowerCase()).join(""); | ||
| } | ||
| function p(r, t = !1) { | ||
| let n = t ? /[\p{L}\p{N}-]+/gu : /[\p{L}-]+/gu, e = r.match(n); | ||
| return e.length <= 1 ? null : e.map((l) => l.toLowerCase()).join("-"); | ||
| function s(e, n = !1) { | ||
| let r = n ? /[\p{L}\p{N}-]+/gu : /[\p{L}-]+/gu, t = e.match(r); | ||
| return t.length <= 1 ? null : t.map((a) => a.toLowerCase()).join("-"); | ||
| } | ||
| function f(r, t, n = " ") { | ||
| const e = Math.floor((t - r.length) / 2) + r.length; | ||
| return r.padStart(e, n).padEnd(t, n); | ||
| function i(e, n, r = " ") { | ||
| const t = Math.floor((n - e.length) / 2) + e.length; | ||
| return e.padStart(t, r).padEnd(n, r); | ||
| } | ||
| function i(r, t = { numbers: !1, lower: !1 }) { | ||
| let n = t.numbers ? /[\p{L}\p{N}]+/gu : /[\p{L}]+/gu, e = r.match(n); | ||
| return e.length <= 1 ? null : e.map((l) => a(l, t.lower)).join(""); | ||
| function f(e, n = !1) { | ||
| let r = n ? /[\p{L}\p{N}]+/gu : /[\p{L}]+/gu, t = e.match(r); | ||
| return t.length <= 1 ? null : t.map((a) => l(a)).join(""); | ||
| } | ||
| function c(r, t = !1) { | ||
| let n = t ? /[\p{L}\p{N}_]+/gu : /[\p{L}_]+/gu, e = r.match(n); | ||
| return e.length <= 1 ? null : e.map((l) => l.toLowerCase()).join("_"); | ||
| function c(e, n = !1) { | ||
| let r = n ? /[\p{L}\p{N}_]+/gu : /[\p{L}_]+/gu, t = e.match(r); | ||
| return t.length <= 1 ? null : t.map((a) => a.toLowerCase()).join("_"); | ||
| } | ||
| function m(r, t = { numbers: !1, lower: !1 }) { | ||
| let n = t.numbers ? /[\p{L}\p{N}-]+/gu : /[\p{L}-]+/gu, e = r.match(n); | ||
| return e.length <= 1 ? null : e.map((l) => a(l, t.lower)).join("-"); | ||
| function g(e, n = !1) { | ||
| let r = n ? /[\p{L}\p{N}]+/gu : /[\p{L}]+/gu, t = e.match(r); | ||
| return t.length <= 1 ? null : t.map((a) => l(a)).join(" "); | ||
| } | ||
| function g(r, t = 32, n = "...") { | ||
| return r.substring(0, t) + n; | ||
| function L(e, n = !1) { | ||
| let r = n ? /[\p{L}\p{N}-]+/gu : /[\p{L}-]+/gu, t = e.match(r); | ||
| return t.length <= 1 ? null : t.map((a) => l(a)).join("-"); | ||
| } | ||
| function h(e, n = 32, r = "...") { | ||
| return e.substring(0, n) + r; | ||
| } | ||
| export { | ||
| s as camelCase, | ||
| a as capitalize, | ||
| p as camelCase, | ||
| l as capitalize, | ||
| o as flatCase, | ||
| p as kebabCase, | ||
| f as pad, | ||
| i as pascalCase, | ||
| s as kebabCase, | ||
| i as pad, | ||
| f as pascalCase, | ||
| c as snakeCase, | ||
| m as trainCase, | ||
| g as truncate | ||
| g as titleCase, | ||
| L as trainCase, | ||
| h as truncate | ||
| }; |
@@ -1,1 +0,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"})})); | ||
| (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
-1
| { | ||
| "name": "string-filters", | ||
| "version": "0.1.0", | ||
| "version": "0.2.0", | ||
| "description": "Fast native javascript string filters library.", | ||
@@ -5,0 +5,0 @@ "type": "module", |
+21
-34
@@ -19,4 +19,5 @@ # Javascript String Filters | ||
| 7. [Snake case](#snake-case) | ||
| 8. [Train case](#train-case) | ||
| 9. [Truncate](#truncate) | ||
| 8. [Title case](#title-case) | ||
| 9. [Train case](#train-case) | ||
| 10. [Truncate](#truncate) | ||
| 4. [Author](#author) | ||
@@ -60,14 +61,6 @@ 5. [License](#license) | ||
| result = camelCase('camel 123 casE') | ||
| // Output: camelCasE | ||
| console.log(result) | ||
| result = camelCase('camel 123 casE', { numbers: true }) | ||
| // Output: camel123CasE | ||
| console.log(result) | ||
| result = camelCase('cameL 123 casE', { lower: true }) | ||
| // Output: camelCase | ||
| console.log(result) | ||
| result = camelCase('cameL 123 casE', { numbers: true, lower: true }) | ||
| result = camelCase('camel 123 casE', true) | ||
| // Output: camel123Case | ||
@@ -82,8 +75,3 @@ console.log(result) | ||
| let result = '' | ||
| result = capitalize('capitalizE') | ||
| // Output: CapitalizE | ||
| console.log(result) | ||
| result = capitalize('cApitalizE', true) | ||
| let result = capitalize('capitalizE') | ||
| // Output: Capitalize | ||
@@ -141,14 +129,6 @@ console.log(result) | ||
| result = pascalCase('pascal 123 casE') | ||
| // Output: PascalCasE | ||
| console.log(result) | ||
| result = pascalCase('pascal 123 casE', { numbers: true }) | ||
| // Output: Pascal123CasE | ||
| console.log(result) | ||
| result = pascalCase('pascaL 123 casE', { lower: true }) | ||
| // Output: PascalCase | ||
| console.log(result) | ||
| result = pascalCase('pascaL 123 casE', { numbers: true, lower: true }) | ||
| result = pascalCase('pascal 123 casE', true) | ||
| // Output: Pascal123Case | ||
@@ -173,21 +153,28 @@ console.log(result) | ||
| ### Train case | ||
| ### Title case | ||
| ```js | ||
| import { trainCase } from 'string-filters' | ||
| import { titleCase } from 'string-filters' | ||
| let result = '' | ||
| result = trainCase('train 123 casE') | ||
| // Output: Train-CasE | ||
| result = titleCase('title 123 casE') | ||
| // Output: Title Case | ||
| console.log(result) | ||
| result = trainCase('train 123 casE', { numbers: true }) | ||
| // Output: Train-123-CasE | ||
| result = titleCase('title 123 casE', true) | ||
| // Output: Title 123 Case | ||
| console.log(result) | ||
| ``` | ||
| result = trainCase('traiN 123 casE', { lower: true }) | ||
| ### Train case | ||
| ```js | ||
| import { trainCase } from 'string-filters' | ||
| let result = '' | ||
| result = trainCase('train 123 casE') | ||
| // Output: Train-Case | ||
| console.log(result) | ||
| result = trainCase('traiN 123 casE', { numbers: true, lower: true }) | ||
| result = trainCase('train 123 casE', true) | ||
| // Output: Train-123-Case | ||
@@ -194,0 +181,0 @@ console.log(result) |
61
8.93%8895
-5.01%196
-6.22%