string-tuner 1.0.4 → 1.0.5

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
@@ -3,3 +3,409 @@
3
3
 
4
4
  Fine-tune your strings the way you like it. A tool made by a dev for devs.
5
5
 
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ npm install string-tuner
11
+ ```
12
+
13
+ ## How to Use
14
+
15
+ ### Importing
16
+
17
+ You can import the entire library or individual modules based on your needs:
18
+
19
+ #### Import Everything (Recommended)
20
+
21
+ ```javascript
22
+ import st from 'string-tuner';
23
+
24
+ // Use all modules
25
+ st.transform.camel('hello world');
26
+ st.validate.email('test@example.com');
27
+ st.edit.trim('long string', 5);
28
+ st.clean.html('<p>text</p>');
29
+ st.format.mask('1234567890');
30
+ ```
31
+
32
+ #### Import Individual Modules
33
+
34
+ ```javascript
35
+ import { transform, validate, edit, clean, format } from 'string-tuner';
36
+
37
+ // Use individual modules directly
38
+ transform.camel('hello world');
39
+ validate.email('test@example.com');
40
+ edit.trim('long string', 5);
41
+ clean.html('<p>text</p>');
42
+ format.mask('1234567890');
43
+ ```
44
+
45
+ #### Destructuring for Cleaner Code
46
+
47
+ ```javascript
48
+ import st from 'string-tuner';
49
+
50
+ // Extract only what you need
51
+ const { transform, validate } = st;
52
+
53
+ transform.pascal('my function name');
54
+ validate.url('https://example.com');
55
+ ```
56
+
57
+ ---
58
+
59
+ ## API Reference
60
+
61
+ ### `transform` - String Transformation
62
+
63
+ String transformation utilities for converting strings to different formats and cases.
64
+
65
+ #### `transform.capitalize(str, fullSentence?)`
66
+ Capitalizes a string or sentence.
67
+
68
+ ```javascript
69
+ st.transform.capitalize('the guitar strings vibrate beautifully');
70
+ // Input: 'the guitar strings vibrate beautifully'
71
+ // Output: 'The Guitar Strings Vibrate Beautifully'
72
+
73
+ st.transform.capitalize('the guitar strings vibrate beautifully', false);
74
+ // Input: 'the guitar strings vibrate beautifully'
75
+ // Output: 'The guitar strings vibrate beautifully'
76
+ ```
77
+
78
+ #### `transform.camel(str)`
79
+ Converts a string to camelCase.
80
+
81
+ ```javascript
82
+ st.transform.camel('acoustic guitar solo');
83
+ // Input: 'acoustic guitar solo'
84
+ // Output: 'acousticGuitarSolo'
85
+ ```
86
+
87
+ #### `transform.snake(str)`
88
+ Converts a string to snake_case.
89
+
90
+ ```javascript
91
+ st.transform.snake('Electric Bass Guitar');
92
+ // Input: 'Electric Bass Guitar'
93
+ // Output: 'electric_bass_guitar'
94
+ ```
95
+
96
+ #### `transform.snakeScream(str)`
97
+ Converts a string to SCREAMING_SNAKE_CASE.
98
+
99
+ ```javascript
100
+ st.transform.snakeScream('Electric Bass Guitar');
101
+ // Input: 'Electric Bass Guitar'
102
+ // Output: 'ELECTRIC_BASS_GUITAR'
103
+ ```
104
+
105
+ #### `transform.kebab(str)`
106
+ Converts a string to kebab-case.
107
+
108
+ ```javascript
109
+ st.transform.kebab('Piano Chord Progression');
110
+ // Input: 'Piano Chord Progression'
111
+ // Output: 'piano-chord-progression'
112
+ ```
113
+
114
+ #### `transform.pascal(str)`
115
+ Converts a string to PascalCase.
116
+
117
+ ```javascript
118
+ st.transform.pascal('violin concerto in d major');
119
+ // Input: 'violin concerto in d major'
120
+ // Output: 'ViolinConcertoInDMajor'
121
+ ```
122
+
123
+ #### `transform.reverse(str)`
124
+ Reverses a string.
125
+
126
+ ```javascript
127
+ st.transform.reverse('melody');
128
+ // Input: 'melody'
129
+ // Output: 'ydomel'
130
+ ```
131
+
132
+ #### `transform.slugify(str)`
133
+ Creates a URL-friendly slug from a string.
134
+
135
+ ```javascript
136
+ st.transform.slugify('Jazz & Blues: A Musical Journey!');
137
+ // Input: 'Jazz & Blues: A Musical Journey!'
138
+ // Output: 'jazz-blues-a-musical-journey'
139
+ ```
140
+
141
+ ---
142
+
143
+ ### `validate` - String Validation
144
+
145
+ Validation utilities for checking string formats.
146
+
147
+ #### `validate.email(str, customRegex?)`
148
+ Validates if a string is a valid email address.
149
+
150
+ ```javascript
151
+ st.validate.email('musician@orchestra.com');
152
+ // Input: 'musician@orchestra.com'
153
+ // Output: true
154
+
155
+ st.validate.email('not-an-email');
156
+ // Input: 'not-an-email'
157
+ // Output: false
158
+ ```
159
+
160
+ #### `validate.url(str, customRegex?)`
161
+ Validates if a string is a valid URL.
162
+
163
+ ```javascript
164
+ st.validate.url('https://guitar-lessons.com');
165
+ // Input: 'https://guitar-lessons.com'
166
+ // Output: true
167
+
168
+ st.validate.url('not a url');
169
+ // Input: 'not a url'
170
+ // Output: false
171
+ ```
172
+
173
+ #### `validate.phone(str, customRegex?)`
174
+ Validates if a string is a valid phone number.
175
+
176
+ ```javascript
177
+ st.validate.phone('+1-555-MUSIC-01');
178
+ // Input: '+1-555-MUSIC-01'
179
+ // Output: true
180
+
181
+ st.validate.phone('call me maybe');
182
+ // Input: 'call me maybe'
183
+ // Output: false
184
+ ```
185
+
186
+ ---
187
+
188
+ ### `edit` - String Manipulation
189
+
190
+ String editing utilities for modifying and manipulating strings.
191
+
192
+ #### `edit.trim(str, maxLength?, trimChar?)`
193
+ Trims a string to a maximum length and appends a trim character.
194
+
195
+ ```javascript
196
+ st.edit.trim('The symphony orchestra performs tonight', 12);
197
+ // Input: 'The symphony orchestra performs tonight'
198
+ // Output: 'The symphony...'
199
+
200
+ st.edit.trim('The symphony orchestra performs tonight', 12, '♪');
201
+ // Input: 'The symphony orchestra performs tonight'
202
+ // Output: 'The symphony♪'
203
+ ```
204
+
205
+ #### `edit.repeat(str, count)`
206
+ Repeats a string n times.
207
+
208
+ ```javascript
209
+ st.edit.repeat('♪ ', 5);
210
+ // Input: '♪ '
211
+ // Output: '♪ ♪ ♪ ♪ ♪ '
212
+ ```
213
+
214
+ #### `edit.pad(str, length, char?, position?)`
215
+ Pads a string to a specified length with a character.
216
+
217
+ ```javascript
218
+ st.edit.pad('DRUMS', 15, '-', 'both');
219
+ // Input: 'DRUMS'
220
+ // Output: '-----DRUMS-----'
221
+
222
+ st.edit.pad('BASS', 10, '*', 'start');
223
+ // Input: 'BASS'
224
+ // Output: '******BASS'
225
+ ```
226
+
227
+ #### `edit.wrap(str, wrapper)`
228
+ Wraps a string with specified characters.
229
+
230
+ ```javascript
231
+ st.edit.wrap('piano forte', '"');
232
+ // Input: 'piano forte'
233
+ // Output: '"piano forte"'
234
+
235
+ st.edit.wrap('crescendo', { start: '[', end: ']' });
236
+ // Input: 'crescendo'
237
+ // Output: '[crescendo]'
238
+ ```
239
+
240
+ #### `edit.unwrap(str, wrapper)`
241
+ Removes wrapping characters from a string.
242
+
243
+ ```javascript
244
+ st.edit.unwrap('"allegro"', '"');
245
+ // Input: '"allegro"'
246
+ // Output: 'allegro'
247
+
248
+ st.edit.unwrap('[diminuendo]', { start: '[', end: ']' });
249
+ // Input: '[diminuendo]'
250
+ // Output: 'diminuendo'
251
+ ```
252
+
253
+ #### `edit.prefix(pf)`
254
+ Creates prefix manipulation utilities for a given prefix string.
255
+
256
+ ```javascript
257
+ const sharp = st.edit.prefix('#');
258
+ sharp.add('C');
259
+ // Input: 'C'
260
+ // Output: '#C'
261
+
262
+ sharp.remove('#F');
263
+ // Input: '#F'
264
+ // Output: 'F'
265
+ ```
266
+
267
+ #### `edit.suffix(sf)`
268
+ Creates suffix manipulation utilities for a given suffix string.
269
+
270
+ ```javascript
271
+ const major = st.edit.suffix(' major');
272
+ major.add('C');
273
+ // Input: 'C'
274
+ // Output: 'C major'
275
+
276
+ major.remove('D major');
277
+ // Input: 'D major'
278
+ // Output: 'D'
279
+ ```
280
+
281
+ #### `edit.initials(str, maxInitials?)`
282
+ Extracts initials from a name or string.
283
+
284
+ ```javascript
285
+ st.edit.initials('Ludwig van Beethoven');
286
+ // Input: 'Ludwig van Beethoven'
287
+ // Output: 'LVB'
288
+
289
+ st.edit.initials('Wolfgang Amadeus Mozart', 2);
290
+ // Input: 'Wolfgang Amadeus Mozart'
291
+ // Output: 'WA'
292
+ ```
293
+
294
+ ---
295
+
296
+ ### `clean` - String Cleaning
297
+
298
+ String cleaning utilities for removing or normalizing content.
299
+
300
+ #### `clean.whitespace(str)`
301
+ Removes all whitespace from a string.
302
+
303
+ ```javascript
304
+ st.clean.whitespace('C D E F G A B');
305
+ // Input: 'C D E F G A B'
306
+ // Output: 'CDEFGAB'
307
+ ```
308
+
309
+ #### `clean.normalizeWhitespace(str)`
310
+ Normalizes whitespace by collapsing multiple spaces to single space and trimming.
311
+
312
+ ```javascript
313
+ st.clean.normalizeWhitespace(' quarter note rest ');
314
+ // Input: ' quarter note rest '
315
+ // Output: 'quarter note rest'
316
+ ```
317
+
318
+ #### `clean.html(str)`
319
+ Removes HTML tags from a string.
320
+
321
+ ```javascript
322
+ st.clean.html('<h1>Jazz</h1> <p>is <strong>amazing</strong></p>');
323
+ // Input: '<h1>Jazz</h1> <p>is <strong>amazing</strong></p>'
324
+ // Output: 'Jazz is amazing'
325
+ ```
326
+
327
+ #### `clean.escapeHtml(str)`
328
+ Escapes HTML special characters.
329
+
330
+ ```javascript
331
+ st.clean.escapeHtml('<chord>C & G</chord>');
332
+ // Input: '<chord>C & G</chord>'
333
+ // Output: '&lt;chord&gt;C &amp; G&lt;/chord&gt;'
334
+ ```
335
+
336
+ #### `clean.unescapeHtml(str)`
337
+ Unescapes HTML entities.
338
+
339
+ ```javascript
340
+ st.clean.unescapeHtml('&lt;note&gt;A&lt;/note&gt;');
341
+ // Input: '&lt;note&gt;A&lt;/note&gt;'
342
+ // Output: '<note>A</note>'
343
+ ```
344
+
345
+ ---
346
+
347
+ ### `format` - String Formatting
348
+
349
+ String formatting utilities for displaying and highlighting strings.
350
+
351
+ #### `format.mask(str, visibleChars?, maskChar?)`
352
+ Masks sensitive data in a string.
353
+
354
+ ```javascript
355
+ st.format.mask('GUITAR-SERIAL-12345');
356
+ // Input: 'GUITAR-SERIAL-12345'
357
+ // Output: '***************2345'
358
+
359
+ st.format.mask('VIOLIN-ID-9876', 3, '#');
360
+ // Input: 'VIOLIN-ID-9876'
361
+ // Output: '###########876'
362
+ ```
363
+
364
+ #### `format.highlight(str, search, wrapper?, caseSensitive?)`
365
+ Highlights search terms in a string by wrapping them.
366
+
367
+ ```javascript
368
+ st.format.highlight('The violin plays a beautiful melody', 'violin');
369
+ // Input: 'The violin plays a beautiful melody'
370
+ // Output: 'The <mark>violin</mark> plays a beautiful melody'
371
+
372
+ st.format.highlight('Drums and bass create rhythm', 'bass', { start: '[', end: ']' });
373
+ // Input: 'Drums and bass create rhythm'
374
+ // Output: 'Drums and [bass] create rhythm'
375
+ ```
376
+
377
+ #### `format.quote(type?)`
378
+ Creates quote manipulation utilities for wrapping/unwrapping strings with quotes.
379
+
380
+ ```javascript
381
+ const dq = st.format.quote('double');
382
+ dq.add('staccato');
383
+ // Input: 'staccato'
384
+ // Output: '"staccato"'
385
+
386
+ const sq = st.format.quote('single');
387
+ sq.remove("'legato'");
388
+ // Input: "'legato'"
389
+ // Output: 'legato'
390
+ ```
391
+
392
+ #### `format.bracket(type?)`
393
+ Creates bracket manipulation utilities for wrapping/unwrapping strings with brackets.
394
+
395
+ ```javascript
396
+ const round = st.format.bracket('round');
397
+ round.add('forte');
398
+ // Input: 'forte'
399
+ // Output: '(forte)'
400
+
401
+ const square = st.format.bracket('square');
402
+ square.remove('[pianissimo]');
403
+ // Input: '[pianissimo]'
404
+ // Output: 'pianissimo'
405
+ ```
406
+
407
+ ---
408
+
409
+ ## License
410
+
411
+ MIT
package/dist/index.d.mts CHANGED
@@ -1,52 +1,193 @@
1
- declare const st: {
2
- bracket: (type?: "round" | "square" | "curly" | "angle") => {
3
- add: (str: string) => string;
4
- remove: (str: string) => string;
5
- };
6
- camelCase: (str: string) => string;
1
+ /**
2
+ * Capitalizes a string or sentence
3
+ * @param str - The string to capitalize
4
+ * @param fullSentence - If true, capitalizes each word in the sentence. If false, only capitalizes the first character
5
+ * @returns The capitalized string, or empty string if input is falsy
6
+ * @example
7
+ * transform.capitalize('hello world') // 'Hello World'
8
+ * transform.capitalize('hello world', false) // 'Hello world'
9
+ */
10
+ declare const capitalize: (str: string, fullSentence?: boolean) => string;
11
+ /**
12
+ * String transformation utilities for converting strings to different formats and cases
13
+ * @property capitalize - Capitalizes a string or sentence
14
+ * @property camel - Converts to camelCase
15
+ * @property kebab - Converts to kebab-case
16
+ * @property pascal - Converts to PascalCase
17
+ * @property snake - Converts to snake_case
18
+ * @property snakeScream - Converts to SCREAMING_SNAKE_CASE
19
+ * @property reverse - Reverses a string
20
+ * @property slugify - Creates URL-friendly slugs
21
+ * @example
22
+ * transform.capitalize('hello world') // 'Hello World'
23
+ * transform.camel('hello world') // 'helloWorld'
24
+ * transform.kebab('helloWorld') // 'hello-world'
25
+ * transform.pascal('hello-world') // 'HelloWorld'
26
+ * transform.snake('helloWorld') // 'hello_world'
27
+ * transform.snakeScream('hello world') // 'HELLO_WORLD'
28
+ * transform.reverse('hello') // 'olleh'
29
+ * transform.slugify('Hello World!') // 'hello-world'
30
+ */
31
+ declare const transform: {
7
32
  capitalize: (str: string, fullSentence?: boolean) => string;
8
- escapeHtml: (str: string) => string;
9
- highlight: (str: string, search: string, wrapper?: string | {
33
+ camel: (str: string) => string;
34
+ kebab: (str: string) => string;
35
+ pascal: (str: string) => string;
36
+ snake: (str: string) => string;
37
+ snakeScream: (str: string) => string;
38
+ reverse: (str: string) => string;
39
+ slugify: (str: string) => string;
40
+ };
41
+ declare const validate: {
42
+ email: (str: string, customRegex?: RegExp) => boolean;
43
+ url: (str: string, customRegex?: RegExp) => boolean;
44
+ phone: (str: string, customRegex?: RegExp) => boolean;
45
+ };
46
+ declare const edit: {
47
+ trim: (str: string, maxLength?: number, trimChar?: string) => string;
48
+ repeat: (str: string, count: number) => string;
49
+ pad: (str: string, length: number, char?: string, position?: "start" | "end" | "both") => string;
50
+ wrap: (str: string, wrapper: string | {
10
51
  start: string;
11
52
  end: string;
12
- }, caseSensitive?: boolean) => string;
13
- initials: (str: string, maxInitials?: number) => string;
14
- isEmail: (str: string, customRegex?: RegExp) => boolean;
15
- isPhone: (str: string, customRegex?: RegExp) => boolean;
16
- isUrl: (str: string, customRegex?: RegExp) => boolean;
17
- kebabCase: (str: string) => string;
18
- mask: (str: string, visibleChars?: number, maskChar?: string) => string;
19
- normalizeWhitespace: (str: string) => string;
20
- pad: (str: string, length: number, char?: string, position?: "start" | "end" | "both") => string;
21
- pascalCase: (str: string) => string;
53
+ }) => string;
54
+ unwrap: (str: string, wrapper: string | {
55
+ start: string;
56
+ end: string;
57
+ }) => string;
22
58
  prefix: (pf: string) => {
59
+ /**
60
+ * Adds the prefix to a string if it doesn't already start with it
61
+ * @param str - The string to add prefix to
62
+ * @returns The string with prefix, or empty string if input is falsy
63
+ */
23
64
  add: (str: string | undefined) => string;
65
+ /**
66
+ * Removes the prefix from a string if it starts with it
67
+ * @param str - The string to remove prefix from
68
+ * @returns The string without prefix, or empty string if input is falsy
69
+ */
24
70
  remove: (str: string | undefined) => string;
25
71
  };
26
- quote: (type?: "single" | "double" | "backtick") => {
27
- add: (str: string) => string;
28
- remove: (str: string) => string;
29
- };
30
- removeWhitespace: (str: string) => string;
31
- repeat: (str: string, count: number) => string;
32
- reverse: (str: string) => string;
33
- slugify: (str: string) => string;
34
- snakeCase: (str: string) => string;
35
- stripHtml: (str: string) => string;
36
72
  suffix: (sf: string) => {
73
+ /**
74
+ * Adds the suffix to a string if it doesn't already end with it
75
+ * @param str - The string to add suffix to
76
+ * @returns The string with suffix, or empty string if input is falsy
77
+ */
37
78
  add: (str: string | undefined) => string;
79
+ /**
80
+ * Removes the suffix from a string if it ends with it
81
+ * @param str - The string to remove suffix from
82
+ * @returns The string without suffix, or empty string if input is falsy
83
+ */
38
84
  remove: (str: string | undefined) => string;
39
85
  };
40
- trim: (str: string, maxLength?: number, trimChar?: string) => string;
86
+ initials: (str: string, maxInitials?: number) => string;
87
+ };
88
+ declare const clean: {
89
+ whitespace: (str: string) => string;
90
+ normalizeWhitespace: (str: string) => string;
91
+ html: (str: string) => string;
92
+ escapeHtml: (str: string) => string;
41
93
  unescapeHtml: (str: string) => string;
42
- unwrap: (str: string, wrapper: string | {
43
- start: string;
44
- end: string;
45
- }) => string;
46
- wrap: (str: string, wrapper: string | {
94
+ };
95
+ declare const format: {
96
+ mask: (str: string, visibleChars?: number, maskChar?: string) => string;
97
+ highlight: (str: string, search: string, wrapper?: string | {
47
98
  start: string;
48
99
  end: string;
49
- }) => string;
100
+ }, caseSensitive?: boolean) => string;
101
+ quote: (type?: "single" | "double" | "backtick") => {
102
+ /**
103
+ * Adds quotes to a string
104
+ * @param str - The string to quote
105
+ * @returns The quoted string
106
+ */
107
+ add: (str: string) => string;
108
+ /**
109
+ * Removes quotes from a string
110
+ * @param str - The string to unquote
111
+ * @returns The unquoted string
112
+ */
113
+ remove: (str: string) => string;
114
+ };
115
+ bracket: (type?: "round" | "square" | "curly" | "angle") => {
116
+ /**
117
+ * Adds brackets to a string
118
+ * @param str - The string to wrap
119
+ * @returns The bracketed string
120
+ */
121
+ add: (str: string) => string;
122
+ /**
123
+ * Removes brackets from a string
124
+ * @param str - The string to unwrap
125
+ * @returns The unbracketted string
126
+ */
127
+ remove: (str: string) => string;
128
+ };
129
+ };
130
+
131
+ declare const st: {
132
+ transform: {
133
+ capitalize: (str: string, fullSentence?: boolean) => string;
134
+ camel: (str: string) => string;
135
+ kebab: (str: string) => string;
136
+ pascal: (str: string) => string;
137
+ snake: (str: string) => string;
138
+ snakeScream: (str: string) => string;
139
+ reverse: (str: string) => string;
140
+ slugify: (str: string) => string;
141
+ };
142
+ validate: {
143
+ email: (str: string, customRegex?: RegExp) => boolean;
144
+ url: (str: string, customRegex?: RegExp) => boolean;
145
+ phone: (str: string, customRegex?: RegExp) => boolean;
146
+ };
147
+ edit: {
148
+ trim: (str: string, maxLength?: number, trimChar?: string) => string;
149
+ repeat: (str: string, count: number) => string;
150
+ pad: (str: string, length: number, char?: string, position?: "start" | "end" | "both") => string;
151
+ wrap: (str: string, wrapper: string | {
152
+ start: string;
153
+ end: string;
154
+ }) => string;
155
+ unwrap: (str: string, wrapper: string | {
156
+ start: string;
157
+ end: string;
158
+ }) => string;
159
+ prefix: (pf: string) => {
160
+ add: (str: string | undefined) => string;
161
+ remove: (str: string | undefined) => string;
162
+ };
163
+ suffix: (sf: string) => {
164
+ add: (str: string | undefined) => string;
165
+ remove: (str: string | undefined) => string;
166
+ };
167
+ initials: (str: string, maxInitials?: number) => string;
168
+ };
169
+ clean: {
170
+ whitespace: (str: string) => string;
171
+ normalizeWhitespace: (str: string) => string;
172
+ html: (str: string) => string;
173
+ escapeHtml: (str: string) => string;
174
+ unescapeHtml: (str: string) => string;
175
+ };
176
+ format: {
177
+ mask: (str: string, visibleChars?: number, maskChar?: string) => string;
178
+ highlight: (str: string, search: string, wrapper?: string | {
179
+ start: string;
180
+ end: string;
181
+ }, caseSensitive?: boolean) => string;
182
+ quote: (type?: "single" | "double" | "backtick") => {
183
+ add: (str: string) => string;
184
+ remove: (str: string) => string;
185
+ };
186
+ bracket: (type?: "round" | "square" | "curly" | "angle") => {
187
+ add: (str: string) => string;
188
+ remove: (str: string) => string;
189
+ };
190
+ };
50
191
  };
51
192
 
52
- export { st as default };
193
+ export { capitalize, clean, st as default, edit, format, transform, validate };
package/dist/index.d.ts CHANGED
@@ -1,52 +1,193 @@
1
- declare const st: {
2
- bracket: (type?: "round" | "square" | "curly" | "angle") => {
3
- add: (str: string) => string;
4
- remove: (str: string) => string;
5
- };
6
- camelCase: (str: string) => string;
1
+ /**
2
+ * Capitalizes a string or sentence
3
+ * @param str - The string to capitalize
4
+ * @param fullSentence - If true, capitalizes each word in the sentence. If false, only capitalizes the first character
5
+ * @returns The capitalized string, or empty string if input is falsy
6
+ * @example
7
+ * transform.capitalize('hello world') // 'Hello World'
8
+ * transform.capitalize('hello world', false) // 'Hello world'
9
+ */
10
+ declare const capitalize: (str: string, fullSentence?: boolean) => string;
11
+ /**
12
+ * String transformation utilities for converting strings to different formats and cases
13
+ * @property capitalize - Capitalizes a string or sentence
14
+ * @property camel - Converts to camelCase
15
+ * @property kebab - Converts to kebab-case
16
+ * @property pascal - Converts to PascalCase
17
+ * @property snake - Converts to snake_case
18
+ * @property snakeScream - Converts to SCREAMING_SNAKE_CASE
19
+ * @property reverse - Reverses a string
20
+ * @property slugify - Creates URL-friendly slugs
21
+ * @example
22
+ * transform.capitalize('hello world') // 'Hello World'
23
+ * transform.camel('hello world') // 'helloWorld'
24
+ * transform.kebab('helloWorld') // 'hello-world'
25
+ * transform.pascal('hello-world') // 'HelloWorld'
26
+ * transform.snake('helloWorld') // 'hello_world'
27
+ * transform.snakeScream('hello world') // 'HELLO_WORLD'
28
+ * transform.reverse('hello') // 'olleh'
29
+ * transform.slugify('Hello World!') // 'hello-world'
30
+ */
31
+ declare const transform: {
7
32
  capitalize: (str: string, fullSentence?: boolean) => string;
8
- escapeHtml: (str: string) => string;
9
- highlight: (str: string, search: string, wrapper?: string | {
33
+ camel: (str: string) => string;
34
+ kebab: (str: string) => string;
35
+ pascal: (str: string) => string;
36
+ snake: (str: string) => string;
37
+ snakeScream: (str: string) => string;
38
+ reverse: (str: string) => string;
39
+ slugify: (str: string) => string;
40
+ };
41
+ declare const validate: {
42
+ email: (str: string, customRegex?: RegExp) => boolean;
43
+ url: (str: string, customRegex?: RegExp) => boolean;
44
+ phone: (str: string, customRegex?: RegExp) => boolean;
45
+ };
46
+ declare const edit: {
47
+ trim: (str: string, maxLength?: number, trimChar?: string) => string;
48
+ repeat: (str: string, count: number) => string;
49
+ pad: (str: string, length: number, char?: string, position?: "start" | "end" | "both") => string;
50
+ wrap: (str: string, wrapper: string | {
10
51
  start: string;
11
52
  end: string;
12
- }, caseSensitive?: boolean) => string;
13
- initials: (str: string, maxInitials?: number) => string;
14
- isEmail: (str: string, customRegex?: RegExp) => boolean;
15
- isPhone: (str: string, customRegex?: RegExp) => boolean;
16
- isUrl: (str: string, customRegex?: RegExp) => boolean;
17
- kebabCase: (str: string) => string;
18
- mask: (str: string, visibleChars?: number, maskChar?: string) => string;
19
- normalizeWhitespace: (str: string) => string;
20
- pad: (str: string, length: number, char?: string, position?: "start" | "end" | "both") => string;
21
- pascalCase: (str: string) => string;
53
+ }) => string;
54
+ unwrap: (str: string, wrapper: string | {
55
+ start: string;
56
+ end: string;
57
+ }) => string;
22
58
  prefix: (pf: string) => {
59
+ /**
60
+ * Adds the prefix to a string if it doesn't already start with it
61
+ * @param str - The string to add prefix to
62
+ * @returns The string with prefix, or empty string if input is falsy
63
+ */
23
64
  add: (str: string | undefined) => string;
65
+ /**
66
+ * Removes the prefix from a string if it starts with it
67
+ * @param str - The string to remove prefix from
68
+ * @returns The string without prefix, or empty string if input is falsy
69
+ */
24
70
  remove: (str: string | undefined) => string;
25
71
  };
26
- quote: (type?: "single" | "double" | "backtick") => {
27
- add: (str: string) => string;
28
- remove: (str: string) => string;
29
- };
30
- removeWhitespace: (str: string) => string;
31
- repeat: (str: string, count: number) => string;
32
- reverse: (str: string) => string;
33
- slugify: (str: string) => string;
34
- snakeCase: (str: string) => string;
35
- stripHtml: (str: string) => string;
36
72
  suffix: (sf: string) => {
73
+ /**
74
+ * Adds the suffix to a string if it doesn't already end with it
75
+ * @param str - The string to add suffix to
76
+ * @returns The string with suffix, or empty string if input is falsy
77
+ */
37
78
  add: (str: string | undefined) => string;
79
+ /**
80
+ * Removes the suffix from a string if it ends with it
81
+ * @param str - The string to remove suffix from
82
+ * @returns The string without suffix, or empty string if input is falsy
83
+ */
38
84
  remove: (str: string | undefined) => string;
39
85
  };
40
- trim: (str: string, maxLength?: number, trimChar?: string) => string;
86
+ initials: (str: string, maxInitials?: number) => string;
87
+ };
88
+ declare const clean: {
89
+ whitespace: (str: string) => string;
90
+ normalizeWhitespace: (str: string) => string;
91
+ html: (str: string) => string;
92
+ escapeHtml: (str: string) => string;
41
93
  unescapeHtml: (str: string) => string;
42
- unwrap: (str: string, wrapper: string | {
43
- start: string;
44
- end: string;
45
- }) => string;
46
- wrap: (str: string, wrapper: string | {
94
+ };
95
+ declare const format: {
96
+ mask: (str: string, visibleChars?: number, maskChar?: string) => string;
97
+ highlight: (str: string, search: string, wrapper?: string | {
47
98
  start: string;
48
99
  end: string;
49
- }) => string;
100
+ }, caseSensitive?: boolean) => string;
101
+ quote: (type?: "single" | "double" | "backtick") => {
102
+ /**
103
+ * Adds quotes to a string
104
+ * @param str - The string to quote
105
+ * @returns The quoted string
106
+ */
107
+ add: (str: string) => string;
108
+ /**
109
+ * Removes quotes from a string
110
+ * @param str - The string to unquote
111
+ * @returns The unquoted string
112
+ */
113
+ remove: (str: string) => string;
114
+ };
115
+ bracket: (type?: "round" | "square" | "curly" | "angle") => {
116
+ /**
117
+ * Adds brackets to a string
118
+ * @param str - The string to wrap
119
+ * @returns The bracketed string
120
+ */
121
+ add: (str: string) => string;
122
+ /**
123
+ * Removes brackets from a string
124
+ * @param str - The string to unwrap
125
+ * @returns The unbracketted string
126
+ */
127
+ remove: (str: string) => string;
128
+ };
129
+ };
130
+
131
+ declare const st: {
132
+ transform: {
133
+ capitalize: (str: string, fullSentence?: boolean) => string;
134
+ camel: (str: string) => string;
135
+ kebab: (str: string) => string;
136
+ pascal: (str: string) => string;
137
+ snake: (str: string) => string;
138
+ snakeScream: (str: string) => string;
139
+ reverse: (str: string) => string;
140
+ slugify: (str: string) => string;
141
+ };
142
+ validate: {
143
+ email: (str: string, customRegex?: RegExp) => boolean;
144
+ url: (str: string, customRegex?: RegExp) => boolean;
145
+ phone: (str: string, customRegex?: RegExp) => boolean;
146
+ };
147
+ edit: {
148
+ trim: (str: string, maxLength?: number, trimChar?: string) => string;
149
+ repeat: (str: string, count: number) => string;
150
+ pad: (str: string, length: number, char?: string, position?: "start" | "end" | "both") => string;
151
+ wrap: (str: string, wrapper: string | {
152
+ start: string;
153
+ end: string;
154
+ }) => string;
155
+ unwrap: (str: string, wrapper: string | {
156
+ start: string;
157
+ end: string;
158
+ }) => string;
159
+ prefix: (pf: string) => {
160
+ add: (str: string | undefined) => string;
161
+ remove: (str: string | undefined) => string;
162
+ };
163
+ suffix: (sf: string) => {
164
+ add: (str: string | undefined) => string;
165
+ remove: (str: string | undefined) => string;
166
+ };
167
+ initials: (str: string, maxInitials?: number) => string;
168
+ };
169
+ clean: {
170
+ whitespace: (str: string) => string;
171
+ normalizeWhitespace: (str: string) => string;
172
+ html: (str: string) => string;
173
+ escapeHtml: (str: string) => string;
174
+ unescapeHtml: (str: string) => string;
175
+ };
176
+ format: {
177
+ mask: (str: string, visibleChars?: number, maskChar?: string) => string;
178
+ highlight: (str: string, search: string, wrapper?: string | {
179
+ start: string;
180
+ end: string;
181
+ }, caseSensitive?: boolean) => string;
182
+ quote: (type?: "single" | "double" | "backtick") => {
183
+ add: (str: string) => string;
184
+ remove: (str: string) => string;
185
+ };
186
+ bracket: (type?: "round" | "square" | "curly" | "angle") => {
187
+ add: (str: string) => string;
188
+ remove: (str: string) => string;
189
+ };
190
+ };
50
191
  };
51
192
 
52
- export { st as default };
193
+ export { capitalize, clean, st as default, edit, format, transform, validate };
package/dist/index.js CHANGED
@@ -20,7 +20,13 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/index.ts
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
- default: () => index_default
23
+ capitalize: () => capitalize,
24
+ clean: () => clean,
25
+ default: () => index_default,
26
+ edit: () => edit,
27
+ format: () => format,
28
+ transform: () => transform,
29
+ validate: () => validate
24
30
  });
25
31
  module.exports = __toCommonJS(index_exports);
26
32
 
@@ -62,10 +68,6 @@ var camelCase = (str) => {
62
68
  if (!str) return "";
63
69
  return str.replace(REGEX_CAMEL_CASE_SEPARATOR, (_, chr) => chr.toUpperCase()).replace(REGEX_CAMEL_CASE_FIRST_CHAR, (chr) => chr.toLowerCase());
64
70
  };
65
- var snakeCase = (str) => {
66
- if (!str) return "";
67
- return str.replace(REGEX_SNAKE_CASE_CAPITAL, "_$1").replace(REGEX_SNAKE_CASE_NON_ALPHANUMERIC, "_").replace(REGEX_SNAKE_CASE_LEADING_UNDERSCORE, "").toLowerCase();
68
- };
69
71
  var kebabCase = (str) => {
70
72
  if (!str) return "";
71
73
  return str.replace(REGEX_KEBAB_CASE_CAPITAL, "-$1").replace(REGEX_KEBAB_CASE_NON_ALPHANUMERIC, "-").replace(REGEX_KEBAB_CASE_LEADING_DASH, "").toLowerCase();
@@ -74,6 +76,14 @@ var pascalCase = (str) => {
74
76
  if (!str) return "";
75
77
  return str.replace(REGEX_PASCAL_CASE_SEPARATOR, (_, chr) => chr.toUpperCase()).replace(REGEX_PASCAL_CASE_FIRST_CHAR, (chr) => chr.toUpperCase());
76
78
  };
79
+ var snakeCase = (str) => {
80
+ if (!str) return "";
81
+ return str.replace(REGEX_SNAKE_CASE_CAPITAL, "_$1").replace(REGEX_SNAKE_CASE_NON_ALPHANUMERIC, "_").replace(REGEX_SNAKE_CASE_LEADING_UNDERSCORE, "").toLowerCase();
82
+ };
83
+ var snakeScreamCase = (str) => {
84
+ if (!str) return "";
85
+ return str.replace(REGEX_SNAKE_CASE_CAPITAL, "_$1").replace(REGEX_SNAKE_CASE_NON_ALPHANUMERIC, "_").replace(REGEX_SNAKE_CASE_LEADING_UNDERSCORE, "").toUpperCase();
86
+ };
77
87
  var reverse = (str) => {
78
88
  if (!str) return "";
79
89
  return str.split("").reverse().join("");
@@ -82,6 +92,16 @@ var slugify = (str) => {
82
92
  if (!str) return "";
83
93
  return str.toLowerCase().trim().replace(REGEX_SLUGIFY_NON_WORD, "").replace(REGEX_SLUGIFY_WHITESPACE, "-").replace(REGEX_SLUGIFY_TRIM_DASHES, "");
84
94
  };
95
+ var transform = {
96
+ capitalize,
97
+ camel: camelCase,
98
+ kebab: kebabCase,
99
+ pascal: pascalCase,
100
+ snake: snakeCase,
101
+ snakeScream: snakeScreamCase,
102
+ reverse,
103
+ slugify
104
+ };
85
105
  var isEmail = (str, customRegex) => {
86
106
  if (!str) return false;
87
107
  const regex = customRegex || REGEX_EMAIL_DEFAULT;
@@ -97,6 +117,11 @@ var isPhone = (str, customRegex) => {
97
117
  const regex = customRegex || REGEX_PHONE_DEFAULT;
98
118
  return regex.test(str);
99
119
  };
120
+ var validate = {
121
+ email: isEmail,
122
+ url: isUrl,
123
+ phone: isPhone
124
+ };
100
125
  var trim = (str, maxLength, trimChar = "...") => {
101
126
  if (!maxLength) return str;
102
127
  return str?.length > maxLength ? `${str?.slice(0, maxLength)}${trimChar}` : str;
@@ -175,6 +200,16 @@ var initials = (str, maxInitials) => {
175
200
  }
176
201
  return initialsArray.join("");
177
202
  };
203
+ var edit = {
204
+ trim,
205
+ repeat,
206
+ pad,
207
+ wrap,
208
+ unwrap,
209
+ prefix,
210
+ suffix,
211
+ initials
212
+ };
178
213
  var removeWhitespace = (str) => {
179
214
  if (!str) return "";
180
215
  return str.replace(REGEX_WHITESPACE_ALL, "");
@@ -207,7 +242,17 @@ var unescapeHtml = (str) => {
207
242
  "&quot;": '"',
208
243
  "&#39;": "'"
209
244
  };
210
- return str.replace(REGEX_HTML_UNESCAPE_ENTITIES, (entity) => htmlUnescapes[entity]);
245
+ return str.replace(
246
+ REGEX_HTML_UNESCAPE_ENTITIES,
247
+ (entity) => htmlUnescapes[entity]
248
+ );
249
+ };
250
+ var clean = {
251
+ whitespace: removeWhitespace,
252
+ normalizeWhitespace,
253
+ html: stripHtml,
254
+ escapeHtml,
255
+ unescapeHtml
211
256
  };
212
257
  var mask = (str, visibleChars = 4, maskChar = "*") => {
213
258
  if (!str) return "";
@@ -215,12 +260,18 @@ var mask = (str, visibleChars = 4, maskChar = "*") => {
215
260
  const maskLength = str.length - visibleChars;
216
261
  return maskChar.repeat(maskLength) + str.slice(-visibleChars);
217
262
  };
218
- var highlight = (str, search, wrapper = { start: "<mark>", end: "</mark>" }, caseSensitive = false) => {
263
+ var highlight = (str, search, wrapper = {
264
+ start: "<mark>",
265
+ end: "</mark>"
266
+ }, caseSensitive = false) => {
219
267
  if (!str || !search) return str;
220
268
  const wrapStart = typeof wrapper === "string" ? wrapper : wrapper.start;
221
269
  const wrapEnd = typeof wrapper === "string" ? wrapper : wrapper.end;
222
270
  const flags = caseSensitive ? "g" : "gi";
223
- const regex = new RegExp(search.replace(REGEX_HIGHLIGHT_ESCAPE, "\\$&"), flags);
271
+ const regex = new RegExp(
272
+ search.replace(REGEX_HIGHLIGHT_ESCAPE, "\\$&"),
273
+ flags
274
+ );
224
275
  return str.replace(regex, (match) => `${wrapStart}${match}${wrapEnd}`);
225
276
  };
226
277
  var quote = (type = "double") => {
@@ -263,35 +314,28 @@ var bracket = (type = "round") => {
263
314
  remove: (str) => unwrap(str, bracketPair)
264
315
  };
265
316
  };
317
+ var format = {
318
+ mask,
319
+ highlight,
320
+ quote,
321
+ bracket
322
+ };
266
323
 
267
324
  // src/index.ts
268
325
  var st = {
269
- bracket,
270
- camelCase,
271
- capitalize,
272
- escapeHtml,
273
- highlight,
274
- initials,
275
- isEmail,
276
- isPhone,
277
- isUrl,
278
- kebabCase,
279
- mask,
280
- normalizeWhitespace,
281
- pad,
282
- pascalCase,
283
- prefix,
284
- quote,
285
- removeWhitespace,
286
- repeat,
287
- reverse,
288
- slugify,
289
- snakeCase,
290
- stripHtml,
291
- suffix,
292
- trim,
293
- unescapeHtml,
294
- unwrap,
295
- wrap
326
+ transform,
327
+ validate,
328
+ edit,
329
+ clean,
330
+ format
296
331
  };
297
332
  var index_default = st;
333
+ // Annotate the CommonJS export names for ESM import in node:
334
+ 0 && (module.exports = {
335
+ capitalize,
336
+ clean,
337
+ edit,
338
+ format,
339
+ transform,
340
+ validate
341
+ });
package/dist/index.mjs CHANGED
@@ -36,10 +36,6 @@ var camelCase = (str) => {
36
36
  if (!str) return "";
37
37
  return str.replace(REGEX_CAMEL_CASE_SEPARATOR, (_, chr) => chr.toUpperCase()).replace(REGEX_CAMEL_CASE_FIRST_CHAR, (chr) => chr.toLowerCase());
38
38
  };
39
- var snakeCase = (str) => {
40
- if (!str) return "";
41
- return str.replace(REGEX_SNAKE_CASE_CAPITAL, "_$1").replace(REGEX_SNAKE_CASE_NON_ALPHANUMERIC, "_").replace(REGEX_SNAKE_CASE_LEADING_UNDERSCORE, "").toLowerCase();
42
- };
43
39
  var kebabCase = (str) => {
44
40
  if (!str) return "";
45
41
  return str.replace(REGEX_KEBAB_CASE_CAPITAL, "-$1").replace(REGEX_KEBAB_CASE_NON_ALPHANUMERIC, "-").replace(REGEX_KEBAB_CASE_LEADING_DASH, "").toLowerCase();
@@ -48,6 +44,14 @@ var pascalCase = (str) => {
48
44
  if (!str) return "";
49
45
  return str.replace(REGEX_PASCAL_CASE_SEPARATOR, (_, chr) => chr.toUpperCase()).replace(REGEX_PASCAL_CASE_FIRST_CHAR, (chr) => chr.toUpperCase());
50
46
  };
47
+ var snakeCase = (str) => {
48
+ if (!str) return "";
49
+ return str.replace(REGEX_SNAKE_CASE_CAPITAL, "_$1").replace(REGEX_SNAKE_CASE_NON_ALPHANUMERIC, "_").replace(REGEX_SNAKE_CASE_LEADING_UNDERSCORE, "").toLowerCase();
50
+ };
51
+ var snakeScreamCase = (str) => {
52
+ if (!str) return "";
53
+ return str.replace(REGEX_SNAKE_CASE_CAPITAL, "_$1").replace(REGEX_SNAKE_CASE_NON_ALPHANUMERIC, "_").replace(REGEX_SNAKE_CASE_LEADING_UNDERSCORE, "").toUpperCase();
54
+ };
51
55
  var reverse = (str) => {
52
56
  if (!str) return "";
53
57
  return str.split("").reverse().join("");
@@ -56,6 +60,16 @@ var slugify = (str) => {
56
60
  if (!str) return "";
57
61
  return str.toLowerCase().trim().replace(REGEX_SLUGIFY_NON_WORD, "").replace(REGEX_SLUGIFY_WHITESPACE, "-").replace(REGEX_SLUGIFY_TRIM_DASHES, "");
58
62
  };
63
+ var transform = {
64
+ capitalize,
65
+ camel: camelCase,
66
+ kebab: kebabCase,
67
+ pascal: pascalCase,
68
+ snake: snakeCase,
69
+ snakeScream: snakeScreamCase,
70
+ reverse,
71
+ slugify
72
+ };
59
73
  var isEmail = (str, customRegex) => {
60
74
  if (!str) return false;
61
75
  const regex = customRegex || REGEX_EMAIL_DEFAULT;
@@ -71,6 +85,11 @@ var isPhone = (str, customRegex) => {
71
85
  const regex = customRegex || REGEX_PHONE_DEFAULT;
72
86
  return regex.test(str);
73
87
  };
88
+ var validate = {
89
+ email: isEmail,
90
+ url: isUrl,
91
+ phone: isPhone
92
+ };
74
93
  var trim = (str, maxLength, trimChar = "...") => {
75
94
  if (!maxLength) return str;
76
95
  return str?.length > maxLength ? `${str?.slice(0, maxLength)}${trimChar}` : str;
@@ -149,6 +168,16 @@ var initials = (str, maxInitials) => {
149
168
  }
150
169
  return initialsArray.join("");
151
170
  };
171
+ var edit = {
172
+ trim,
173
+ repeat,
174
+ pad,
175
+ wrap,
176
+ unwrap,
177
+ prefix,
178
+ suffix,
179
+ initials
180
+ };
152
181
  var removeWhitespace = (str) => {
153
182
  if (!str) return "";
154
183
  return str.replace(REGEX_WHITESPACE_ALL, "");
@@ -181,7 +210,17 @@ var unescapeHtml = (str) => {
181
210
  "&quot;": '"',
182
211
  "&#39;": "'"
183
212
  };
184
- return str.replace(REGEX_HTML_UNESCAPE_ENTITIES, (entity) => htmlUnescapes[entity]);
213
+ return str.replace(
214
+ REGEX_HTML_UNESCAPE_ENTITIES,
215
+ (entity) => htmlUnescapes[entity]
216
+ );
217
+ };
218
+ var clean = {
219
+ whitespace: removeWhitespace,
220
+ normalizeWhitespace,
221
+ html: stripHtml,
222
+ escapeHtml,
223
+ unescapeHtml
185
224
  };
186
225
  var mask = (str, visibleChars = 4, maskChar = "*") => {
187
226
  if (!str) return "";
@@ -189,12 +228,18 @@ var mask = (str, visibleChars = 4, maskChar = "*") => {
189
228
  const maskLength = str.length - visibleChars;
190
229
  return maskChar.repeat(maskLength) + str.slice(-visibleChars);
191
230
  };
192
- var highlight = (str, search, wrapper = { start: "<mark>", end: "</mark>" }, caseSensitive = false) => {
231
+ var highlight = (str, search, wrapper = {
232
+ start: "<mark>",
233
+ end: "</mark>"
234
+ }, caseSensitive = false) => {
193
235
  if (!str || !search) return str;
194
236
  const wrapStart = typeof wrapper === "string" ? wrapper : wrapper.start;
195
237
  const wrapEnd = typeof wrapper === "string" ? wrapper : wrapper.end;
196
238
  const flags = caseSensitive ? "g" : "gi";
197
- const regex = new RegExp(search.replace(REGEX_HIGHLIGHT_ESCAPE, "\\$&"), flags);
239
+ const regex = new RegExp(
240
+ search.replace(REGEX_HIGHLIGHT_ESCAPE, "\\$&"),
241
+ flags
242
+ );
198
243
  return str.replace(regex, (match) => `${wrapStart}${match}${wrapEnd}`);
199
244
  };
200
245
  var quote = (type = "double") => {
@@ -237,38 +282,28 @@ var bracket = (type = "round") => {
237
282
  remove: (str) => unwrap(str, bracketPair)
238
283
  };
239
284
  };
285
+ var format = {
286
+ mask,
287
+ highlight,
288
+ quote,
289
+ bracket
290
+ };
240
291
 
241
292
  // src/index.ts
242
293
  var st = {
243
- bracket,
244
- camelCase,
245
- capitalize,
246
- escapeHtml,
247
- highlight,
248
- initials,
249
- isEmail,
250
- isPhone,
251
- isUrl,
252
- kebabCase,
253
- mask,
254
- normalizeWhitespace,
255
- pad,
256
- pascalCase,
257
- prefix,
258
- quote,
259
- removeWhitespace,
260
- repeat,
261
- reverse,
262
- slugify,
263
- snakeCase,
264
- stripHtml,
265
- suffix,
266
- trim,
267
- unescapeHtml,
268
- unwrap,
269
- wrap
294
+ transform,
295
+ validate,
296
+ edit,
297
+ clean,
298
+ format
270
299
  };
271
300
  var index_default = st;
272
301
  export {
273
- index_default as default
302
+ capitalize,
303
+ clean,
304
+ index_default as default,
305
+ edit,
306
+ format,
307
+ transform,
308
+ validate
274
309
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "string-tuner",
3
- "version": "1.0.4",
4
- "description": "Multitool for string manipulation and analysis.",
3
+ "version": "1.0.5",
4
+ "description": "Multitool for string edits and analysis.",
5
5
  "main": "/dist/index.js",
6
6
  "module": "./dist/index.mjs",
7
7
  "types": "./dist/index.d.ts",