stringzy 2.2.1 → 3.0.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.
Files changed (150) hide show
  1. package/.github/workflows/publish.yml +29 -0
  2. package/.github/workflows/test-on-pr.yml +23 -0
  3. package/CONTRIBUTING.md +87 -0
  4. package/LICENSE +21 -21
  5. package/README.md +952 -723
  6. package/changelog.txt +110 -110
  7. package/dist/analyzing/characterCount.d.ts +1 -0
  8. package/dist/analyzing/characterCount.js +9 -0
  9. package/dist/analyzing/characterFrequency.d.ts +1 -0
  10. package/dist/analyzing/characterFrequency.js +16 -0
  11. package/dist/analyzing/complexity.d.ts +6 -0
  12. package/dist/analyzing/complexity.js +30 -0
  13. package/dist/analyzing/index.d.ts +20 -0
  14. package/dist/analyzing/index.js +29 -0
  15. package/dist/analyzing/readingDuration.d.ts +10 -0
  16. package/dist/analyzing/readingDuration.js +17 -0
  17. package/dist/analyzing/stringSimilarity.d.ts +8 -0
  18. package/dist/analyzing/stringSimilarity.js +145 -0
  19. package/dist/analyzing/wordCount.d.ts +1 -0
  20. package/dist/analyzing/wordCount.js +11 -0
  21. package/dist/formatting/capitalize.d.ts +1 -0
  22. package/dist/formatting/capitalize.js +12 -0
  23. package/dist/formatting/index.d.ts +11 -0
  24. package/dist/formatting/index.js +17 -0
  25. package/dist/formatting/number.d.ts +1 -0
  26. package/dist/formatting/number.js +7 -0
  27. package/dist/formatting/phone.d.ts +2 -0
  28. package/dist/formatting/phone.js +25 -0
  29. package/dist/index.d.ts +47 -0
  30. package/dist/index.js +30 -0
  31. package/dist/tests/analyzing/characterCount.test.d.ts +1 -0
  32. package/dist/tests/analyzing/characterCount.test.js +19 -0
  33. package/dist/tests/analyzing/characterFrequency.test.d.ts +1 -0
  34. package/dist/tests/analyzing/characterFrequency.test.js +22 -0
  35. package/dist/tests/analyzing/complexity.test.d.ts +1 -0
  36. package/dist/tests/analyzing/complexity.test.js +28 -0
  37. package/dist/tests/analyzing/readingDuration.test.d.ts +1 -0
  38. package/dist/tests/analyzing/readingDuration.test.js +45 -0
  39. package/dist/tests/analyzing/stringSimilarity.test.d.ts +1 -0
  40. package/dist/tests/analyzing/stringSimilarity.test.js +61 -0
  41. package/dist/tests/analyzing/wordCount.test.d.ts +1 -0
  42. package/dist/tests/analyzing/wordCount.test.js +22 -0
  43. package/dist/tests/formatting/capitalize.test.d.ts +1 -0
  44. package/dist/tests/formatting/capitalize.test.js +22 -0
  45. package/dist/tests/formatting/number.test.d.ts +1 -0
  46. package/dist/tests/formatting/number.test.js +19 -0
  47. package/dist/tests/formatting/phone.test.d.ts +1 -0
  48. package/dist/tests/formatting/phone.test.js +25 -0
  49. package/dist/tests/transformations/camelCase.test.d.ts +1 -0
  50. package/dist/tests/transformations/camelCase.test.js +19 -0
  51. package/dist/tests/transformations/capitalizeWords.test.d.ts +1 -0
  52. package/dist/tests/transformations/capitalizeWords.test.js +19 -0
  53. package/dist/tests/transformations/constantCase.test.d.ts +1 -0
  54. package/dist/tests/transformations/constantCase.test.js +19 -0
  55. package/dist/tests/transformations/deburr.test.d.ts +1 -0
  56. package/dist/tests/transformations/deburr.test.js +27 -0
  57. package/dist/tests/transformations/escapeHTML.test.d.ts +1 -0
  58. package/dist/tests/transformations/escapeHTML.test.js +46 -0
  59. package/dist/tests/transformations/initials.test.d.ts +1 -0
  60. package/dist/tests/transformations/initials.test.js +25 -0
  61. package/dist/tests/transformations/kebabCase.test.d.ts +1 -0
  62. package/dist/tests/transformations/kebabCase.test.js +19 -0
  63. package/dist/tests/transformations/maskSegment.test.d.ts +1 -0
  64. package/dist/tests/transformations/maskSegment.test.js +30 -0
  65. package/dist/tests/transformations/pascalCase.test.d.ts +1 -0
  66. package/dist/tests/transformations/pascalCase.test.js +19 -0
  67. package/dist/tests/transformations/removeDuplicates.test.d.ts +1 -0
  68. package/dist/tests/transformations/removeDuplicates.test.js +19 -0
  69. package/dist/tests/transformations/removeSpecialChars.test.d.ts +1 -0
  70. package/dist/tests/transformations/removeSpecialChars.test.js +22 -0
  71. package/dist/tests/transformations/removeWords.test.d.ts +1 -0
  72. package/dist/tests/transformations/removeWords.test.js +25 -0
  73. package/dist/tests/transformations/snakeCase.test.d.ts +1 -0
  74. package/dist/tests/transformations/snakeCase.test.js +19 -0
  75. package/dist/tests/transformations/titleCase.test.d.ts +1 -0
  76. package/dist/tests/transformations/titleCase.test.js +19 -0
  77. package/dist/tests/transformations/toSlug.test.d.ts +1 -0
  78. package/dist/tests/transformations/toSlug.test.js +22 -0
  79. package/dist/tests/transformations/truncateText.test.d.ts +1 -0
  80. package/dist/tests/transformations/truncateText.test.js +31 -0
  81. package/dist/tests/validations/isDate.test.d.ts +1 -0
  82. package/dist/tests/validations/isDate.test.js +55 -0
  83. package/dist/tests/validations/isEmail.test.d.ts +1 -0
  84. package/dist/tests/validations/isEmail.test.js +17 -0
  85. package/dist/tests/validations/isEmpty.test.d.ts +1 -0
  86. package/dist/tests/validations/isEmpty.test.js +19 -0
  87. package/dist/tests/validations/isHexColor.test.d.ts +1 -0
  88. package/dist/tests/validations/isHexColor.test.js +32 -0
  89. package/dist/tests/validations/isIPv4.test.d.ts +1 -0
  90. package/dist/tests/validations/isIPv4.test.js +59 -0
  91. package/dist/tests/validations/isSlug.test.d.ts +1 -0
  92. package/dist/tests/validations/isSlug.test.js +22 -0
  93. package/dist/tests/validations/isURL.test.d.ts +1 -0
  94. package/dist/tests/validations/isURL.test.js +18 -0
  95. package/dist/transformations/camelCase.d.ts +1 -0
  96. package/dist/transformations/camelCase.js +15 -0
  97. package/dist/transformations/capitalizeWords.d.ts +1 -0
  98. package/dist/transformations/capitalizeWords.js +9 -0
  99. package/dist/transformations/constantCase.d.ts +1 -0
  100. package/dist/transformations/constantCase.js +15 -0
  101. package/dist/transformations/deburr.d.ts +7 -0
  102. package/dist/transformations/deburr.js +16 -0
  103. package/dist/transformations/escapeHTML.d.ts +1 -0
  104. package/dist/transformations/escapeHTML.js +14 -0
  105. package/dist/transformations/index.d.ts +49 -0
  106. package/dist/transformations/index.js +67 -0
  107. package/dist/transformations/initials.d.ts +1 -0
  108. package/dist/transformations/initials.js +19 -0
  109. package/dist/transformations/kebabCase.d.ts +1 -0
  110. package/dist/transformations/kebabCase.js +15 -0
  111. package/dist/transformations/maskSegment.d.ts +9 -0
  112. package/dist/transformations/maskSegment.js +25 -0
  113. package/dist/transformations/pascalCase.d.ts +1 -0
  114. package/dist/transformations/pascalCase.js +15 -0
  115. package/dist/transformations/removeDuplicates.d.ts +1 -0
  116. package/dist/transformations/removeDuplicates.js +13 -0
  117. package/dist/transformations/removeSpecialChars.d.ts +1 -0
  118. package/dist/transformations/removeSpecialChars.js +12 -0
  119. package/dist/transformations/removeWords.d.ts +1 -0
  120. package/dist/transformations/removeWords.js +23 -0
  121. package/dist/transformations/snakeCase.d.ts +1 -0
  122. package/dist/transformations/snakeCase.js +15 -0
  123. package/dist/transformations/titleCase.d.ts +1 -0
  124. package/dist/transformations/titleCase.js +14 -0
  125. package/dist/transformations/toSlug.d.ts +1 -0
  126. package/dist/transformations/toSlug.js +13 -0
  127. package/dist/transformations/truncateText.d.ts +1 -0
  128. package/dist/transformations/truncateText.js +19 -0
  129. package/dist/validations/index.d.ts +23 -0
  130. package/dist/validations/index.js +33 -0
  131. package/dist/validations/isDate.d.ts +18 -0
  132. package/dist/validations/isDate.js +63 -0
  133. package/dist/validations/isEmail.d.ts +1 -0
  134. package/dist/validations/isEmail.js +7 -0
  135. package/dist/validations/isEmpty.d.ts +1 -0
  136. package/dist/validations/isEmpty.js +6 -0
  137. package/dist/validations/isHexColor.d.ts +7 -0
  138. package/dist/validations/isHexColor.js +15 -0
  139. package/dist/validations/isIPv4.d.ts +1 -0
  140. package/dist/validations/isIPv4.js +13 -0
  141. package/dist/validations/isSlug.d.ts +1 -0
  142. package/dist/validations/isSlug.js +10 -0
  143. package/dist/validations/isURL.d.ts +1 -0
  144. package/dist/validations/isURL.js +12 -0
  145. package/package.json +10 -4
  146. package/analysis.js +0 -21
  147. package/formatting.js +0 -37
  148. package/index.js +0 -75
  149. package/transformations.js +0 -190
  150. package/validations.js +0 -80
