stringzy 2.2.0 → 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.
- package/.github/workflows/publish.yml +29 -0
- package/.github/workflows/test-on-pr.yml +23 -0
- package/CONTRIBUTING.md +87 -0
- package/LICENSE +21 -21
- package/README.md +952 -723
- package/changelog.txt +110 -102
- package/dist/analyzing/characterCount.d.ts +1 -0
- package/dist/analyzing/characterCount.js +9 -0
- package/dist/analyzing/characterFrequency.d.ts +1 -0
- package/dist/analyzing/characterFrequency.js +16 -0
- package/dist/analyzing/complexity.d.ts +6 -0
- package/dist/analyzing/complexity.js +30 -0
- package/dist/analyzing/index.d.ts +20 -0
- package/dist/analyzing/index.js +29 -0
- package/dist/analyzing/readingDuration.d.ts +10 -0
- package/dist/analyzing/readingDuration.js +17 -0
- package/dist/analyzing/stringSimilarity.d.ts +8 -0
- package/dist/analyzing/stringSimilarity.js +145 -0
- package/dist/analyzing/wordCount.d.ts +1 -0
- package/dist/analyzing/wordCount.js +11 -0
- package/dist/formatting/capitalize.d.ts +1 -0
- package/dist/formatting/capitalize.js +12 -0
- package/dist/formatting/index.d.ts +11 -0
- package/dist/formatting/index.js +17 -0
- package/dist/formatting/number.d.ts +1 -0
- package/dist/formatting/number.js +7 -0
- package/dist/formatting/phone.d.ts +2 -0
- package/dist/formatting/phone.js +25 -0
- package/dist/index.d.ts +47 -0
- package/dist/index.js +30 -0
- package/dist/tests/analyzing/characterCount.test.d.ts +1 -0
- package/dist/tests/analyzing/characterCount.test.js +19 -0
- package/dist/tests/analyzing/characterFrequency.test.d.ts +1 -0
- package/dist/tests/analyzing/characterFrequency.test.js +22 -0
- package/dist/tests/analyzing/complexity.test.d.ts +1 -0
- package/dist/tests/analyzing/complexity.test.js +28 -0
- package/dist/tests/analyzing/readingDuration.test.d.ts +1 -0
- package/dist/tests/analyzing/readingDuration.test.js +45 -0
- package/dist/tests/analyzing/stringSimilarity.test.d.ts +1 -0
- package/dist/tests/analyzing/stringSimilarity.test.js +61 -0
- package/dist/tests/analyzing/wordCount.test.d.ts +1 -0
- package/dist/tests/analyzing/wordCount.test.js +22 -0
- package/dist/tests/formatting/capitalize.test.d.ts +1 -0
- package/dist/tests/formatting/capitalize.test.js +22 -0
- package/dist/tests/formatting/number.test.d.ts +1 -0
- package/dist/tests/formatting/number.test.js +19 -0
- package/dist/tests/formatting/phone.test.d.ts +1 -0
- package/dist/tests/formatting/phone.test.js +25 -0
- package/dist/tests/transformations/camelCase.test.d.ts +1 -0
- package/dist/tests/transformations/camelCase.test.js +19 -0
- package/dist/tests/transformations/capitalizeWords.test.d.ts +1 -0
- package/dist/tests/transformations/capitalizeWords.test.js +19 -0
- package/dist/tests/transformations/constantCase.test.d.ts +1 -0
- package/dist/tests/transformations/constantCase.test.js +19 -0
- package/dist/tests/transformations/deburr.test.d.ts +1 -0
- package/dist/tests/transformations/deburr.test.js +27 -0
- package/dist/tests/transformations/escapeHTML.test.d.ts +1 -0
- package/dist/tests/transformations/escapeHTML.test.js +46 -0
- package/dist/tests/transformations/initials.test.d.ts +1 -0
- package/dist/tests/transformations/initials.test.js +25 -0
- package/dist/tests/transformations/kebabCase.test.d.ts +1 -0
- package/dist/tests/transformations/kebabCase.test.js +19 -0
- package/dist/tests/transformations/maskSegment.test.d.ts +1 -0
- package/dist/tests/transformations/maskSegment.test.js +30 -0
- package/dist/tests/transformations/pascalCase.test.d.ts +1 -0
- package/dist/tests/transformations/pascalCase.test.js +19 -0
- package/dist/tests/transformations/removeDuplicates.test.d.ts +1 -0
- package/dist/tests/transformations/removeDuplicates.test.js +19 -0
- package/dist/tests/transformations/removeSpecialChars.test.d.ts +1 -0
- package/dist/tests/transformations/removeSpecialChars.test.js +22 -0
- package/dist/tests/transformations/removeWords.test.d.ts +1 -0
- package/dist/tests/transformations/removeWords.test.js +25 -0
- package/dist/tests/transformations/snakeCase.test.d.ts +1 -0
- package/dist/tests/transformations/snakeCase.test.js +19 -0
- package/dist/tests/transformations/titleCase.test.d.ts +1 -0
- package/dist/tests/transformations/titleCase.test.js +19 -0
- package/dist/tests/transformations/toSlug.test.d.ts +1 -0
- package/dist/tests/transformations/toSlug.test.js +22 -0
- package/dist/tests/transformations/truncateText.test.d.ts +1 -0
- package/dist/tests/transformations/truncateText.test.js +31 -0
- package/dist/tests/validations/isDate.test.d.ts +1 -0
- package/dist/tests/validations/isDate.test.js +55 -0
- package/dist/tests/validations/isEmail.test.d.ts +1 -0
- package/dist/tests/validations/isEmail.test.js +17 -0
- package/dist/tests/validations/isEmpty.test.d.ts +1 -0
- package/dist/tests/validations/isEmpty.test.js +19 -0
- package/dist/tests/validations/isHexColor.test.d.ts +1 -0
- package/dist/tests/validations/isHexColor.test.js +32 -0
- package/dist/tests/validations/isIPv4.test.d.ts +1 -0
- package/dist/tests/validations/isIPv4.test.js +59 -0
- package/dist/tests/validations/isSlug.test.d.ts +1 -0
- package/dist/tests/validations/isSlug.test.js +22 -0
- package/dist/tests/validations/isURL.test.d.ts +1 -0
- package/dist/tests/validations/isURL.test.js +18 -0
- package/dist/transformations/camelCase.d.ts +1 -0
- package/dist/transformations/camelCase.js +15 -0
- package/dist/transformations/capitalizeWords.d.ts +1 -0
- package/dist/transformations/capitalizeWords.js +9 -0
- package/dist/transformations/constantCase.d.ts +1 -0
- package/dist/transformations/constantCase.js +15 -0
- package/dist/transformations/deburr.d.ts +7 -0
- package/dist/transformations/deburr.js +16 -0
- package/dist/transformations/escapeHTML.d.ts +1 -0
- package/dist/transformations/escapeHTML.js +14 -0
- package/dist/transformations/index.d.ts +49 -0
- package/dist/transformations/index.js +67 -0
- package/dist/transformations/initials.d.ts +1 -0
- package/dist/transformations/initials.js +19 -0
- package/dist/transformations/kebabCase.d.ts +1 -0
- package/dist/transformations/kebabCase.js +15 -0
- package/dist/transformations/maskSegment.d.ts +9 -0
- package/dist/transformations/maskSegment.js +25 -0
- package/dist/transformations/pascalCase.d.ts +1 -0
- package/dist/transformations/pascalCase.js +15 -0
- package/dist/transformations/removeDuplicates.d.ts +1 -0
- package/dist/transformations/removeDuplicates.js +13 -0
- package/dist/transformations/removeSpecialChars.d.ts +1 -0
- package/dist/transformations/removeSpecialChars.js +12 -0
- package/dist/transformations/removeWords.d.ts +1 -0
- package/dist/transformations/removeWords.js +23 -0
- package/dist/transformations/snakeCase.d.ts +1 -0
- package/dist/transformations/snakeCase.js +15 -0
- package/dist/transformations/titleCase.d.ts +1 -0
- package/dist/transformations/titleCase.js +14 -0
- package/dist/transformations/toSlug.d.ts +1 -0
- package/dist/transformations/toSlug.js +13 -0
- package/dist/transformations/truncateText.d.ts +1 -0
- package/dist/transformations/truncateText.js +19 -0
- package/dist/validations/index.d.ts +23 -0
- package/dist/validations/index.js +33 -0
- package/dist/validations/isDate.d.ts +18 -0
- package/dist/validations/isDate.js +63 -0
- package/dist/validations/isEmail.d.ts +1 -0
- package/dist/validations/isEmail.js +7 -0
- package/dist/validations/isEmpty.d.ts +1 -0
- package/dist/validations/isEmpty.js +6 -0
- package/dist/validations/isHexColor.d.ts +7 -0
- package/dist/validations/isHexColor.js +15 -0
- package/dist/validations/isIPv4.d.ts +1 -0
- package/dist/validations/isIPv4.js +13 -0
- package/dist/validations/isSlug.d.ts +1 -0
- package/dist/validations/isSlug.js +10 -0
- package/dist/validations/isURL.d.ts +1 -0
- package/dist/validations/isURL.js +12 -0
- package/package.json +10 -4
- package/analysis.js +0 -21
- package/assets/stringzy-banner2.jpg +0 -0
- package/formatting.js +0 -37
- package/index.js +0 -75
- package/transformations.js +0 -190
- package/validations.js +0 -80
package/README.md
CHANGED
|
@@ -1,723 +1,952 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-

|
|
5
|
+
|
|
6
|
+
|
|
7
|
+

|
|
8
|
+

|
|
9
|
+

|
|
10
|
+

|
|
11
|
+
[](https://github.com/ellerbrock/open-source-badges/)
|
|
12
|
+
[](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 & Jerry'
|
|
374
|
+
|
|
375
|
+
escapeHTML('<script>alert("XSS")</script>');
|
|
376
|
+
// Returns: '<script>alert("XSS")</script>'
|
|
377
|
+
|
|
378
|
+
escapeHTML('<div class="test">content</div>');
|
|
379
|
+
// Returns: '<div class="test">content</div>'
|
|
380
|
+
|
|
381
|
+
escapeHTML('Say "Hello" & it\'s < 5 > 2');
|
|
382
|
+
// Returns: 'Say "Hello" & it's < 5 > 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
|