string-filters 0.1.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/LICENSE +21 -0
- package/README.md +209 -0
- package/dist/string-filters.js +49 -0
- package/dist/string-filters.umd.cjs +1 -0
- package/package.json +50 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Tarkhov
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
# Javascript String Filters
|
|
2
|
+
|
|
3
|
+
Fast native javascript string filters library.
|
|
4
|
+
|
|
5
|
+
### Contents
|
|
6
|
+
|
|
7
|
+
1. [Compatibility](#compatibility)
|
|
8
|
+
2. [Installation](#installation)
|
|
9
|
+
1. [NPM](#npm)
|
|
10
|
+
2. [Manually](#manually)
|
|
11
|
+
3. [Usage](#usage)
|
|
12
|
+
1. [Camel case](#camel-case)
|
|
13
|
+
2. [Capitalize](#capitalize)
|
|
14
|
+
3. [Flat case](#flat-case)
|
|
15
|
+
4. [Kebab case](#kebab-case)
|
|
16
|
+
5. [Pad](#pad)
|
|
17
|
+
6. [Pascal case](#pascal-case)
|
|
18
|
+
7. [Snake case](#snake-case)
|
|
19
|
+
8. [Train case](#train-case)
|
|
20
|
+
9. [Truncate](#truncate)
|
|
21
|
+
4. [Author](#author)
|
|
22
|
+
5. [License](#license)
|
|
23
|
+
|
|
24
|
+
## Compatibility
|
|
25
|
+
|
|
26
|
+
Browser | Version
|
|
27
|
+
------- | -------
|
|
28
|
+
Chrome | >= 107
|
|
29
|
+
Edge | >= 107
|
|
30
|
+
Firefox | >= 104
|
|
31
|
+
Safari | >= 16
|
|
32
|
+
|
|
33
|
+
## Installation
|
|
34
|
+
|
|
35
|
+
### NPM
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
npm install string-filters
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### Manually
|
|
42
|
+
|
|
43
|
+
[Download](https://github.com/tarkhov/js-string-filters/releases/download/v0.1.0/js-string-filters.zip) package and unpack it or use following commands:
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
wget https://github.com/tarkhov/js-string-filters/releases/download/v0.1.0/js-string-filters.zip
|
|
47
|
+
unzip js-string-filters.zip
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Usage
|
|
51
|
+
|
|
52
|
+
### Camel case
|
|
53
|
+
|
|
54
|
+
```js
|
|
55
|
+
import { camelCase } from 'string-filters'
|
|
56
|
+
|
|
57
|
+
let result = ''
|
|
58
|
+
result = camelCase('camel 123 casE')
|
|
59
|
+
// Output: camelCasE
|
|
60
|
+
console.log(result)
|
|
61
|
+
|
|
62
|
+
result = camelCase('camel 123 casE', { numbers: true })
|
|
63
|
+
// Output: camel123CasE
|
|
64
|
+
console.log(result)
|
|
65
|
+
|
|
66
|
+
result = camelCase('cameL 123 casE', { lower: true })
|
|
67
|
+
// Output: camelCase
|
|
68
|
+
console.log(result)
|
|
69
|
+
|
|
70
|
+
result = camelCase('cameL 123 casE', { numbers: true, lower: true })
|
|
71
|
+
// Output: camel123Case
|
|
72
|
+
console.log(result)
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### Capitalize
|
|
76
|
+
|
|
77
|
+
```js
|
|
78
|
+
import { capitalize } from 'string-filters'
|
|
79
|
+
|
|
80
|
+
let result = ''
|
|
81
|
+
result = capitalize('capitalizE')
|
|
82
|
+
// Output: CapitalizE
|
|
83
|
+
console.log(result)
|
|
84
|
+
|
|
85
|
+
result = capitalize('cApitalizE', true)
|
|
86
|
+
// Output: Capitalize
|
|
87
|
+
console.log(result)
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### Flat case
|
|
91
|
+
|
|
92
|
+
```js
|
|
93
|
+
import { flatCase } from 'string-filters'
|
|
94
|
+
|
|
95
|
+
let result = ''
|
|
96
|
+
result = flatCase('Flat 123 Case')
|
|
97
|
+
// Output: flatcase
|
|
98
|
+
console.log(result)
|
|
99
|
+
|
|
100
|
+
result = flatCase('Flat 123 Case', true)
|
|
101
|
+
// Output: flat123case
|
|
102
|
+
console.log(result)
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### Kebab case
|
|
106
|
+
|
|
107
|
+
```js
|
|
108
|
+
import { kebabCase } from 'string-filters'
|
|
109
|
+
|
|
110
|
+
let result = ''
|
|
111
|
+
result = kebabCase('Kebab 123 Case')
|
|
112
|
+
// Output: kebab-case
|
|
113
|
+
console.log(result)
|
|
114
|
+
|
|
115
|
+
result = kebabCase('Kebab 123 Case', true)
|
|
116
|
+
// Output: kebab-123-case
|
|
117
|
+
console.log(result)
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### Pad
|
|
121
|
+
|
|
122
|
+
```js
|
|
123
|
+
import { pad } from 'string-filters'
|
|
124
|
+
|
|
125
|
+
let result = ''
|
|
126
|
+
result = pad('pad', 10, '_')
|
|
127
|
+
// Output: ___pad____
|
|
128
|
+
console.log(result)
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### Pascal case
|
|
132
|
+
|
|
133
|
+
```js
|
|
134
|
+
import { pascalCase } from 'string-filters'
|
|
135
|
+
|
|
136
|
+
let result = ''
|
|
137
|
+
result = pascalCase('pascal 123 casE')
|
|
138
|
+
// Output: PascalCasE
|
|
139
|
+
console.log(result)
|
|
140
|
+
|
|
141
|
+
result = pascalCase('pascal 123 casE', { numbers: true })
|
|
142
|
+
// Output: Pascal123CasE
|
|
143
|
+
console.log(result)
|
|
144
|
+
|
|
145
|
+
result = pascalCase('pascaL 123 casE', { lower: true })
|
|
146
|
+
// Output: PascalCase
|
|
147
|
+
console.log(result)
|
|
148
|
+
|
|
149
|
+
result = pascalCase('pascaL 123 casE', { numbers: true, lower: true })
|
|
150
|
+
// Output: Pascal123Case
|
|
151
|
+
console.log(result)
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
### Snake case
|
|
155
|
+
|
|
156
|
+
```js
|
|
157
|
+
import { snakeCase } from 'string-filters'
|
|
158
|
+
|
|
159
|
+
let result = ''
|
|
160
|
+
result = snakeCase('Snake 123 Case')
|
|
161
|
+
// Output: snake_case
|
|
162
|
+
console.log(result)
|
|
163
|
+
|
|
164
|
+
result = snakeCase('Snake 123 Case', true)
|
|
165
|
+
// Output: snake_123_case
|
|
166
|
+
console.log(result)
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
### Train case
|
|
170
|
+
|
|
171
|
+
```js
|
|
172
|
+
import { trainCase } from 'string-filters'
|
|
173
|
+
|
|
174
|
+
let result = ''
|
|
175
|
+
result = trainCase('train 123 casE')
|
|
176
|
+
// Output: Train-CasE
|
|
177
|
+
console.log(result)
|
|
178
|
+
|
|
179
|
+
result = trainCase('train 123 casE', { numbers: true })
|
|
180
|
+
// Output: Train-123-CasE
|
|
181
|
+
console.log(result)
|
|
182
|
+
|
|
183
|
+
result = trainCase('traiN 123 casE', { lower: true })
|
|
184
|
+
// Output: Train-Case
|
|
185
|
+
console.log(result)
|
|
186
|
+
|
|
187
|
+
result = trainCase('traiN 123 casE', { numbers: true, lower: true })
|
|
188
|
+
// Output: Train-123-Case
|
|
189
|
+
console.log(result)
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
### Truncate
|
|
193
|
+
|
|
194
|
+
```js
|
|
195
|
+
import { truncate } from 'string-filters'
|
|
196
|
+
|
|
197
|
+
let result = truncate('etcetera', 3, '...')
|
|
198
|
+
// Output: etc...
|
|
199
|
+
console.log(result)
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
## Author
|
|
203
|
+
|
|
204
|
+
* [Twitter](https://x.com/tarkhovich)
|
|
205
|
+
* [Medium](https://medium.com/@tarkhov)
|
|
206
|
+
|
|
207
|
+
## License
|
|
208
|
+
|
|
209
|
+
This project is licensed under the **MIT License** - see the `LICENSE` file for details.
|
|
@@ -0,0 +1,49 @@
|
|
|
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}`;
|
|
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)
|
|
8
|
+
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
|
+
}
|
|
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
|
+
}
|
|
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
|
+
}
|
|
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
|
+
}
|
|
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
|
+
}
|
|
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("_");
|
|
31
|
+
}
|
|
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("-");
|
|
35
|
+
}
|
|
36
|
+
function g(r, t = 32, n = "...") {
|
|
37
|
+
return r.substring(0, t) + n;
|
|
38
|
+
}
|
|
39
|
+
export {
|
|
40
|
+
s as camelCase,
|
|
41
|
+
a as capitalize,
|
|
42
|
+
o as flatCase,
|
|
43
|
+
p as kebabCase,
|
|
44
|
+
f as pad,
|
|
45
|
+
i as pascalCase,
|
|
46
|
+
c as snakeCase,
|
|
47
|
+
m as trainCase,
|
|
48
|
+
g as truncate
|
|
49
|
+
};
|
|
@@ -0,0 +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"})}));
|
package/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "string-filters",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Fast native javascript string filters library.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"files": [
|
|
7
|
+
"dist"
|
|
8
|
+
],
|
|
9
|
+
"main": "./dist/string-filters.umd.cjs",
|
|
10
|
+
"module": "./dist/string-filters.js",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"import": "./dist/string-filters.js",
|
|
14
|
+
"require": "./dist/string-filters.umd.cjs"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"string",
|
|
19
|
+
"filter",
|
|
20
|
+
"filters",
|
|
21
|
+
"formatter",
|
|
22
|
+
"string-manipulation",
|
|
23
|
+
"text-processing",
|
|
24
|
+
"utility",
|
|
25
|
+
"validation",
|
|
26
|
+
"transformation",
|
|
27
|
+
"sanitize",
|
|
28
|
+
"input-mask",
|
|
29
|
+
"javascript",
|
|
30
|
+
"js"
|
|
31
|
+
],
|
|
32
|
+
"repository": {
|
|
33
|
+
"type": "git",
|
|
34
|
+
"url": "git+https://github.com/tarkhov/js-string-filters.git"
|
|
35
|
+
},
|
|
36
|
+
"author": "Tarkhov",
|
|
37
|
+
"license": "MIT",
|
|
38
|
+
"bugs": {
|
|
39
|
+
"url": "https://github.com/tarkhov/js-string-filters/issues"
|
|
40
|
+
},
|
|
41
|
+
"homepage": "https://github.com/tarkhov/js-string-filters",
|
|
42
|
+
"scripts": {
|
|
43
|
+
"dev": "vite",
|
|
44
|
+
"build": "vite build",
|
|
45
|
+
"preview": "vite preview"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"vite": "^7.3.1"
|
|
49
|
+
}
|
|
50
|
+
}
|