package/README.md CHANGED
@@ -1,723 +1,952 @@
1
-
2
- <div align="center">
3
-
4
-
5
- ![Stringzy banner](./assets/stringzy-banner2.jpg)
6
-
7
-
8
- ![NPM Version](https://img.shields.io/npm/v/stringzy)
9
- ![Downloads](https://img.shields.io/npm/dt/stringzy)
10
- ![License](https://img.shields.io/npm/l/stringzy)
11
- ![Bundle Size](https://img.shields.io/bundlephobia/min/stringzy)
12
- [![Open Source Love svg1](https://badges.frapsoft.com/os/v1/open-source.svg?v=103)](https://github.com/ellerbrock/open-source-badges/)
13
- [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)
14
-
15
- **A lightweight, zero-dependency NPM Package for elegant string manipulations. It provides a comprehensive range of text utilities for JavaScript and Node.js applications including transformations, validations, analysis, and formatting.**
16
-
17
- [Checkout our Contributors!](#contri)
18
-
19
-
20
- </div>
21
-
22
-
23
- ## ✨ Features
24
-
25
- - 💪 **Powerful** - Transform, validate, analyze, and format strings with minimal code
26
- - 🪶 **Lightweight** - Zero dependencies, tiny footprint
27
- - 🧩 **Modular** - Import only what you need with organized namespaces
28
- - 🚀 **Fast** - Optimized for performance
29
- - **Tested** - Reliable and robust
30
- - 🎯 **Comprehensive** - 4 specialized modules for all string needs
31
-
32
- ## 📦 Installation
33
-
34
- ```bash
35
- # Using npm
36
- npm install stringzy
37
-
38
- # Using yarn
39
- yarn add stringzy
40
-
41
- # Using pnpm
42
- pnpm add stringzy
43
- ```
44
-
45
- ## 🚀 Quick Start
46
-
47
- ```javascript
48
- // Import the entire library
49
- import stringzy from 'stringzy';
50
-
51
- // Or import specific functions
52
- import { toUpperCase, isEmail, wordCount, formatPhone } from 'stringzy';
53
-
54
- // Or import by namespace
55
- import { transform, validate, analyze, format } from 'stringzy';
56
-
57
- // Transform your strings
58
- const slug = stringzy.toSlug('Hello World!'); // 'hello-world'
59
- const isValid = stringzy.validate.isEmail('user@example.com'); // true
60
- const count = stringzy.analyze.wordCount('Hello world'); // 2
61
- ```
62
-
63
- ## 📋 Table of Contents
64
-
65
- ### Transformations
66
- - [truncateText](#truncatetext) - Truncates text to a specified maximum length
67
- - [toSlug](#toslug) - Converts a string to a URL-friendly slug
68
- - [capitalizeWords](#capitalizewords) - Capitalizes the first letter of each word
69
- - [removeSpecialChars](#removespecialchars) - Removes special characters from a string
70
- - [removeWords](#removewords) - Removes specified words from a string
71
- - [removeDuplicates](#removeduplicates) - Removes specified words from a string
72
- - [initials](#initials) - Extracts initials from a text string
73
- - [camelCase](#camelcase) - Converts the given string to Camel Case
74
- - [pascaslCase](#pascalcase) - Converts the given string to Pascal Case
75
- - [snakeCase](#snakecase) - Converts the given string to Snake Case
76
- - [kebabCase](#kebabcase) - Converts the given string to Kebab Case
77
- - [titleCase](#titlecase) - Converts the given string to Title Case
78
- - [constantCase](#constantcase) - Converts the given string to Constant Case
79
-
80
- ### Validations
81
- - [isURL](#isurl) - Checks if a string is a valid URL
82
- - [isEmail](#isemail) - Checks if a string is a valid email address
83
- - [isDate](#isdate) - Checks if a string is a valid date
84
- - [isEmpty](#isempty) - Checks if a string is empty or contains only whitespace
85
-
86
- ### Analysis
87
- - [wordCount](#wordcount) - Counts the number of words in a string
88
- - [characterCount](#charactercount) - Counts the number of characters in a string
89
- - [characterFrequency](#characterfrequency) - Analyzes character frequency in a string
90
-
91
- ### Formatting
92
- - [capitalize](#capitalize) - Capitalizes the first letter of each word
93
- - [formatNumber](#formatnumber) - Formats a number string with thousand separators
94
- - [formatPhone](#formatphone) - Formats a phone number string to standard format
95
-
96
- ## 📋 API Reference
97
-
98
- ### 🔄 Transformations
99
-
100
- Functions for transforming and manipulating strings.
101
-
102
- #### <a id="truncatetext"></a>`truncateText(text, maxLength, suffix = '...')`
103
-
104
- Truncates text to a specified maximum length, adding a suffix if truncated.
105
-
106
- ```javascript
107
- import { truncateText } from 'stringzy';
108
-
109
- truncateText('This is a long sentence that needs truncating', 10);
110
- // Returns: 'This is a...'
111
-
112
- truncateText('This is a long sentence', 10, ' →');
113
- // Returns: 'This is a →'
114
-
115
- truncateText('Short', 10);
116
- // Returns: 'Short' (no truncation needed)
117
- ```
118
-
119
- | Parameter | Type | Default | Description |
120
- |-----------|------|---------|-------------|
121
- | text | string | required | The input string to truncate |
122
- | maxLength | number | required | Maximum length of the output string (excluding suffix) |
123
- | suffix | string | '...' | String to append if truncation occurs |
124
-
125
- #### <a id="toslug"></a>`toSlug(text)`
126
-
127
- Converts a string to a URL-friendly slug.
128
-
129
- ```javascript
130
- import { toSlug } from 'stringzy';
131
-
132
- toSlug('Hello World!');
133
- // Returns: 'hello-world'
134
-
135
- toSlug('This is a TEST string 123');
136
- // Returns: 'this-is-a-test-string-123'
137
-
138
- toSlug('Special $#@! characters');
139
- // Returns: 'special-characters'
140
- ```
141
-
142
- | Parameter | Type | Default | Description |
143
- |-----------|------|---------|-------------|
144
- | text | string | required | The input string to convert to a slug |
145
-
146
- #### <a id="capitalizewords"></a>`capitalizeWords(text)`
147
-
148
- Capitalizes the first letter of each word in a string.
149
-
150
- ```javascript
151
- import { capitalizeWords } from 'stringzy';
152
-
153
- capitalizeWords('hello world');
154
- // Returns: 'Hello World'
155
-
156
- capitalizeWords('javascript string manipulation');
157
- // Returns: 'Javascript String Manipulation'
158
-
159
- capitalizeWords('already Capitalized');
160
- // Returns: 'Already Capitalized'
161
- ```
162
-
163
- | Parameter | Type | Default | Description |
164
- |-----------|------|---------|-------------|
165
- | text | string | required | The input string to capitalize |
166
-
167
- #### <a id="removespecialchars"></a>`removeSpecialChars(text, replacement = '')`
168
-
169
- Removes special characters from a string, optionally replacing them.
170
-
171
- ```javascript
172
- import { removeSpecialChars } from 'stringzy';
173
-
174
- removeSpecialChars('Hello, world!');
175
- // Returns: 'Hello world'
176
-
177
- removeSpecialChars('email@example.com');
178
- // Returns: 'emailexamplecom'
179
-
180
- removeSpecialChars('Phone: (123) 456-7890', '-');
181
- // Returns: 'Phone-123-456-7890'
182
- ```
183
-
184
- | Parameter | Type | Default | Description |
185
- |-----------|------|---------|-------------|
186
- | text | string | required | The input string to process |
187
- | replacement | string | '' | String to replace special characters with |
188
-
189
- #### <a id="removewords"></a>`removeWords(text, wordsToRemove)`
190
-
191
- Removes specified words from a string
192
-
193
- ```javascript
194
- import { removeWords } from 'stringzy';
195
-
196
- removeWords('Hello world this is a test', ['this', 'is']);
197
- // Returns: 'Hello world a test'
198
-
199
- removeWords('Remove The Quick BROWN fox', ['the', 'brown']);
200
- // Returns: 'Remove Quick fox'
201
-
202
- removeWords('JavaScript is awesome and JavaScript rocks', ['JavaScript']);
203
- // Returns: 'is awesome and rocks'
204
- ```
205
-
206
- | Parameter | Type | Default | Description |
207
- |-----------|------|---------|-------------|
208
- | text | string | required | The input string to process |
209
- | wordsToRemove | string[] | required | Array of words to remove from the string |
210
-
211
- #### <a id="removeduplicates"></a>`removeDuplicates(text)`
212
-
213
- Removes duplicate case-sensitive words from a given text.
214
-
215
- ```javascript
216
- import { removeDuplicates } from 'stringzy';
217
-
218
- removeDuplicates('Hello world this is a is a test');
219
- // Returns: 'Hello world this is a test'
220
-
221
- removeDuplicates('Remove me me me me or Me');
222
- // Returns: 'Remove me or Me''
223
-
224
- removeDuplicates('JavaScript is not bad and not awesome');
225
- // Returns: 'JavaScript is not bad and awesome'
226
- ```
227
-
228
- | Parameter | Type | Default | Description |
229
- |-----------|------|---------|-------------|
230
- | text | string | required | The input string to process |
231
-
232
- #### <a id="initials"></a>`initials(text, limit)`
233
-
234
- Extracts initials from a text string.
235
-
236
- ```javascript
237
- import { initials } from 'stringzy';
238
-
239
- initials('John Doe');
240
- // Returns: 'JD'
241
-
242
- initials('Alice Bob Charlie', 2);
243
- // Returns: 'AB'
244
-
245
- initials('Hello World Test Case');
246
- // Returns: 'HWTC'
247
-
248
- initials('single');
249
- // Returns: 's'
250
-
251
- initials(' Multiple Spaces Between ');
252
- // Returns: 'MSB'
253
- ```
254
-
255
- | Parameter | Type | Default | Description |
256
- |-----------|------|---------|-------------|
257
- | text | string | required | The input string to extract initials from |
258
- | limit | number | undefined | Maximum number of initials to return (optional) |
259
-
260
- #### <a id="camelcase"></a>`camelCase(text)`
261
-
262
- Converts the given string to Camel Case.
263
-
264
- ```javascript
265
- import { camelCase } from 'stringzy';
266
-
267
- camelCase('hello world'); // 'helloWorld'
268
- camelCase('this is a test'); // 'thisIsATest'
269
- ```
270
- | Parameter | Type | Default | Description |
271
- |-----------|------|---------|-------------|
272
- | text | string | required | The input string to convert to Camel Case |
273
-
274
-
275
- #### <a id="pascalcase"></a>`pascalCase(text)`
276
- Converts the given string to Pascal Case.
277
-
278
- ```javascript
279
- import { pascalCase } from 'stringzy';
280
-
281
-
282
- pascalCase('hello world'); // 'HelloWorld'
283
- pascalCase('this is a test'); // 'ThisIsATest'
284
- ```
285
- | Parameter | Type | Default | Description |
286
- |-----------|------|---------|-------------|
287
- | text | string | required | The input string to convert to Pascal Case |
288
-
289
- #### <a id="snakecase"></a>`snakeCase(text)`
290
-
291
- Converts the given string to Snake Case.
292
-
293
- ```javascript
294
- import { snakeCase } from 'stringzy';
295
- snakeCase('hello world'); // 'hello_world'
296
- snakeCase('this is a test'); // 'this_is_a_test'
297
- ```
298
-
299
- | Parameter | Type | Default | Description |
300
- |-----------|------|---------|-------------|
301
- | text | string | required | The input string to convert to Snake Case |
302
-
303
-
304
-
305
-
306
- #### <a id="kebabcase"></a>`kebabCase(text)`
307
-
308
- Converts the given string to Kebab Case.
309
-
310
- ```javascript
311
- import { kebabCase } from 'stringzy';
312
-
313
-
314
- kebabCase('hello world'); // 'hello-world'
315
- kebabCase('this is a test'); // 'this-is-a-test'
316
- ```
317
- | Parameter | Type | Default | Description |
318
- |-----------|------|---------|-------------|
319
- | text | string | required | The input string to convert to Kebab Case |
320
-
321
-
322
-
323
- #### <a id="titlecase"></a>`titleCase(text)`
324
-
325
- Converts the given string to Title Case.
326
-
327
- ```javascript
328
- import { titleCase } from 'stringzy';
329
-
330
-
331
- titleCase('hello world'); // 'Hello World'
332
- titleCase('this is a test'); // 'This Is A Test'
333
- ```
334
- | Parameter | Type | Default | Description |
335
- |-----------|------|---------|-------------|
336
- | text | string | required | The input string to convert to Title Case |
337
-
338
- #### <a id="constantcase"></a>`constantCase(text)`
339
- Converts the given string to Constant Case.
340
-
341
- ```javascript
342
- import { constantCase } from 'stringzy';
343
-
344
-
345
- constantCase('hello world'); // 'HELLO_WORLD'
346
- constantCase('this is a test'); // 'THIS_IS_A_TEST'
347
-
348
- ```
349
- | Parameter | Type | Default | Description |
350
- |-----------|------|---------|-------------|
351
- | text | string | required | The input string to convert to Constant Case |
352
-
353
- ---
354
-
355
- ### ✅ Validations
356
-
357
- Functions for validating string formats and content.
358
-
359
- #### <a id="isurl"></a>`isURL(text)`
360
-
361
- Checks if a string is a valid URL.
362
-
363
- ```javascript
364
- isURL('https://example.com'); // true
365
- isURL('not-a-url'); // false
366
- ```
367
-
368
- | Parameter | Type | Default | Description |
369
- |-----------|------|---------|-------------|
370
- | text | string | required | The input string to validate as URL |
371
-
372
- #### <a id="isemail"></a>`isEmail(text)`
373
-
374
- Checks if a string is a valid email address.
375
-
376
- ```javascript
377
- isEmail('user@example.com'); // true
378
- isEmail('invalid-email'); // false
379
- ```
380
-
381
- | Parameter | Type | Default | Description |
382
- |-----------|------|---------|-------------|
383
- | text | string | required | The input string to validate as email |
384
-
385
- #### <a id="isdate"></a>`isDate(text)`
386
-
387
- Checks if a string is a valid date.
388
-
389
- ```javascript
390
- import { isDate } from 'stringzy';
391
-
392
- isDate('2023-12-25'); // true
393
- isDate('12/25/2023'); // true
394
- isDate('invalid-date'); // false
395
- isDate('2023-13-45'); // false
396
- ```
397
-
398
- | Parameter | Type | Default | Description |
399
- |-----------|------|---------|-------------|
400
- | text | string | required | The input string to validate as date |
401
-
402
- #### <a id="isempty"></a>`isEmpty(text)`
403
-
404
- Checks if a string is empty or contains only whitespace.
405
-
406
- ```javascript
407
- isEmpty(' '); // true
408
- isEmpty('hello'); // false
409
- ```
410
-
411
- | Parameter | Type | Default | Description |
412
- |-----------|------|---------|-------------|
413
- | text | string | required | The input string to check for emptiness |
414
-
415
- ---
416
-
417
-
418
- ### 📊 Analysis
419
-
420
- Functions for analyzing string content and structure.
421
-
422
- #### <a id="wordcount"></a>`wordCount(text)`
423
-
424
- Counts the number of words in a string.
425
-
426
- ```javascript
427
- wordCount('Hello world'); // 2
428
- wordCount(''); // 0
429
- ```
430
-
431
- | Parameter | Type | Default | Description |
432
- |-----------|------|---------|-------------|
433
- | text | string | required | The input string to count words in |
434
-
435
- #### <a id="charactercount"></a>`characterCount(text)`
436
-
437
- Counts the number of characters in a string.
438
-
439
- ```javascript
440
- characterCount('Hello'); // 5
441
- ```
442
-
443
- | Parameter | Type | Default | Description |
444
- |-----------|------|---------|-------------|
445
- | text | string | required | The input string to count characters in |
446
-
447
- #### <a id="characterfrequency"></a>`characterFrequency(text)`
448
-
449
- Analyzes character frequency in a string (excluding spaces).
450
-
451
- ```javascript
452
- characterFrequency('hello'); // { h: 1, e: 1, l: 2, o: 1 }
453
- ```
454
-
455
- | Parameter | Type | Default | Description |
456
- |-----------|------|---------|-------------|
457
- | text | string | required | The input string to analyze character frequency |
458
-
459
- ---
460
-
461
- ### 🎨 Formatting
462
-
463
- Functions for formatting strings into specific patterns.
464
-
465
- #### <a id="capitalize"></a>`capitalize(text)`
466
-
467
- Capitalizes the first letter of each word.
468
-
469
- ```javascript
470
- capitalize('hello world'); // 'Hello World'
471
- capitalize('javaScript programming'); // 'Javascript Programming'
472
- ```
473
-
474
- | Parameter | Type | Default | Description |
475
- |-----------|------|---------|-------------|
476
- | text | string | required | The input string to capitalize |
477
-
478
- #### <a id="formatnumber"></a>`formatNumber(number, separator = ',')`
479
-
480
- Formats a number string with thousand separators.
481
-
482
- ```javascript
483
- formatNumber('1234567'); // '1,234,567'
484
- formatNumber('1234567', '.'); // '1.234.567'
485
- ```
486
-
487
- | Parameter | Type | Default | Description |
488
- |-----------|------|---------|-------------|
489
- | number | string\|number | required | The number to format |
490
- | separator | string | ',' | The separator to use for thousands |
491
-
492
- #### <a id="formatphone"></a>`formatPhone(phone, format = 'us')`
493
-
494
- Formats a phone number string to standard format.
495
-
496
- ```javascript
497
- formatPhone('1234567890'); // '(123) 456-7890'
498
- formatPhone('11234567890', 'international'); // '+1 (123) 456-7890'
499
- ```
500
-
501
- | Parameter | Type | Default | Description |
502
- |-----------|------|---------|-------------|
503
- | phone | string | required | The phone number string to format |
504
- | format | string | 'us' | Format type: 'us' or 'international' |
505
-
506
- ## 🔧 Usage Patterns
507
-
508
- ### Individual Function Imports
509
- ```javascript
510
- import { isEmail, wordCount, capitalize } from 'stringzy';
511
-
512
- const email = 'user@example.com';
513
- if (isEmail(email)) {
514
- console.log('Valid email!');
515
- }
516
- ```
517
-
518
- ### Namespace Imports
519
- ```javascript
520
- import { validate, analyze, format } from 'stringzy';
521
-
522
- // Organized by functionality
523
- const emailValid = validate.isEmail('test@example.com');
524
- const words = analyze.wordCount('Hello world');
525
- const formatted = format.capitalize('hello world');
526
- ```
527
-
528
- ### Default Import (All Functions)
529
- ```javascript
530
- import stringzy from 'stringzy';
531
-
532
- // Access any function
533
- stringzy.toUpperCase('hello');
534
- stringzy.validate.isEmail('test@example.com');
535
- stringzy.analyze.wordCount('Hello world');
536
- stringzy.format.capitalize('hello world');
537
- ```
538
-
539
- ## 🛠️ Usage Examples
540
-
541
- ### In a React component
542
-
543
- ```jsx
544
- import React from 'react';
545
- import { truncate, capitalize, wordCount, isEmpty } from 'stringzy';
546
-
547
- function ArticlePreview({ title, content }) {
548
- const displayTitle = isEmpty(title) ? 'Untitled' : capitalize(title);
549
- const previewText = truncate(content, 150);
550
- const readingTime = Math.ceil(wordCount(content) / 200);
551
-
552
- return (
553
- <div className="article-preview">
554
- <h2>{displayTitle}</h2>
555
- <p>{previewText}</p>
556
- <small>{readingTime} min read</small>
557
- </div>
558
- );
559
- }
560
- ```
561
-
562
- ### Form Validation
563
-
564
- ```javascript
565
- import { validate } from 'stringzy';
566
-
567
- function validateForm(formData) {
568
- const errors = {};
569
-
570
- if (!validate.isEmail(formData.email)) {
571
- errors.email = 'Please enter a valid email address';
572
- }
573
-
574
- if (!validate.isURL(formData.website)) {
575
- errors.website = 'Please enter a valid URL';
576
- }
577
-
578
- if (validate.isEmpty(formData.name)) {
579
- errors.name = 'Name is required';
580
- }
581
-
582
- return errors;
583
- }
584
- ```
585
-
586
- ### Content Analysis Dashboard
587
-
588
- ```javascript
589
- import { analyze } from 'stringzy';
590
-
591
- function getContentStats(text) {
592
- return {
593
- words: analyze.wordCount(text),
594
- characters: analyze.characterCount(text),
595
- frequency: analyze.characterFrequency(text),
596
- readingTime: Math.ceil(analyze.wordCount(text) / 200)
597
- };
598
- }
599
- ```
600
-
601
- ### Data Formatting
602
-
603
- ```javascript
604
- import { format } from 'stringzy';
605
-
606
- function formatUserData(userData) {
607
- return {
608
- name: format.capitalize(userData.name),
609
- phone: format.formatPhone(userData.phone),
610
- revenue: format.formatNumber(userData.revenue)
611
- };
612
- }
613
- ```
614
-
615
- ## 🔄 TypeScript Support
616
-
617
- The package includes TypeScript type definitions for all functions.
618
-
619
- ```typescript
620
- import { validate, analyze, format } from 'stringzy';
621
-
622
- // TypeScript will provide proper type checking
623
- const isValid: boolean = validate.isEmail('test@example.com');
624
- const count: number = analyze.wordCount('Hello world');
625
- const formatted: string = format.capitalize('hello world');
626
- ```
627
-
628
- ## 🏗️ Architecture
629
-
630
- stringzy is organized into four specialized modules:
631
-
632
- - **`transformations.js`** - Core string transformations
633
- - **`validations.js`** - String validation utilities
634
- - **`analysis.js`** - String analysis and metrics
635
- - **`formatting.js`** - String formatting functions
636
-
637
- Each module can be imported individually or accessed through the main entry point.
638
-
639
- ## 🤝 Contributing
640
-
641
- Contributions are welcome! Please feel free to submit a Pull Request.
642
-
643
- 1. Fork the repository
644
- 2. Create your feature branch (`git checkout -b feature/amazing-feature`)
645
- 3. Commit your changes (`git commit -m 'Add some amazing feature'`)
646
- 4. Push to the branch (`git push origin feature/amazing-feature`)
647
- 5. Open a Pull Request
648
-
649
-
650
- ## <a id="contri"></a>`Contributors`
651
-
652
- <table>
653
- <tbody>
654
- <tr>
655
- <td align="center">
656
- <a href="https://github.com/Samarth2190">
657
- <img src="https://avatars.githubusercontent.com/Samarth2190" width="100px;"
658
- alt="Samarth Ruia" />
659
- <br />
660
- <sub>
661
- <b>Samarth Ruia</b>
662
- </sub>
663
- </a>
664
- </td>
665
- <td align="center">
666
- <a href="https://github.com/JohnCervantes">
667
- <img src="https://avatars.githubusercontent.com/JohnCervantes" width="100px;"
668
- alt="John Cervantes" />
669
- <br />
670
- <sub>
671
- <b>John Cervantes</b>
672
- </sub>
673
- </a>
674
- </td>
675
- <td align="center">
676
- <a href="https://github.com/thehardiik">
677
- <img src="https://avatars.githubusercontent.com/thehardiik" width="100px;"
678
- alt="Hardik Srivastav" />
679
- <br />
680
- <sub>
681
- <b>Hardik Srivastav</b>
682
- </sub>
683
- </a>
684
- </td>
685
- <td align="center">
686
- <a href="https://github.com/ahmedsemih">
687
- <img src="https://avatars.githubusercontent.com/ahmedsemih" width="100px;"
688
- alt="Ahmed Semih Erkan" />
689
- <br />
690
- <sub>
691
- <b>Ahmed Semih Erkan</b>
692
- </sub>
693
- </a>
694
- </td>
695
- <td align="center">
696
- <a href="https://github.com/michaelvbend">
697
- <img src="https://avatars.githubusercontent.com/michaelvbend" width="100px;"
698
- alt="Michael van der Bend" />
699
- <br />
700
- <sub>
701
- <b>Michael van der Bend</b>
702
- </sub>
703
- </a>
704
- </td>
705
- </tr>
706
- </tbody>
707
- </table>
708
-
709
-
710
- ## 📝 License
711
-
712
- This project is licensed under the MIT License - see the LICENSE file for details.
713
-
714
- ## 🙏 Acknowledgments
715
-
716
- - Thank you to all contributors and users of this package!
717
- - Inspired by the need for comprehensive yet simple string manipulation utilities.
718
-
719
- If you have contributed to this project and your image is not here, please let us know, and we'll be happy to add it!
720
-
721
- ---
722
-
723
- Made with ❤️ by Samarth Ruia
1
+ <div align="center">
2
+
3
+
4
+ ![Stringzy banner](./assets/stringzy-banner2.jpg)
5
+
6
+
7
+ ![NPM Version](https://img.shields.io/npm/v/stringzy)
8
+ ![Downloads](https://img.shields.io/npm/dt/stringzy)
9
+ ![License](https://img.shields.io/npm/l/stringzy)
10
+ ![Bundle Size](https://img.shields.io/bundlephobia/min/stringzy)
11
+ [![Open Source Love svg1](https://badges.frapsoft.com/os/v1/open-source.svg?v=103)](https://github.com/ellerbrock/open-source-badges/)
12
+ [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)
13
+
14
+ **A lightweight, zero-dependency NPM Package for elegant string manipulations. It provides a comprehensive range of text utilities for JavaScript and Node.js applications including transformations, validations, analysis, and formatting.**
15
+
16
+ [Checkout our Contributors!](#contri)
17
+
18
+
19
+ [Join the Community!](#community)
20
+
21
+
22
+
23
+
24
+ </div>
25
+
26
+
27
+ ## Features
28
+
29
+ - 💪 **Powerful** - Transform, validate, analyze, and format strings with minimal code
30
+ - 🪶 **Lightweight** - Zero dependencies, tiny footprint
31
+ - 🧩 **Modular** - Import only what you need with organized namespaces
32
+ - 🚀 **Fast** - Optimized for performance
33
+ - ✅ **Tested** - Reliable and robust
34
+ - 🎯 **Comprehensive** - 4 specialized modules for all string needs
35
+
36
+ ## 📦 Installation
37
+
38
+ ```bash
39
+ # Using npm
40
+ npm install stringzy
41
+
42
+ # Using yarn
43
+ yarn add stringzy
44
+
45
+ # Using pnpm
46
+ pnpm add stringzy
47
+ ```
48
+
49
+ ## 🚀 Quick Start
50
+
51
+ ```javascript
52
+ // Import the entire library
53
+ import stringzy from 'stringzy';
54
+
55
+ // Or import specific functions
56
+ import { isEmail, wordCount, formatPhone } from 'stringzy';
57
+
58
+ // Or import by namespace
59
+ import { transform, validate, analyze, format } from 'stringzy';
60
+
61
+ // Transform your strings
62
+ const slug = stringzy.toSlug('Hello World!'); // 'hello-world'
63
+ const isValid = stringzy.validate.isEmail('user@example.com'); // true
64
+ const count = stringzy.analyze.wordCount('Hello world'); // 2
65
+ ```
66
+
67
+ ## 📋 Table of Contents
68
+
69
+ ### Transformations
70
+ - [truncateText](#truncatetext) - Truncates text to a specified maximum length
71
+ - [toSlug](#toslug) - Converts a string to a URL-friendly slug
72
+ - [capitalizeWords](#capitalizewords) - Capitalizes the first letter of each word
73
+ - [removeSpecialChars](#removespecialchars) - Removes special characters from a string
74
+ - [removeWords](#removewords) - Removes specified words from a string
75
+ - [removeDuplicates](#removeduplicates) - Removes duplicate words from a string
76
+ - [initials](#initials) - Extracts initials from a text string
77
+ - [camelCase](#camelcase) - Converts the given string to Camel Case
78
+ - [pascalCase](#pascalcase) - Converts the given string to Pascal Case
79
+ - [snakeCase](#snakecase) - Converts the given string to Snake Case
80
+ - [kebabCase](#kebabcase) - Converts the given string to Kebab Case
81
+ - [titleCase](#titlecase) - Converts the given string to Title Case
82
+ - [constantCase](#constantcase) - Converts the given string to Constant Case
83
+ - [escapeHTML](#escapehtml) - Escapes HTML special characters to prevent XSS attacks
84
+ - [maskSegment](#masksegment) - Masks a segment of a string by replacing characters between two indices with a specified character
85
+ - [deburr](#deburr) – Removes accents and diacritical marks from a string
86
+
87
+
88
+ ### Validations
89
+ - [isURL](#isurl) - Checks if a string is a valid URL
90
+ - [isEmail](#isemail) - Checks if a string is a valid email address
91
+ - [isDate](#isdate) - Checks if a string is a valid date
92
+ - [isEmpty](#isempty) - Checks if a string is empty or contains only whitespace
93
+ - [isSlug](#isslug) - Checks if a string is a valid slug
94
+ - [isIPv4](#isipv4) - Checks if a string is a valid IPv4 address
95
+ - [isHexColor](#ishexcolor) - Checks if the input string is a valid hex color
96
+
97
+ ### Analysis
98
+ - [wordCount](#wordcount) - Counts the number of words in a string
99
+ - [readingDuration](#readingduration) - Calculates the reading duration of a given string
100
+ - [characterCount](#charactercount) - Counts the number of characters in a string
101
+ - [characterFrequency](#characterfrequency) - Analyzes character frequency in a string
102
+ - [stringSimilarity](#stringsimilarity) - Calculates the percentage similarity between two strings
103
+ ### Formatting
104
+ - [capitalize](#capitalize) - Capitalizes the first letter of each word
105
+ - [formatNumber](#formatnumber) - Formats a number string with thousand separators
106
+ - [formatPhone](#formatphone) - Formats a phone number string to standard format
107
+
108
+ ## 📋 API Reference
109
+
110
+ ### 🔄 Transformations
111
+
112
+ Functions for transforming and manipulating strings.
113
+
114
+ #### <a id="truncatetext"></a>`truncateText(text, maxLength, suffix = '...')`
115
+
116
+ Truncates text to a specified maximum length, adding a suffix if truncated.
117
+
118
+ ```javascript
119
+ import { truncateText } from 'stringzy';
120
+
121
+ truncateText('This is a long sentence that needs truncating', 10);
122
+ // Returns: 'This is a...'
123
+
124
+ truncateText('This is a long sentence', 10, ' →');
125
+ // Returns: 'This is a →'
126
+
127
+ truncateText('Short', 10);
128
+ // Returns: 'Short' (no truncation needed)
129
+ ```
130
+
131
+ | Parameter | Type | Default | Description |
132
+ |-----------|------|---------|-------------|
133
+ | text | string | required | The input string to truncate |
134
+ | maxLength | number | required | Maximum length of the output string (excluding suffix) |
135
+ | suffix | string | '...' | String to append if truncation occurs |
136
+
137
+ #### <a id="toslug"></a>`toSlug(text)`
138
+
139
+ Converts a string to a URL-friendly slug.
140
+
141
+ ```javascript
142
+ import { toSlug } from 'stringzy';
143
+
144
+ toSlug('Hello World!');
145
+ // Returns: 'hello-world'
146
+
147
+ toSlug('This is a TEST string 123');
148
+ // Returns: 'this-is-a-test-string-123'
149
+
150
+ toSlug('Special $#@! characters');
151
+ // Returns: 'special-characters'
152
+ ```
153
+
154
+ | Parameter | Type | Default | Description |
155
+ |-----------|------|---------|-------------|
156
+ | text | string | required | The input string to convert to a slug |
157
+
158
+ #### <a id="capitalizewords"></a>`capitalizeWords(text)`
159
+
160
+ Capitalizes the first letter of each word in a string.
161
+
162
+ ```javascript
163
+ import { capitalizeWords } from 'stringzy';
164
+
165
+ capitalizeWords('hello world');
166
+ // Returns: 'Hello World'
167
+
168
+ capitalizeWords('javascript string manipulation');
169
+ // Returns: 'Javascript String Manipulation'
170
+
171
+ capitalizeWords('already Capitalized');
172
+ // Returns: 'Already Capitalized'
173
+ ```
174
+
175
+ | Parameter | Type | Default | Description |
176
+ |-----------|------|---------|-------------|
177
+ | text | string | required | The input string to capitalize |
178
+
179
+ #### <a id="removespecialchars"></a>`removeSpecialChars(text, replacement = '')`
180
+
181
+ Removes special characters from a string, optionally replacing them.
182
+
183
+ ```javascript
184
+ import { removeSpecialChars } from 'stringzy';
185
+
186
+ removeSpecialChars('Hello, world!');
187
+ // Returns: 'Hello world'
188
+
189
+ removeSpecialChars('email@example.com');
190
+ // Returns: 'emailexamplecom'
191
+
192
+ removeSpecialChars('Phone: (123) 456-7890', '-');
193
+ // Returns: 'Phone-123-456-7890'
194
+ ```
195
+
196
+ | Parameter | Type | Default | Description |
197
+ |-----------|------|---------|-------------|
198
+ | text | string | required | The input string to process |
199
+ | replacement | string | '' | String to replace special characters with |
200
+
201
+ #### <a id="removewords"></a>`removeWords(text, wordsToRemove)`
202
+
203
+ Removes specified words from a string
204
+
205
+ ```javascript
206
+ import { removeWords } from 'stringzy';
207
+
208
+ removeWords('Hello world this is a test', ['this', 'is']);
209
+ // Returns: 'Hello world a test'
210
+
211
+ removeWords('Remove The Quick BROWN fox', ['the', 'brown']);
212
+ // Returns: 'Remove Quick fox'
213
+
214
+ removeWords('JavaScript is awesome and JavaScript rocks', ['JavaScript']);
215
+ // Returns: 'is awesome and rocks'
216
+ ```
217
+
218
+ | Parameter | Type | Default | Description |
219
+ |-----------|------|---------|-------------|
220
+ | text | string | required | The input string to process |
221
+ | wordsToRemove | string[] | required | Array of words to remove from the string |
222
+
223
+ #### <a id="removeduplicates"></a>`removeDuplicates(text)`
224
+
225
+ Removes duplicate case-sensitive words from a given text.
226
+
227
+ ```javascript
228
+ import { removeDuplicates } from 'stringzy';
229
+
230
+ removeDuplicates('Hello world this is a is a test');
231
+ // Returns: 'Hello world this is a test'
232
+
233
+ removeDuplicates('Remove me me me me or Me');
234
+ // Returns: 'Remove me or Me'
235
+
236
+ removeDuplicates('JavaScript is not bad and not awesome');
237
+ // Returns: 'JavaScript is not bad and awesome'
238
+ ```
239
+
240
+ | Parameter | Type | Default | Description |
241
+ |-----------|------|---------|-------------|
242
+ | text | string | required | The input string to process |
243
+
244
+ #### <a id="initials"></a>`initials(text, limit)`
245
+
246
+ Extracts initials from a text string.
247
+
248
+ ```javascript
249
+ import { initials } from 'stringzy';
250
+
251
+ initials('John Doe');
252
+ // Returns: 'JD'
253
+
254
+ initials('Alice Bob Charlie', 2);
255
+ // Returns: 'AB'
256
+
257
+ initials('Hello World Test Case');
258
+ // Returns: 'HWTC'
259
+
260
+ initials('single');
261
+ // Returns: 's'
262
+
263
+ initials(' Multiple Spaces Between ');
264
+ // Returns: 'MSB'
265
+ ```
266
+
267
+ | Parameter | Type | Default | Description |
268
+ |-----------|------|---------|-------------|
269
+ | text | string | required | The input string to extract initials from |
270
+ | limit | number | undefined | Maximum number of initials to return (optional) |
271
+
272
+ #### <a id="camelcase"></a>`camelCase(text)`
273
+
274
+ Converts the given string to Camel Case.
275
+
276
+ ```javascript
277
+ import { camelCase } from 'stringzy';
278
+
279
+ camelCase('hello world'); // 'helloWorld'
280
+ camelCase('this is a test'); // 'thisIsATest'
281
+ ```
282
+ | Parameter | Type | Default | Description |
283
+ |-----------|------|---------|-------------|
284
+ | text | string | required | The input string to convert to Camel Case |
285
+
286
+
287
+ #### <a id="pascalcase"></a>`pascalCase(text)`
288
+ Converts the given string to Pascal Case.
289
+
290
+ ```javascript
291
+ import { pascalCase } from 'stringzy';
292
+
293
+
294
+ pascalCase('hello world'); // 'HelloWorld'
295
+ pascalCase('this is a test'); // 'ThisIsATest'
296
+ ```
297
+ | Parameter | Type | Default | Description |
298
+ |-----------|------|---------|-------------|
299
+ | text | string | required | The input string to convert to Pascal Case |
300
+
301
+ #### <a id="snakecase"></a>`snakeCase(text)`
302
+
303
+ Converts the given string to Snake Case.
304
+
305
+ ```javascript
306
+ import { snakeCase } from 'stringzy';
307
+ snakeCase('hello world'); // 'hello_world'
308
+ snakeCase('this is a test'); // 'this_is_a_test'
309
+ ```
310
+
311
+ | Parameter | Type | Default | Description |
312
+ |-----------|------|---------|-------------|
313
+ | text | string | required | The input string to convert to Snake Case |
314
+
315
+
316
+
317
+
318
+ #### <a id="kebabcase"></a>`kebabCase(text)`
319
+
320
+ Converts the given string to Kebab Case.
321
+
322
+ ```javascript
323
+ import { kebabCase } from 'stringzy';
324
+
325
+
326
+ kebabCase('hello world'); // 'hello-world'
327
+ kebabCase('this is a test'); // 'this-is-a-test'
328
+ ```
329
+ | Parameter | Type | Default | Description |
330
+ |-----------|------|---------|-------------|
331
+ | text | string | required | The input string to convert to Kebab Case |
332
+
333
+
334
+
335
+ #### <a id="titlecase"></a>`titleCase(text)`
336
+
337
+ Converts the given string to Title Case.
338
+
339
+ ```javascript
340
+ import { titleCase } from 'stringzy';
341
+
342
+
343
+ titleCase('hello world'); // 'Hello World'
344
+ titleCase('this is a test'); // 'This Is A Test'
345
+ ```
346
+ | Parameter | Type | Default | Description |
347
+ |-----------|------|---------|-------------|
348
+ | text | string | required | The input string to convert to Title Case |
349
+
350
+ #### <a id="constantcase"></a>`constantCase(text)`
351
+ Converts the given string to Constant Case.
352
+
353
+ ```javascript
354
+ import { constantCase } from 'stringzy';
355
+
356
+
357
+ constantCase('hello world'); // 'HELLO_WORLD'
358
+ constantCase('this is a test'); // 'THIS_IS_A_TEST'
359
+
360
+ ```
361
+ | Parameter | Type | Default | Description |
362
+ |-----------|------|---------|-------------|
363
+ | text | string | required | The input string to convert to Constant Case |
364
+
365
+ #### <a id="escapehtml"></a>`escapeHTML(text)`
366
+
367
+ Escapes HTML special characters to prevent XSS attacks by converting them to their HTML entities.
368
+
369
+ ```javascript
370
+ import { escapeHTML } from 'stringzy';
371
+
372
+ escapeHTML('Tom & Jerry');
373
+ // Returns: 'Tom &amp; Jerry'
374
+
375
+ escapeHTML('<script>alert("XSS")</script>');
376
+ // Returns: '&lt;script&gt;alert(&quot;XSS&quot;)&lt;/script&gt;'
377
+
378
+ escapeHTML('<div class="test">content</div>');
379
+ // Returns: '&lt;div class=&quot;test&quot;&gt;content&lt;/div&gt;'
380
+
381
+ escapeHTML('Say "Hello" & it\'s < 5 > 2');
382
+ // Returns: 'Say &quot;Hello&quot; &amp; it&#39;s &lt; 5 &gt; 2'
383
+ ```
384
+
385
+ | Parameter | Type | Default | Description |
386
+ |-----------|------|---------|-------------|
387
+ | text | string | required | The input string to escape HTML characters from |
388
+
389
+ #### <a id="masksegment"></a>`maskSegment(text, maskStart, maskEnd, maskChar?)`
390
+ Masks a segment of a string by replacing characters between two indices with a specified character (default is '*').
391
+
392
+ ```javascript
393
+ import { maskSegment } from 'stringzy';
394
+
395
+ maskSegment('1234567890', 2, 6);
396
+ // Returns: '12****7890'
397
+
398
+ maskSegment('abcdef', 1, 4, '#');
399
+ // Returns: 'a###ef'
400
+
401
+ maskSegment('token');
402
+ // Returns: '*****'
403
+
404
+ ```
405
+ | Parameter | Type | Default| Description |
406
+ |-----------|------|--------|-------------|
407
+ |text | string | required | The input string to apply the masking to|
408
+ |maskStart |number| `0`| The start index (inclusive) of the segment to mask|
409
+ |maskEnd |number| `text.length`| The end index (exclusive) of the segment to mask|
410
+ |maskChar |string |`'*'` | The character to use for masking (must be one character)|
411
+
412
+ #### <a id="deburr"></a>deburr(text)
413
+ Removes accents and diacritics from letters in a string (e.g. déjà vu deja vu).
414
+
415
+ ```javascript
416
+ import { deburr } from 'stringzy';
417
+
418
+ deburr('déjà vu');
419
+ // Returns: 'deja vu'
420
+
421
+ deburr('Élève São Paulo');
422
+ // Returns: 'Eleve Sao Paulo'
423
+
424
+ deburr('über cool');
425
+ // Returns: 'uber cool'
426
+
427
+ ```
428
+ | Parameter | Type | Default | Description |
429
+ | --------- | ------ | -------- | ----------------------------------------- |
430
+ | text | string | required | The input string to strip diacritics from |
431
+
432
+ ---
433
+
434
+ ### ✅ Validations
435
+
436
+ Functions for validating string formats and content.
437
+
438
+ #### <a id="isurl"></a>`isURL(text)`
439
+
440
+ Checks if a string is a valid URL.
441
+
442
+ ```javascript
443
+ isURL('https://example.com'); // true
444
+ isURL('not-a-url'); // false
445
+ ```
446
+
447
+ | Parameter | Type | Default | Description |
448
+ |-----------|------|---------|-------------|
449
+ | text | string | required | The input string to validate as URL |
450
+
451
+ #### <a id="isemail"></a>`isEmail(text)`
452
+
453
+ Checks if a string is a valid email address.
454
+
455
+ ```javascript
456
+ isEmail('user@example.com'); // true
457
+ isEmail('invalid-email'); // false
458
+ ```
459
+
460
+ | Parameter | Type | Default | Description |
461
+ |-----------|------|---------|-------------|
462
+ | text | string | required | The input string to validate as email |
463
+
464
+ #### <a id="isdate"></a>`isDate(text)`
465
+
466
+ Checks if a string is a valid date.
467
+
468
+ ```javascript
469
+ import { isDate } from 'stringzy';
470
+
471
+ isDate('2023-12-25', DateFormat.YYYMMDD); // true
472
+ isDate('12/25/2023', DateFormat.MMDDYYY, '/'); // true
473
+ isDate('20-12-25', DateFormat.YYYMMDD); // false
474
+ isDate('2023-12-1', DateFormat.YYYMMDD); // false
475
+ isDate('invalid-date', DateFormat.YYYMMDD); // false
476
+ isDate('2023-13-45', DateFormat.YYYMMDD); // false
477
+ ```
478
+
479
+ | Parameter | Type | Default | Description |
480
+ |-----------|------|---------|-------------|
481
+ | input | string | required | The input string to validate as date |
482
+ | format | DateFormats | required | The date format to validate against |
483
+ | separator | string | optional | The separator to be used if it is not "-" |
484
+
485
+ #### <a id="isempty"></a>`isEmpty(text)`
486
+
487
+ Checks if a string is empty or contains only whitespace.
488
+
489
+ ```javascript
490
+ isEmpty(' '); // true
491
+ isEmpty('hello'); // false
492
+ ```
493
+
494
+ | Parameter | Type | Default | Description |
495
+ |-----------|------|---------|-------------|
496
+ | text | string | required | The input string to check for emptiness |
497
+
498
+ #### <a id="isslug"></a>`isSlug(text)`
499
+
500
+ Checks if a string is a valid slug.
501
+
502
+ ```javascript
503
+ isSlug("hello-world"); // true
504
+ isSlug("test-product-123"); // true
505
+ isSlug("Hello-World"); // false (uppercase letters)
506
+ isSlug("hello--world"); // false (consecutive hyphens)
507
+ isSlug("-hello-world"); // false (starts with hyphen)
508
+ isSlug("hello_world"); // false (underscore not allowed)
509
+ ```
510
+
511
+ | Parameter | Type | Default | Description |
512
+ |-----------|------|---------|-------------|
513
+ | text | string | required | The input string to validate as slug |
514
+
515
+ #### <a id="isipv4"></a>`isIPv4(text)`
516
+
517
+ Checks if a string is a valid IPv4 address.
518
+
519
+ ```javascript
520
+ import { isIPv4 } from 'stringzy';
521
+
522
+ isIPv4('192.168.1.1'); // true
523
+ isIPv4('0.0.0.0'); // true
524
+ isIPv4('256.1.1.1'); // false (out of range)
525
+ isIPv4('192.168.1'); // false (incomplete)
526
+ isIPv4('192.168.01.1'); // false (leading zeros)
527
+ isIPv4('192.168.1.a'); // false (non-numeric)
528
+ ```
529
+
530
+ | Parameter | Type | Default | Description |
531
+ |-----------|------|---------|-------------|
532
+ | text | string | required | The input string to validate as IPv4 address |
533
+
534
+
535
+ #### <a id="ishexcolor"></a>`isHexColor(text)`
536
+
537
+ Checks if a string is a valid Hex color.
538
+
539
+ ```javascript
540
+ import { isHexColor } from 'stringzy';
541
+
542
+ isHexColor('#fff'); // true
543
+ isHexColor('fff'); // true
544
+ isHexColor('#a1b2c3'); // true
545
+ isHexColor('123abc'); // true
546
+ isHexColor('#1234'); // false
547
+ isHexColor('blue'); // false
548
+ ```
549
+
550
+ | Parameter | Type | Default | Description |
551
+ |-----------|------|---------|-------------|
552
+ | text | string | required | The input string to validate as Hex color |
553
+
554
+ ---
555
+
556
+
557
+ ### 📊 Analysis
558
+
559
+ Functions for analyzing string content and structure.
560
+
561
+ #### <a id="readingduration"></a>`readingDuration(text, readingSpeed = 230)`
562
+
563
+ Calculates the estimated reading duration for a given text based on an average reading speed.
564
+
565
+ ```javascript
566
+ import { readingDuration } from 'stringzy';
567
+
568
+ readingDuration('This is a sample text with twenty-three words to test the reading duration function.');
569
+ // Returns: 0 (23 words / 230 words per minute ≈ 0 minutes)
570
+
571
+ readingDuration('This text contains fifty words. It is designed to test the reading duration function with a larger input.', 200);
572
+ // Returns: 1 (50 words / 200 words per minute ≈ 1 minute)
573
+
574
+ readingDuration(Array(9999).fill('Word').join(' '));
575
+ // Returns: 43 (9999 words / 230 words per minute ≈ 43 minutes)
576
+ ```
577
+
578
+ | Parameter | Type | Default | Description |
579
+ |----------------|----------|---------|-----------------------------------------------------------------------------|
580
+ | text | string | required | The input text for which the reading duration is to be calculated |
581
+ | readingSpeed | number | 230 | The reading speed in words per minute. Defaults to 230 (average reading speed) |
582
+
583
+
584
+ #### <a id="wordcount"></a>`wordCount(text)`
585
+
586
+ Counts the number of words in a string.
587
+
588
+ ```javascript
589
+ wordCount('Hello world'); // 2
590
+ wordCount(''); // 0
591
+ ```
592
+
593
+ | Parameter | Type | Default | Description |
594
+ |-----------|------|---------|-------------|
595
+ | text | string | required | The input string to count words in |
596
+
597
+ #### <a id="charactercount"></a>`characterCount(text)`
598
+
599
+ Counts the number of characters in a string.
600
+
601
+ ```javascript
602
+ characterCount('Hello'); // 5
603
+ ```
604
+
605
+ | Parameter | Type | Default | Description |
606
+ |-----------|------|---------|-------------|
607
+ | text | string | required | The input string to count characters in |
608
+
609
+ #### <a id="characterfrequency"></a>`characterFrequency(text)`
610
+
611
+ Analyzes character frequency in a string (excluding spaces).
612
+
613
+ ```javascript
614
+ characterFrequency('hello'); // { h: 1, e: 1, l: 2, o: 1 }
615
+ ```
616
+
617
+ | Parameter | Type | Default | Description |
618
+ |-----------|------|---------|-------------|
619
+ | text | string | required | The input string to analyze character frequency |
620
+
621
+ #### <a id="stringsimilarity"></a>`stringSimilarity(textA, textB, algorithm = 'Levenshtein')`
622
+
623
+ Calculates the percentage similarity between two texts using the selected algorithm.
624
+ Method returns a percentage (0–100) value indicating how similar the two strings are.
625
+ ```javascript
626
+ stringSimilarity('kitten', 'sitting'); // Returns: 57.14
627
+
628
+ stringSimilarity('hello', 'hello'); // Returns: 100
629
+
630
+ stringSimilarity('flaw', 'lawn', 'Damerau-Levenshtein'); // Returns: 50
631
+ ```
632
+
633
+ | Parameter | Type | Default | Description |
634
+ |------------|--------|----------------------|-----------------------------------------------------------------------------|
635
+ | textA | string | required | The first text to compare. |
636
+ | textB | string | required | The second text to compare. |
637
+ | algorithm | string | 'Levenshtein' | The algorithm to use: 'Levenshtein' or 'Damerau-Levenshtein'. |
638
+
639
+ ---
640
+
641
+ ### 🎨 Formatting
642
+
643
+ Functions for formatting strings into specific patterns.
644
+
645
+ #### <a id="capitalize"></a>`capitalize(text)`
646
+
647
+ Capitalizes the first letter of each word.
648
+
649
+ ```javascript
650
+ capitalize('hello world'); // 'Hello World'
651
+ capitalize('javaScript programming'); // 'Javascript Programming'
652
+ ```
653
+
654
+ | Parameter | Type | Default | Description |
655
+ |-----------|------|---------|-------------|
656
+ | text | string | required | The input string to capitalize |
657
+
658
+ #### <a id="formatnumber"></a>`formatNumber(number, separator = ',')`
659
+
660
+ Formats a number string with thousand separators.
661
+
662
+ ```javascript
663
+ formatNumber('1234567'); // '1,234,567'
664
+ formatNumber('1234567', '.'); // '1.234.567'
665
+ ```
666
+
667
+ | Parameter | Type | Default | Description |
668
+ |-----------|------|---------|-------------|
669
+ | number | string\|number | required | The number to format |
670
+ | separator | string | ',' | The separator to use for thousands |
671
+
672
+ #### <a id="formatphone"></a>`formatPhone(phone, format = 'us')`
673
+
674
+ Formats a phone number string to standard format.
675
+
676
+ ```javascript
677
+ formatPhone('1234567890'); // '(123) 456-7890'
678
+ formatPhone('11234567890', 'international'); // '+1 (123) 456-7890'
679
+ ```
680
+
681
+ | Parameter | Type | Default | Description |
682
+ |-----------|------|---------|-------------|
683
+ | phone | string | required | The phone number string to format |
684
+ | format | string | 'us' | Format type: 'us' or 'international' |
685
+
686
+ ## 🔧 Usage Patterns
687
+
688
+ ### Individual Function Imports
689
+ ```javascript
690
+ import { isEmail, wordCount, capitalize } from 'stringzy';
691
+
692
+ const email = 'user@example.com';
693
+ if (isEmail(email)) {
694
+ console.log('Valid email!');
695
+ }
696
+ ```
697
+
698
+ ### Namespace Imports
699
+ ```javascript
700
+ import { validate, analyze, format } from 'stringzy';
701
+
702
+ // Organized by functionality
703
+ const emailValid = validate.isEmail('test@example.com');
704
+ const words = analyze.wordCount('Hello world');
705
+ const formatted = format.capitalize('hello world');
706
+ ```
707
+
708
+ ### Default Import (All Functions)
709
+ ```javascript
710
+ import stringzy from 'stringzy';
711
+
712
+ // Access any function
713
+ stringzy.toUpperCase('hello');
714
+ stringzy.validate.isEmail('test@example.com');
715
+ stringzy.analyze.wordCount('Hello world');
716
+ stringzy.format.capitalize('hello world');
717
+ ```
718
+
719
+ ## 🛠️ Usage Examples
720
+
721
+ ### In a React component
722
+
723
+ ```jsx
724
+ import React from 'react';
725
+ import { truncateText, capitalize, wordCount, isEmpty } from 'stringzy';
726
+
727
+ function ArticlePreview({ title, content }) {
728
+ const displayTitle = isEmpty(title) ? 'Untitled' : capitalize(title);
729
+ const previewText = truncateText(content, 150);
730
+ const readingTime = Math.ceil(wordCount(content) / 200);
731
+
732
+ return (
733
+ <div className="article-preview">
734
+ <h2>{displayTitle}</h2>
735
+ <p>{previewText}</p>
736
+ <small>{readingTime} min read</small>
737
+ </div>
738
+ );
739
+ }
740
+ ```
741
+
742
+ ### Form Validation
743
+
744
+ ```javascript
745
+ import { validate } from 'stringzy';
746
+
747
+ function validateForm(formData) {
748
+ const errors = {};
749
+
750
+ if (!validate.isEmail(formData.email)) {
751
+ errors.email = 'Please enter a valid email address';
752
+ }
753
+
754
+ if (!validate.isURL(formData.website)) {
755
+ errors.website = 'Please enter a valid URL';
756
+ }
757
+
758
+ if (validate.isEmpty(formData.name)) {
759
+ errors.name = 'Name is required';
760
+ }
761
+
762
+ return errors;
763
+ }
764
+ ```
765
+
766
+ ### Content Analysis Dashboard
767
+
768
+ ```javascript
769
+ import { analyze } from 'stringzy';
770
+
771
+ function getContentStats(text) {
772
+ return {
773
+ words: analyze.wordCount(text),
774
+ characters: analyze.characterCount(text),
775
+ frequency: analyze.characterFrequency(text),
776
+ readingTime: Math.ceil(analyze.wordCount(text) / 200)
777
+ };
778
+ }
779
+ ```
780
+
781
+ ### Data Formatting
782
+
783
+ ```javascript
784
+ import { format } from 'stringzy';
785
+
786
+ function formatUserData(userData) {
787
+ return {
788
+ name: format.capitalize(userData.name),
789
+ phone: format.formatPhone(userData.phone),
790
+ revenue: format.formatNumber(userData.revenue)
791
+ };
792
+ }
793
+ ```
794
+
795
+ ## 🔄 TypeScript Support
796
+
797
+ The package includes TypeScript type definitions for all functions.
798
+
799
+ ```typescript
800
+ import { validate, analyze, format } from 'stringzy';
801
+
802
+ // TypeScript will provide proper type checking
803
+ const isValid: boolean = validate.isEmail('test@example.com');
804
+ const count: number = analyze.wordCount('Hello world');
805
+ const formatted: string = format.capitalize('hello world');
806
+ ```
807
+
808
+ ## 🏗️ Architecture
809
+
810
+ stringzy is organized into four specialized modules:
811
+
812
+ - **`transformations.js`** - Core string transformations
813
+ - **`validations.js`** - String validation utilities
814
+ - **`analysis.js`** - String analysis and metrics
815
+ - **`formatting.js`** - String formatting functions
816
+
817
+ Each module can be imported individually or accessed through the main entry point.
818
+
819
+ ## 🤝 Contributing
820
+
821
+ Contributions are welcome! Please read our [contribution guidelines](CONTRIBUTING.md) before submitting a pull request.
822
+
823
+
824
+ ## <a id="contri"></a>`Contributors`
825
+
826
+ <table>
827
+ <tbody>
828
+ <tr>
829
+ <td align="center">
830
+ <a href="https://github.com/Samarth2190">
831
+ <img src="https://avatars.githubusercontent.com/Samarth2190" width="100px;"
832
+ alt="Samarth Ruia" />
833
+ <br />
834
+ <sub>
835
+ <b>Samarth Ruia</b>
836
+ </sub>
837
+ </a>
838
+ </td>
839
+ <td align="center">
840
+ <a href="https://github.com/JohnCervantes">
841
+ <img src="https://avatars.githubusercontent.com/JohnCervantes" width="100px;"
842
+ alt="John Cervantes" />
843
+ <br />
844
+ <sub>
845
+ <b>John Cervantes</b>
846
+ </sub>
847
+ </a>
848
+ </td>
849
+ <td align="center">
850
+ <a href="https://github.com/thehardiik">
851
+ <img src="https://avatars.githubusercontent.com/thehardiik" width="100px;"
852
+ alt="Hardik Srivastav" />
853
+ <br />
854
+ <sub>
855
+ <b>Hardik Srivastav</b>
856
+ </sub>
857
+ </a>
858
+ </td>
859
+ <td align="center">
860
+ <a href="https://github.com/ahmedsemih">
861
+ <img src="https://avatars.githubusercontent.com/ahmedsemih" width="100px;"
862
+ alt="Ahmed Semih Erkan" />
863
+ <br />
864
+ <sub>
865
+ <b>Ahmed Semih Erkan</b>
866
+ </sub>
867
+ </a>
868
+ </td>
869
+ <td align="center">
870
+ <a href="https://github.com/michaelvbend">
871
+ <img src="https://avatars.githubusercontent.com/michaelvbend" width="100px;"
872
+ alt="Michael van der Bend" />
873
+ <br />
874
+ <sub>
875
+ <b>Michael van der Bend</b>
876
+ </sub>
877
+ </a>
878
+ </td>
879
+ <td align="center">
880
+ <a href="https://github.com/mamphis">
881
+ <img src="https://avatars.githubusercontent.com/mamphis" width="100px;"
882
+ alt="mamphis" />
883
+ <br />
884
+ <sub>
885
+ <b>mamphis</b>
886
+ </sub>
887
+ </a>
888
+ </td>
889
+ </tr>
890
+ <tr>
891
+ <td align="center">
892
+ <a href="https://github.com/cokolwiekpl">
893
+ <img src="https://avatars.githubusercontent.com/cokolwiekpl" width="100px;"
894
+ alt="Stanisław Kumor" />
895
+ <br />
896
+ <sub>
897
+ <b>Stanisław Kumor</b>
898
+ </sub>
899
+ </a>
900
+ </td>
901
+ <td align="center">
902
+ <a href="https://github.com/Alimedhat000">
903
+ <img src="https://avatars.githubusercontent.com/Alimedhat000" width="100px;"
904
+ alt="Ali Medhat" />
905
+ <br />
906
+ <sub>
907
+ <b>Ali Medhat</b>
908
+ </sub>
909
+ </a>
910
+ </td>
911
+ <td align="center">
912
+ <a href="https://github.com/Soham-Powar">
913
+ <img src="https://avatars.githubusercontent.com/Soham-Powar" width="100px;"
914
+ alt="Soham Powar" />
915
+ <br />
916
+ <sub>
917
+ <b>Soham Powar</b>
918
+ </sub>
919
+ </a>
920
+ </td>
921
+ <td align="center">
922
+ <a href="https://github.com/a-arham-x">
923
+ <img src="https://avatars.githubusercontent.com/a-arham-x" width="100px;"
924
+ alt="Soham Powar" />
925
+ <br />
926
+ <sub>
927
+ <b>Abdul Arham</b>
928
+ </sub>
929
+ </a>
930
+ </td>
931
+ </tr>
932
+ </tbody>
933
+ </table>
934
+
935
+ ## <a id="community"></a>💬 Join the Community
936
+
937
+ Have questions, ideas, or want to contribute? Join our [Discord server](https://discord.gg/DmvY7XJMdk) to chat with the community, discuss features, and help shape the future of the project.
938
+
939
+ ## 📝 License
940
+
941
+ This project is licensed under the MIT License - see the LICENSE file for details.
942
+
943
+ ## 🙏 Acknowledgments
944
+
945
+ - Thank you to all contributors and users of this package!
946
+ - Inspired by the need for comprehensive yet simple string manipulation utilities.
947
+
948
+ If you have contributed to this project and your image is not here, please let us know, and we'll be happy to add it!
949
+
950
+ ---
951
+
952
+ Made with ❤️ by Samarth Ruia