stringzy 3.0.0 → 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.prettierignore +4 -0
- package/.prettierrc +7 -0
- package/CONTRIBUTING.md +41 -29
- package/README.md +811 -163
- package/dist/analyzing/characterCount.d.ts +19 -0
- package/dist/analyzing/characterCount.js +21 -2
- package/dist/analyzing/characterFrequency.d.ts +19 -0
- package/dist/analyzing/characterFrequency.js +22 -3
- package/dist/analyzing/checkMultiplePatterns.d.ts +14 -0
- package/dist/analyzing/checkMultiplePatterns.js +63 -0
- package/dist/analyzing/checkSubsequence.d.ts +14 -0
- package/dist/analyzing/checkSubsequence.js +33 -0
- package/dist/analyzing/complexity.d.ts +33 -0
- package/dist/analyzing/complexity.js +35 -2
- package/dist/analyzing/contentWordCount.d.ts +11 -0
- package/dist/analyzing/contentWordCount.js +23 -0
- package/dist/analyzing/functionWordCount.d.ts +11 -0
- package/dist/analyzing/functionWordCount.js +33 -0
- package/dist/analyzing/index.d.ts +29 -12
- package/dist/analyzing/index.js +26 -2
- package/dist/analyzing/patternCount.d.ts +11 -0
- package/dist/analyzing/patternCount.js +54 -0
- package/dist/analyzing/stringRotation.d.ts +29 -0
- package/dist/analyzing/stringRotation.js +44 -0
- package/dist/analyzing/stringSimilarity.js +1 -1
- package/dist/analyzing/vowelConsonantCount.d.ts +22 -0
- package/dist/analyzing/vowelConsonantCount.js +38 -0
- package/dist/analyzing/wordCount.d.ts +22 -0
- package/dist/analyzing/wordCount.js +24 -2
- package/dist/formatting/capitalize.d.ts +21 -0
- package/dist/formatting/capitalize.js +22 -1
- package/dist/formatting/index.d.ts +6 -6
- package/dist/formatting/number.d.ts +23 -0
- package/dist/formatting/number.js +24 -1
- package/dist/formatting/phone.d.ts +23 -0
- package/dist/formatting/phone.js +23 -0
- package/dist/index.d.ts +22 -4
- package/dist/tests/analyzing/checkMultiplePatterns.test.d.ts +1 -0
- package/dist/tests/analyzing/checkMultiplePatterns.test.js +81 -0
- package/dist/tests/analyzing/checkSubsequence.test.d.ts +1 -0
- package/dist/tests/analyzing/checkSubsequence.test.js +34 -0
- package/dist/tests/analyzing/contentWordCount.test.d.ts +1 -0
- package/dist/tests/analyzing/contentWordCount.test.js +20 -0
- package/dist/tests/analyzing/functionWordCount.test.d.ts +1 -0
- package/dist/tests/analyzing/functionWordCount.test.js +20 -0
- package/dist/tests/analyzing/patternCount.test.d.ts +1 -0
- package/dist/tests/analyzing/patternCount.test.js +34 -0
- package/dist/tests/analyzing/readingDuration.test.js +12 -12
- package/dist/tests/analyzing/stringRotation.test.d.ts +1 -0
- package/dist/tests/analyzing/stringRotation.test.js +42 -0
- package/dist/tests/analyzing/vowelConsonantCount.test.d.ts +1 -0
- package/dist/tests/analyzing/vowelConsonantCount.test.js +25 -0
- package/dist/tests/transformations/numberToText.test.d.ts +1 -0
- package/dist/tests/transformations/numberToText.test.js +60 -0
- package/dist/tests/transformations/reverseString.test.d.ts +1 -0
- package/dist/tests/transformations/reverseString.test.js +41 -0
- package/dist/tests/transformations/splitChunks.test.d.ts +1 -0
- package/dist/tests/transformations/splitChunks.test.js +31 -0
- package/dist/tests/transformations/stringCombinations.test.d.ts +1 -0
- package/dist/tests/transformations/stringCombinations.test.js +41 -0
- package/dist/tests/transformations/stringPermutations.test.d.ts +1 -0
- package/dist/tests/transformations/stringPermutations.test.js +40 -0
- package/dist/tests/validations/isAlphaNumeric.test.d.ts +1 -0
- package/dist/tests/validations/isAlphaNumeric.test.js +30 -0
- package/dist/tests/validations/isAlphabetic.test.d.ts +1 -0
- package/dist/tests/validations/isAlphabetic.test.js +32 -0
- package/dist/tests/validations/isAnagram.test.d.ts +1 -0
- package/dist/tests/validations/isAnagram.test.js +44 -0
- package/dist/tests/validations/isCoordinates.test.d.ts +1 -0
- package/dist/tests/validations/isCoordinates.test.js +18 -0
- package/dist/tests/validations/isEmail.smtpUTF8.test.d.ts +1 -0
- package/dist/tests/validations/isEmail.smtpUTF8.test.js +16 -0
- package/dist/tests/validations/isEmail.test.js +56 -6
- package/dist/tests/validations/isHexColor.test.js +21 -21
- package/dist/tests/validations/isLowerCase.test.d.ts +1 -0
- package/dist/tests/validations/isLowerCase.test.js +50 -0
- package/dist/tests/validations/isMacAddress.test.d.ts +1 -0
- package/dist/tests/validations/isMacAddress.test.js +72 -0
- package/dist/tests/validations/isPalindrome.test.d.ts +1 -0
- package/dist/tests/validations/isPalindrome.test.js +39 -0
- package/dist/tests/validations/isPanagram.test.d.ts +1 -0
- package/dist/tests/validations/isPanagram.test.js +39 -0
- package/dist/tests/validations/isTypeOf.test.d.ts +1 -0
- package/dist/tests/validations/isTypeOf.test.js +28 -0
- package/dist/tests/validations/isUpperCase.test.d.ts +1 -0
- package/dist/tests/validations/isUpperCase.test.js +50 -0
- package/dist/transformations/camelCase.d.ts +24 -0
- package/dist/transformations/camelCase.js +24 -0
- package/dist/transformations/capitalizeWords.d.ts +21 -0
- package/dist/transformations/capitalizeWords.js +23 -2
- package/dist/transformations/constantCase.d.ts +26 -0
- package/dist/transformations/constantCase.js +26 -0
- package/dist/transformations/escapeHTML.d.ts +23 -0
- package/dist/transformations/escapeHTML.js +24 -2
- package/dist/transformations/index.d.ts +12 -0
- package/dist/transformations/index.js +18 -2
- package/dist/transformations/initials.d.ts +27 -0
- package/dist/transformations/initials.js +38 -8
- package/dist/transformations/kebabCase.d.ts +26 -0
- package/dist/transformations/kebabCase.js +26 -0
- package/dist/transformations/maskSegment.js +4 -6
- package/dist/transformations/numberToText/helpers.d.ts +10 -0
- package/dist/transformations/numberToText/helpers.js +31 -0
- package/dist/transformations/numberToText/implementation_EN.d.ts +10 -0
- package/dist/transformations/numberToText/implementation_EN.js +45 -0
- package/dist/transformations/numberToText/implementation_PL.d.ts +10 -0
- package/dist/transformations/numberToText/implementation_PL.js +79 -0
- package/dist/transformations/numberToText/main.d.ts +19 -0
- package/dist/transformations/numberToText/main.js +67 -0
- package/dist/transformations/numberToText/types.d.ts +3 -0
- package/dist/transformations/numberToText/types.js +82 -0
- package/dist/transformations/pascalCase.d.ts +25 -0
- package/dist/transformations/pascalCase.js +25 -0
- package/dist/transformations/removeDuplicates.d.ts +21 -0
- package/dist/transformations/removeDuplicates.js +25 -4
- package/dist/transformations/removeSpecialChars.d.ts +22 -0
- package/dist/transformations/removeSpecialChars.js +26 -4
- package/dist/transformations/removeWords.d.ts +27 -0
- package/dist/transformations/removeWords.js +31 -4
- package/dist/transformations/reverseWordsInString .d.ts +9 -0
- package/dist/transformations/reverseWordsInString .js +49 -0
- package/dist/transformations/snakeCase.d.ts +26 -0
- package/dist/transformations/snakeCase.js +26 -0
- package/dist/transformations/splitChunks.d.ts +8 -0
- package/dist/transformations/splitChunks.js +24 -0
- package/dist/transformations/stringCombinations.d.ts +28 -0
- package/dist/transformations/stringCombinations.js +44 -0
- package/dist/transformations/stringPermutations.d.ts +31 -0
- package/dist/transformations/stringPermutations.js +53 -0
- package/dist/transformations/titleCase.d.ts +25 -0
- package/dist/transformations/titleCase.js +25 -0
- package/dist/transformations/toSlug.d.ts +24 -0
- package/dist/transformations/toSlug.js +28 -4
- package/dist/transformations/truncateText.d.ts +25 -0
- package/dist/transformations/truncateText.js +28 -3
- package/dist/validations/index.d.ts +27 -0
- package/dist/validations/index.js +38 -2
- package/dist/validations/isAlphaNumeric.d.ts +11 -0
- package/dist/validations/isAlphaNumeric.js +22 -0
- package/dist/validations/isAlphabetic.d.ts +9 -0
- package/dist/validations/isAlphabetic.js +21 -0
- package/dist/validations/isAnagram.d.ts +13 -0
- package/dist/validations/isAnagram.js +23 -0
- package/dist/validations/isCoordinates.d.ts +8 -0
- package/dist/validations/isCoordinates.js +19 -0
- package/dist/validations/isDate.d.ts +1 -1
- package/dist/validations/isDate.js +6 -8
- package/dist/validations/isEmail.d.ts +13 -1
- package/dist/validations/isEmail.js +176 -3
- package/dist/validations/isEmpty.d.ts +9 -0
- package/dist/validations/isEmpty.js +9 -0
- package/dist/validations/isHexColor.js +1 -1
- package/dist/validations/isIPv4.d.ts +21 -0
- package/dist/validations/isIPv4.js +22 -2
- package/dist/validations/isLowerCase.d.ts +12 -0
- package/dist/validations/isLowerCase.js +32 -0
- package/dist/validations/isMacAddress.d.ts +27 -0
- package/dist/validations/isMacAddress.js +43 -0
- package/dist/validations/isPalindrome.d.ts +10 -0
- package/dist/validations/isPalindrome.js +21 -0
- package/dist/validations/isPanagram.d.ts +20 -0
- package/dist/validations/isPanagram.js +35 -0
- package/dist/validations/isSlug.d.ts +27 -0
- package/dist/validations/isSlug.js +27 -0
- package/dist/validations/isTypeOf.d.ts +9 -0
- package/dist/validations/isTypeOf.js +30 -0
- package/dist/validations/isURL.d.ts +21 -0
- package/dist/validations/isURL.js +21 -0
- package/dist/validations/isUpperCase.d.ts +12 -0
- package/dist/validations/isUpperCase.js +32 -0
- package/package.json +6 -4
package/README.md
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
<div align="center">
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-

|
|
5
2
|
|
|
3
|
+

|
|
6
4
|
|
|
7
5
|

|
|
6
|
+

|
|
8
7
|

|
|
9
8
|

|
|
10
|
-

|
|
11
9
|
[](https://github.com/ellerbrock/open-source-badges/)
|
|
12
10
|
[](http://makeapullrequest.com)
|
|
13
11
|
|
|
@@ -15,15 +13,10 @@
|
|
|
15
13
|
|
|
16
14
|
[Checkout our Contributors!](#contri)
|
|
17
15
|
|
|
18
|
-
|
|
19
16
|
[Join the Community!](#community)
|
|
20
17
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
18
|
</div>
|
|
25
19
|
|
|
26
|
-
|
|
27
20
|
## ✨ Features
|
|
28
21
|
|
|
29
22
|
- 💪 **Powerful** - Transform, validate, analyze, and format strings with minimal code
|
|
@@ -66,7 +59,8 @@ const count = stringzy.analyze.wordCount('Hello world'); // 2
|
|
|
66
59
|
|
|
67
60
|
## 📋 Table of Contents
|
|
68
61
|
|
|
69
|
-
###
|
|
62
|
+
### Transformations
|
|
63
|
+
|
|
70
64
|
- [truncateText](#truncatetext) - Truncates text to a specified maximum length
|
|
71
65
|
- [toSlug](#toslug) - Converts a string to a URL-friendly slug
|
|
72
66
|
- [capitalizeWords](#capitalizewords) - Capitalizes the first letter of each word
|
|
@@ -76,31 +70,56 @@ const count = stringzy.analyze.wordCount('Hello world'); // 2
|
|
|
76
70
|
- [initials](#initials) - Extracts initials from a text string
|
|
77
71
|
- [camelCase](#camelcase) - Converts the given string to Camel Case
|
|
78
72
|
- [pascalCase](#pascalcase) - Converts the given string to Pascal Case
|
|
79
|
-
- [snakeCase](#snakecase) - Converts the given string to Snake Case
|
|
73
|
+
- [snakeCase](#snakecase) - Converts the given string to Snake Case
|
|
80
74
|
- [kebabCase](#kebabcase) - Converts the given string to Kebab Case
|
|
81
75
|
- [titleCase](#titlecase) - Converts the given string to Title Case
|
|
82
76
|
- [constantCase](#constantcase) - Converts the given string to Constant Case
|
|
83
77
|
- [escapeHTML](#escapehtml) - Escapes HTML special characters to prevent XSS attacks
|
|
84
78
|
- [maskSegment](#masksegment) - Masks a segment of a string by replacing characters between two indices with a specified character
|
|
85
79
|
- [deburr](#deburr) – Removes accents and diacritical marks from a string
|
|
80
|
+
- [splitChunks](#splitchunks) - Breaks a string down into chunks of specified length.
|
|
81
|
+
- [numberToText](#numbertotext) - Converts a number to its text representation in specified language
|
|
82
|
+
- [reverseWordsInString](#reversewordsinstring) - Reverses the order of words in a given string
|
|
83
|
+
- [stringPermutations](#stringpermutations) - Generates all unique permutations of a given string.
|
|
84
|
+
- [stringCombinations](#stringcombinations) - Generates all unique combinations of a given string.
|
|
86
85
|
|
|
86
|
+
### Validations
|
|
87
87
|
|
|
88
|
-
### Validations
|
|
89
88
|
- [isURL](#isurl) - Checks if a string is a valid URL
|
|
90
89
|
- [isEmail](#isemail) - Checks if a string is a valid email address
|
|
91
90
|
- [isDate](#isdate) - Checks if a string is a valid date
|
|
92
91
|
- [isEmpty](#isempty) - Checks if a string is empty or contains only whitespace
|
|
93
92
|
- [isSlug](#isslug) - Checks if a string is a valid slug
|
|
93
|
+
- [isTypeOf](#istypeof) - Checks if a file or URL has a valid extension for a given type
|
|
94
94
|
- [isIPv4](#isipv4) - Checks if a string is a valid IPv4 address
|
|
95
95
|
- [isHexColor](#ishexcolor) - Checks if the input string is a valid hex color
|
|
96
|
+
- [isPalindrome](#ispalindrome) - Checks if the input string is a palindrome (ignores case, spaces, and punctuation)
|
|
97
|
+
- [isCoordinates](#iscoordinates) - Checks if given latitude and longitude are valid coordinates
|
|
98
|
+
- [isLowerCase](#islowercase) - Checks if given string only has lower case characters.
|
|
99
|
+
- [isUpperCase](#isuppercase) - Checks if given string only has upper case characters.
|
|
100
|
+
- [isAlphabetic](#isalphabetic) - Checks if input string contains only Alphabets (case insensitive)
|
|
101
|
+
- [isAlphaNumeric](#isalphanumeric) - Checks if input string contains only Alphabets and Digits (case insensitive)
|
|
102
|
+
- [isAnagram](#isanagram)- Checks if both strings are anagrams of each other. (ignores case and punctuations)
|
|
103
|
+
- [isMacAddress](#ismacaddress)- Checks if a given string is a valid MAC address.
|
|
104
|
+
- [isPanagram](#ispanagram)- Checks if a given string is a pangram (contains every letter of the English alphabet at least once).
|
|
105
|
+
|
|
106
|
+
### Analysis
|
|
96
107
|
|
|
97
|
-
### Analysis
|
|
98
108
|
- [wordCount](#wordcount) - Counts the number of words in a string
|
|
109
|
+
- [contentWordCount](#contentwordcount)- Counts the number of content words (nouns, verbs, adjectives, adverbs, etc.) in a string.
|
|
110
|
+
- [functionWordCount](#functionwordcount)- Counts the number of function words (prepositions, pronouns, conjunctions, articles, etc.) in a string.
|
|
99
111
|
- [readingDuration](#readingduration) - Calculates the reading duration of a given string
|
|
100
112
|
- [characterCount](#charactercount) - Counts the number of characters in a string
|
|
101
113
|
- [characterFrequency](#characterfrequency) - Analyzes character frequency in a string
|
|
102
114
|
- [stringSimilarity](#stringsimilarity) - Calculates the percentage similarity between two strings
|
|
103
|
-
|
|
115
|
+
- [complexity](#complexity) - Analyzes string complexity including score, uniqueness, and length
|
|
116
|
+
- [patternCount](#patterncount) - calculates the number of times a specific pattern occurs in a given text
|
|
117
|
+
- [vowelConsonantCount](#vowelconsonantcount) - Counts the number of vowels and consonants in a given string
|
|
118
|
+
- [checkMultiplePatterns](#checkmultiplepatterns) - Finds occurrences of multiple patterns within a given text using Rabin–Karp algorithm (case sensitive)
|
|
119
|
+
- [checkSubsequence](#checksubsequence) - Checks whether the second string is a subsequence of the first string (case sensitive)
|
|
120
|
+
- [stringRotation](#stringrotation) - Checks if one string is a rotation of another (case sensitive).
|
|
121
|
+
### Formatting
|
|
122
|
+
|
|
104
123
|
- [capitalize](#capitalize) - Capitalizes the first letter of each word
|
|
105
124
|
- [formatNumber](#formatnumber) - Formats a number string with thousand separators
|
|
106
125
|
- [formatPhone](#formatphone) - Formats a phone number string to standard format
|
|
@@ -128,11 +147,11 @@ truncateText('Short', 10);
|
|
|
128
147
|
// Returns: 'Short' (no truncation needed)
|
|
129
148
|
```
|
|
130
149
|
|
|
131
|
-
| Parameter | Type
|
|
132
|
-
|
|
133
|
-
| text
|
|
150
|
+
| Parameter | Type | Default | Description |
|
|
151
|
+
| --------- | ------ | -------- | ------------------------------------------------------ |
|
|
152
|
+
| text | string | required | The input string to truncate |
|
|
134
153
|
| maxLength | number | required | Maximum length of the output string (excluding suffix) |
|
|
135
|
-
| suffix
|
|
154
|
+
| suffix | string | '...' | String to append if truncation occurs |
|
|
136
155
|
|
|
137
156
|
#### <a id="toslug"></a>`toSlug(text)`
|
|
138
157
|
|
|
@@ -151,9 +170,9 @@ toSlug('Special $#@! characters');
|
|
|
151
170
|
// Returns: 'special-characters'
|
|
152
171
|
```
|
|
153
172
|
|
|
154
|
-
| Parameter | Type
|
|
155
|
-
|
|
156
|
-
| text
|
|
173
|
+
| Parameter | Type | Default | Description |
|
|
174
|
+
| --------- | ------ | -------- | ------------------------------------- |
|
|
175
|
+
| text | string | required | The input string to convert to a slug |
|
|
157
176
|
|
|
158
177
|
#### <a id="capitalizewords"></a>`capitalizeWords(text)`
|
|
159
178
|
|
|
@@ -172,9 +191,9 @@ capitalizeWords('already Capitalized');
|
|
|
172
191
|
// Returns: 'Already Capitalized'
|
|
173
192
|
```
|
|
174
193
|
|
|
175
|
-
| Parameter | Type
|
|
176
|
-
|
|
177
|
-
| text
|
|
194
|
+
| Parameter | Type | Default | Description |
|
|
195
|
+
| --------- | ------ | -------- | ------------------------------ |
|
|
196
|
+
| text | string | required | The input string to capitalize |
|
|
178
197
|
|
|
179
198
|
#### <a id="removespecialchars"></a>`removeSpecialChars(text, replacement = '')`
|
|
180
199
|
|
|
@@ -193,10 +212,10 @@ removeSpecialChars('Phone: (123) 456-7890', '-');
|
|
|
193
212
|
// Returns: 'Phone-123-456-7890'
|
|
194
213
|
```
|
|
195
214
|
|
|
196
|
-
| Parameter
|
|
197
|
-
|
|
198
|
-
| text
|
|
199
|
-
| replacement | string | ''
|
|
215
|
+
| Parameter | Type | Default | Description |
|
|
216
|
+
| ----------- | ------ | -------- | ----------------------------------------- |
|
|
217
|
+
| text | string | required | The input string to process |
|
|
218
|
+
| replacement | string | '' | String to replace special characters with |
|
|
200
219
|
|
|
201
220
|
#### <a id="removewords"></a>`removeWords(text, wordsToRemove)`
|
|
202
221
|
|
|
@@ -209,20 +228,20 @@ removeWords('Hello world this is a test', ['this', 'is']);
|
|
|
209
228
|
// Returns: 'Hello world a test'
|
|
210
229
|
|
|
211
230
|
removeWords('Remove The Quick BROWN fox', ['the', 'brown']);
|
|
212
|
-
// Returns: 'Remove Quick fox'
|
|
231
|
+
// Returns: 'Remove Quick fox'
|
|
213
232
|
|
|
214
233
|
removeWords('JavaScript is awesome and JavaScript rocks', ['JavaScript']);
|
|
215
234
|
// Returns: 'is awesome and rocks'
|
|
216
235
|
```
|
|
217
236
|
|
|
218
|
-
| Parameter
|
|
219
|
-
|
|
220
|
-
| text
|
|
237
|
+
| Parameter | Type | Default | Description |
|
|
238
|
+
| ------------- | -------- | -------- | ---------------------------------------- |
|
|
239
|
+
| text | string | required | The input string to process |
|
|
221
240
|
| wordsToRemove | string[] | required | Array of words to remove from the string |
|
|
222
241
|
|
|
223
242
|
#### <a id="removeduplicates"></a>`removeDuplicates(text)`
|
|
224
243
|
|
|
225
|
-
Removes duplicate case-sensitive words from a given text.
|
|
244
|
+
Removes duplicate case-sensitive words from a given text.
|
|
226
245
|
|
|
227
246
|
```javascript
|
|
228
247
|
import { removeDuplicates } from 'stringzy';
|
|
@@ -231,15 +250,15 @@ removeDuplicates('Hello world this is a is a test');
|
|
|
231
250
|
// Returns: 'Hello world this is a test'
|
|
232
251
|
|
|
233
252
|
removeDuplicates('Remove me me me me or Me');
|
|
234
|
-
// Returns: 'Remove me or Me'
|
|
253
|
+
// Returns: 'Remove me or Me'
|
|
235
254
|
|
|
236
255
|
removeDuplicates('JavaScript is not bad and not awesome');
|
|
237
256
|
// Returns: 'JavaScript is not bad and awesome'
|
|
238
257
|
```
|
|
239
258
|
|
|
240
|
-
| Parameter | Type
|
|
241
|
-
|
|
242
|
-
| text
|
|
259
|
+
| Parameter | Type | Default | Description |
|
|
260
|
+
| --------- | ------ | -------- | --------------------------- |
|
|
261
|
+
| text | string | required | The input string to process |
|
|
243
262
|
|
|
244
263
|
#### <a id="initials"></a>`initials(text, limit)`
|
|
245
264
|
|
|
@@ -264,10 +283,10 @@ initials(' Multiple Spaces Between ');
|
|
|
264
283
|
// Returns: 'MSB'
|
|
265
284
|
```
|
|
266
285
|
|
|
267
|
-
| Parameter | Type
|
|
268
|
-
|
|
269
|
-
| text
|
|
270
|
-
| limit
|
|
286
|
+
| Parameter | Type | Default | Description |
|
|
287
|
+
| --------- | ------ | --------- | ----------------------------------------------- |
|
|
288
|
+
| text | string | required | The input string to extract initials from |
|
|
289
|
+
| limit | number | undefined | Maximum number of initials to return (optional) |
|
|
271
290
|
|
|
272
291
|
#### <a id="camelcase"></a>`camelCase(text)`
|
|
273
292
|
|
|
@@ -277,43 +296,41 @@ Converts the given string to Camel Case.
|
|
|
277
296
|
import { camelCase } from 'stringzy';
|
|
278
297
|
|
|
279
298
|
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 |
|
|
299
|
+
camelCase('this is a test'); // 'thisIsATest'
|
|
300
|
+
```
|
|
285
301
|
|
|
302
|
+
| Parameter | Type | Default | Description |
|
|
303
|
+
| --------- | ------ | -------- | ----------------------------------------- |
|
|
304
|
+
| text | string | required | The input string to convert to Camel Case |
|
|
286
305
|
|
|
287
306
|
#### <a id="pascalcase"></a>`pascalCase(text)`
|
|
307
|
+
|
|
288
308
|
Converts the given string to Pascal Case.
|
|
289
309
|
|
|
290
310
|
```javascript
|
|
291
311
|
import { pascalCase } from 'stringzy';
|
|
292
312
|
|
|
293
|
-
|
|
294
313
|
pascalCase('hello world'); // 'HelloWorld'
|
|
295
314
|
pascalCase('this is a test'); // 'ThisIsATest'
|
|
296
315
|
```
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
|
316
|
+
|
|
317
|
+
| Parameter | Type | Default | Description |
|
|
318
|
+
| --------- | ------ | -------- | ------------------------------------------ |
|
|
319
|
+
| text | string | required | The input string to convert to Pascal Case |
|
|
300
320
|
|
|
301
321
|
#### <a id="snakecase"></a>`snakeCase(text)`
|
|
302
322
|
|
|
303
323
|
Converts the given string to Snake Case.
|
|
304
324
|
|
|
305
|
-
```javascript
|
|
325
|
+
```javascript
|
|
306
326
|
import { snakeCase } from 'stringzy';
|
|
307
327
|
snakeCase('hello world'); // 'hello_world'
|
|
308
328
|
snakeCase('this is a test'); // 'this_is_a_test'
|
|
309
329
|
```
|
|
310
330
|
|
|
311
|
-
| Parameter | Type
|
|
312
|
-
|
|
313
|
-
| text
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
331
|
+
| Parameter | Type | Default | Description |
|
|
332
|
+
| --------- | ------ | -------- | ----------------------------------------- |
|
|
333
|
+
| text | string | required | The input string to convert to Snake Case |
|
|
317
334
|
|
|
318
335
|
#### <a id="kebabcase"></a>`kebabCase(text)`
|
|
319
336
|
|
|
@@ -322,15 +339,13 @@ Converts the given string to Kebab Case.
|
|
|
322
339
|
```javascript
|
|
323
340
|
import { kebabCase } from 'stringzy';
|
|
324
341
|
|
|
325
|
-
|
|
326
342
|
kebabCase('hello world'); // 'hello-world'
|
|
327
343
|
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
|
-
|
|
344
|
+
```
|
|
333
345
|
|
|
346
|
+
| Parameter | Type | Default | Description |
|
|
347
|
+
| --------- | ------ | -------- | ----------------------------------------- |
|
|
348
|
+
| text | string | required | The input string to convert to Kebab Case |
|
|
334
349
|
|
|
335
350
|
#### <a id="titlecase"></a>`titleCase(text)`
|
|
336
351
|
|
|
@@ -339,28 +354,28 @@ Converts the given string to Title Case.
|
|
|
339
354
|
```javascript
|
|
340
355
|
import { titleCase } from 'stringzy';
|
|
341
356
|
|
|
342
|
-
|
|
343
357
|
titleCase('hello world'); // 'Hello World'
|
|
344
358
|
titleCase('this is a test'); // 'This Is A Test'
|
|
345
359
|
```
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
|
360
|
+
|
|
361
|
+
| Parameter | Type | Default | Description |
|
|
362
|
+
| --------- | ------ | -------- | ----------------------------------------- |
|
|
363
|
+
| text | string | required | The input string to convert to Title Case |
|
|
349
364
|
|
|
350
365
|
#### <a id="constantcase"></a>`constantCase(text)`
|
|
366
|
+
|
|
351
367
|
Converts the given string to Constant Case.
|
|
352
368
|
|
|
353
369
|
```javascript
|
|
354
370
|
import { constantCase } from 'stringzy';
|
|
355
371
|
|
|
356
|
-
|
|
357
372
|
constantCase('hello world'); // 'HELLO_WORLD'
|
|
358
373
|
constantCase('this is a test'); // 'THIS_IS_A_TEST'
|
|
359
|
-
|
|
360
374
|
```
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
|
375
|
+
|
|
376
|
+
| Parameter | Type | Default | Description |
|
|
377
|
+
| --------- | ------ | -------- | -------------------------------------------- |
|
|
378
|
+
| text | string | required | The input string to convert to Constant Case |
|
|
364
379
|
|
|
365
380
|
#### <a id="escapehtml"></a>`escapeHTML(text)`
|
|
366
381
|
|
|
@@ -382,12 +397,13 @@ escapeHTML('Say "Hello" & it\'s < 5 > 2');
|
|
|
382
397
|
// Returns: 'Say "Hello" & it's < 5 > 2'
|
|
383
398
|
```
|
|
384
399
|
|
|
385
|
-
| Parameter | Type
|
|
386
|
-
|
|
387
|
-
| text
|
|
400
|
+
| Parameter | Type | Default | Description |
|
|
401
|
+
| --------- | ------ | -------- | ----------------------------------------------- |
|
|
402
|
+
| text | string | required | The input string to escape HTML characters from |
|
|
388
403
|
|
|
389
404
|
#### <a id="masksegment"></a>`maskSegment(text, maskStart, maskEnd, maskChar?)`
|
|
390
|
-
|
|
405
|
+
|
|
406
|
+
Masks a segment of a string by replacing characters between two indices with a specified character (default is '\*').
|
|
391
407
|
|
|
392
408
|
```javascript
|
|
393
409
|
import { maskSegment } from 'stringzy';
|
|
@@ -400,16 +416,17 @@ maskSegment('abcdef', 1, 4, '#');
|
|
|
400
416
|
|
|
401
417
|
maskSegment('token');
|
|
402
418
|
// Returns: '*****'
|
|
403
|
-
|
|
404
419
|
```
|
|
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
420
|
|
|
412
|
-
|
|
421
|
+
| Parameter | Type | Default | Description |
|
|
422
|
+
| --------- | ------ | ------------- | -------------------------------------------------------- |
|
|
423
|
+
| text | string | required | The input string to apply the masking to |
|
|
424
|
+
| maskStart | number | `0` | The start index (inclusive) of the segment to mask |
|
|
425
|
+
| maskEnd | number | `text.length` | The end index (exclusive) of the segment to mask |
|
|
426
|
+
| maskChar | string | `'*'` | The character to use for masking (must be one character) |
|
|
427
|
+
|
|
428
|
+
#### <a id="deburr"></a>`deburr(text)`
|
|
429
|
+
|
|
413
430
|
Removes accents and diacritics from letters in a string (e.g. déjà vu → deja vu).
|
|
414
431
|
|
|
415
432
|
```javascript
|
|
@@ -423,14 +440,137 @@ deburr('Élève São Paulo');
|
|
|
423
440
|
|
|
424
441
|
deburr('über cool');
|
|
425
442
|
// Returns: 'uber cool'
|
|
426
|
-
|
|
427
443
|
```
|
|
428
|
-
|
|
444
|
+
|
|
445
|
+
| Parameter | Type | Default | Description |
|
|
429
446
|
| --------- | ------ | -------- | ----------------------------------------- |
|
|
430
447
|
| text | string | required | The input string to strip diacritics from |
|
|
431
448
|
|
|
432
449
|
---
|
|
433
450
|
|
|
451
|
+
#### <a id="splitchunks"></a>`splitChunks(text, chunkSize)`
|
|
452
|
+
|
|
453
|
+
Takes a string and chunk size as the argument and splits the string into chunks of given size.
|
|
454
|
+
|
|
455
|
+
```javascript
|
|
456
|
+
import { splitChunks } from 'stringzy';
|
|
457
|
+
|
|
458
|
+
splitChunks('helloworld', 2);
|
|
459
|
+
// Returns: ['he', 'll', 'ow', 'or', 'ld']
|
|
460
|
+
|
|
461
|
+
splitChunks('helloworld', 3);
|
|
462
|
+
// Returns: ['hel', 'low', 'orl', 'd']
|
|
463
|
+
|
|
464
|
+
splitChunks('helloworld');
|
|
465
|
+
// Returns: ['h', 'e', 'l', 'l', 'o', 'w', 'o', 'r', 'l', 'd']
|
|
466
|
+
```
|
|
467
|
+
|
|
468
|
+
| Parameter | Type | Default | Description |
|
|
469
|
+
| --------- | ------ | -------- | --------------------------------------------------------- |
|
|
470
|
+
| text | string | required | The input string that needs to be chunked |
|
|
471
|
+
| chunkSize | number | `1` | The size of each chunk in which the string is to be split |
|
|
472
|
+
|
|
473
|
+
---
|
|
474
|
+
|
|
475
|
+
#### <a id="numbertotext"></a>`numberToText(num, lang)`
|
|
476
|
+
|
|
477
|
+
Converts a number to its text representation in the specified language.
|
|
478
|
+
|
|
479
|
+
```javascript
|
|
480
|
+
import { numberToText } from 'stringzy';
|
|
481
|
+
numberToText(12345); // Returns: 'twelve thousand three hundred forty-five'
|
|
482
|
+
numberToText(12345, 'en'); // Returns: 'twelve thousand three hundred forty-five'
|
|
483
|
+
numberToText(12345, 'pl'); // Returns: 'dwanaście tysięcy trzysta czterdzieści pięć'
|
|
484
|
+
```
|
|
485
|
+
|
|
486
|
+
| Parameter | Type | Default | Description |
|
|
487
|
+
| --------- | ------ | -------- | --------------------------------------------------------------------------------------- |
|
|
488
|
+
| num | number | required | The number to convert to text |
|
|
489
|
+
| lang | string | 'en' | The language code for the text representation (e.g., 'en' for English, 'pl' for Polish) |
|
|
490
|
+
|
|
491
|
+
Available languages: en (English), pl (Polish).
|
|
492
|
+
|
|
493
|
+
#### <a id="reversewordsinstring"></a>`reverseWordsInString(str)`
|
|
494
|
+
Reverses the order of words in a string and reverses the position of surrounding whitespace (leading becomes trailing and vice-versa).
|
|
495
|
+
Reverses the order of words in a string while preserving the exact original spacing between each word.
|
|
496
|
+
```javascript
|
|
497
|
+
import { reverseWordsInString } from 'stringzy';
|
|
498
|
+
|
|
499
|
+
reverseWordsInString('Hello world from stringzy');
|
|
500
|
+
// Returns: 'stringzy from world Hello'
|
|
501
|
+
|
|
502
|
+
// Note how the double and triple spaces are preserved:
|
|
503
|
+
reverseWordsInString(' leading spaces and trailing ');
|
|
504
|
+
// Returns: ' trailing and spaces leading '
|
|
505
|
+
|
|
506
|
+
reverseWordsInString('single-word');
|
|
507
|
+
// Returns: 'single-word'
|
|
508
|
+
```
|
|
509
|
+
| Parameter | Type | Default | Description |
|
|
510
|
+
| --------- | ------ | -------- | --------------------------- |
|
|
511
|
+
| str | string | required | The input string to reverse |
|
|
512
|
+
|
|
513
|
+
#### <a id="stringpermutations"></a>`stringPermutations(str)`
|
|
514
|
+
|
|
515
|
+
Generates all unique permutations of a given string.
|
|
516
|
+
Repeated characters are handled by ensuring only unique permutations are included in the output array.
|
|
517
|
+
The order of permutations is not guaranteed.
|
|
518
|
+
|
|
519
|
+
```javascript
|
|
520
|
+
stringPermutations('ab');
|
|
521
|
+
// ['ab', 'ba']
|
|
522
|
+
|
|
523
|
+
stringPermutations('abc');
|
|
524
|
+
// ['abc', 'acb', 'bac', 'bca', 'cab', 'cba']
|
|
525
|
+
|
|
526
|
+
stringPermutations('aab');
|
|
527
|
+
// ['aab', 'aba', 'baa']
|
|
528
|
+
|
|
529
|
+
stringPermutations('');
|
|
530
|
+
// ['']
|
|
531
|
+
|
|
532
|
+
stringPermutations('a');
|
|
533
|
+
// ['a']
|
|
534
|
+
|
|
535
|
+
stringPermutations('a1!');
|
|
536
|
+
// ['a1!', 'a!1', '1a!', '1!a', '!a1', '!1a']
|
|
537
|
+
```
|
|
538
|
+
|
|
539
|
+
| Parameter | Type | Default | Description |
|
|
540
|
+
| --------- | ------ | -------- | ----------------------------------------------------- |
|
|
541
|
+
| str | string | required | The input string to generate all unique permutations. |
|
|
542
|
+
|
|
543
|
+
#### <a id="stringcombinations"></a>`stringCombinations(str)`
|
|
544
|
+
|
|
545
|
+
Generates all unique combinations (subsequences) of a given string, including the empty string.
|
|
546
|
+
Duplicate characters are handled by ensuring only unique combinations are returned.
|
|
547
|
+
The order of combinations in the output array is not guaranteed.
|
|
548
|
+
|
|
549
|
+
```javascript
|
|
550
|
+
stringCombinations('ab');
|
|
551
|
+
// ["", "a", "b", "ab"]
|
|
552
|
+
|
|
553
|
+
stringCombinations('abc');
|
|
554
|
+
// ["", "a", "b", "c", "ab", "ac", "bc", "abc"]
|
|
555
|
+
|
|
556
|
+
stringCombinations('aab');
|
|
557
|
+
// ["", "a", "b", "aa", "ab", "aab"]
|
|
558
|
+
|
|
559
|
+
stringCombinations('');
|
|
560
|
+
// [""]
|
|
561
|
+
|
|
562
|
+
stringCombinations('A');
|
|
563
|
+
// ["", "A"]
|
|
564
|
+
|
|
565
|
+
stringCombinations('!@');
|
|
566
|
+
// ["", "!", "@", "!@"]
|
|
567
|
+
```
|
|
568
|
+
|
|
569
|
+
| Parameter | Type | Default | Description |
|
|
570
|
+
| --------- | ------ | -------- | ------------------------------------------------------ |
|
|
571
|
+
| str | string | required | The input string to generate unique combinations from. |
|
|
572
|
+
|
|
573
|
+
|
|
434
574
|
### ✅ Validations
|
|
435
575
|
|
|
436
576
|
Functions for validating string formats and content.
|
|
@@ -444,9 +584,9 @@ isURL('https://example.com'); // true
|
|
|
444
584
|
isURL('not-a-url'); // false
|
|
445
585
|
```
|
|
446
586
|
|
|
447
|
-
| Parameter | Type
|
|
448
|
-
|
|
449
|
-
| text
|
|
587
|
+
| Parameter | Type | Default | Description |
|
|
588
|
+
| --------- | ------ | -------- | ----------------------------------- |
|
|
589
|
+
| text | string | required | The input string to validate as URL |
|
|
450
590
|
|
|
451
591
|
#### <a id="isemail"></a>`isEmail(text)`
|
|
452
592
|
|
|
@@ -457,9 +597,9 @@ isEmail('user@example.com'); // true
|
|
|
457
597
|
isEmail('invalid-email'); // false
|
|
458
598
|
```
|
|
459
599
|
|
|
460
|
-
| Parameter | Type
|
|
461
|
-
|
|
462
|
-
| text
|
|
600
|
+
| Parameter | Type | Default | Description |
|
|
601
|
+
| --------- | ------ | -------- | ------------------------------------- |
|
|
602
|
+
| text | string | required | The input string to validate as email |
|
|
463
603
|
|
|
464
604
|
#### <a id="isdate"></a>`isDate(text)`
|
|
465
605
|
|
|
@@ -476,11 +616,11 @@ isDate('invalid-date', DateFormat.YYYMMDD); // false
|
|
|
476
616
|
isDate('2023-13-45', DateFormat.YYYMMDD); // false
|
|
477
617
|
```
|
|
478
618
|
|
|
479
|
-
| Parameter | Type
|
|
480
|
-
|
|
481
|
-
| input
|
|
482
|
-
| format
|
|
483
|
-
| separator | string
|
|
619
|
+
| Parameter | Type | Default | Description |
|
|
620
|
+
| --------- | ----------- | -------- | ----------------------------------------- |
|
|
621
|
+
| input | string | required | The input string to validate as date |
|
|
622
|
+
| format | DateFormats | required | The date format to validate against |
|
|
623
|
+
| separator | string | optional | The separator to be used if it is not "-" |
|
|
484
624
|
|
|
485
625
|
#### <a id="isempty"></a>`isEmpty(text)`
|
|
486
626
|
|
|
@@ -491,26 +631,44 @@ isEmpty(' '); // true
|
|
|
491
631
|
isEmpty('hello'); // false
|
|
492
632
|
```
|
|
493
633
|
|
|
494
|
-
| Parameter | Type
|
|
495
|
-
|
|
496
|
-
| text
|
|
634
|
+
| Parameter | Type | Default | Description |
|
|
635
|
+
| --------- | ------ | -------- | --------------------------------------- |
|
|
636
|
+
| text | string | required | The input string to check for emptiness |
|
|
497
637
|
|
|
498
638
|
#### <a id="isslug"></a>`isSlug(text)`
|
|
499
639
|
|
|
500
640
|
Checks if a string is a valid slug.
|
|
501
641
|
|
|
502
642
|
```javascript
|
|
503
|
-
isSlug(
|
|
504
|
-
isSlug(
|
|
505
|
-
isSlug(
|
|
506
|
-
isSlug(
|
|
507
|
-
isSlug(
|
|
508
|
-
isSlug(
|
|
643
|
+
isSlug('hello-world'); // true
|
|
644
|
+
isSlug('test-product-123'); // true
|
|
645
|
+
isSlug('Hello-World'); // false (uppercase letters)
|
|
646
|
+
isSlug('hello--world'); // false (consecutive hyphens)
|
|
647
|
+
isSlug('-hello-world'); // false (starts with hyphen)
|
|
648
|
+
isSlug('hello_world'); // false (underscore not allowed)
|
|
509
649
|
```
|
|
510
650
|
|
|
511
|
-
| Parameter | Type
|
|
512
|
-
|
|
513
|
-
| text
|
|
651
|
+
| Parameter | Type | Default | Description |
|
|
652
|
+
| --------- | ------ | -------- | ------------------------------------ |
|
|
653
|
+
| text | string | required | The input string to validate as slug |
|
|
654
|
+
|
|
655
|
+
#### <a id="istypeof"></a>`isTypeOf(input, type)`
|
|
656
|
+
|
|
657
|
+
Checks if a file or URL has a valid extension for a given type
|
|
658
|
+
|
|
659
|
+
```javascript
|
|
660
|
+
isType('photo.PNG', 'image'); // true
|
|
661
|
+
isType('https://example.com/logo.svg', 'image'); // true
|
|
662
|
+
isType({ name: 'track.mp3' }, 'audio'); // true
|
|
663
|
+
isType('filewithoutextension', 'image'); // false
|
|
664
|
+
isType('document.zip', 'document'); // false
|
|
665
|
+
isType('video.mp4', 'document'); // false
|
|
666
|
+
```
|
|
667
|
+
|
|
668
|
+
| Parameter | Type | Default | Description |
|
|
669
|
+
| --------- | ------ | -------- | --------------------------------------------------------------------------- |
|
|
670
|
+
| input | string | required | The file name, URL string, or object with .name |
|
|
671
|
+
| input | string | required | The file type category to validate (image, video, audio, document, archive) |
|
|
514
672
|
|
|
515
673
|
#### <a id="isipv4"></a>`isIPv4(text)`
|
|
516
674
|
|
|
@@ -527,10 +685,9 @@ isIPv4('192.168.01.1'); // false (leading zeros)
|
|
|
527
685
|
isIPv4('192.168.1.a'); // false (non-numeric)
|
|
528
686
|
```
|
|
529
687
|
|
|
530
|
-
| Parameter | Type
|
|
531
|
-
|
|
532
|
-
| text
|
|
533
|
-
|
|
688
|
+
| Parameter | Type | Default | Description |
|
|
689
|
+
| --------- | ------ | -------- | -------------------------------------------- |
|
|
690
|
+
| text | string | required | The input string to validate as IPv4 address |
|
|
534
691
|
|
|
535
692
|
#### <a id="ishexcolor"></a>`isHexColor(text)`
|
|
536
693
|
|
|
@@ -539,20 +696,202 @@ Checks if a string is a valid Hex color.
|
|
|
539
696
|
```javascript
|
|
540
697
|
import { isHexColor } from 'stringzy';
|
|
541
698
|
|
|
542
|
-
isHexColor('#fff');
|
|
543
|
-
isHexColor('fff');
|
|
544
|
-
isHexColor('#a1b2c3');
|
|
545
|
-
isHexColor('123abc');
|
|
546
|
-
isHexColor('#1234');
|
|
547
|
-
isHexColor('blue');
|
|
699
|
+
isHexColor('#fff'); // true
|
|
700
|
+
isHexColor('fff'); // true
|
|
701
|
+
isHexColor('#a1b2c3'); // true
|
|
702
|
+
isHexColor('123abc'); // true
|
|
703
|
+
isHexColor('#1234'); // false
|
|
704
|
+
isHexColor('blue'); // false
|
|
548
705
|
```
|
|
549
706
|
|
|
550
|
-
| Parameter | Type
|
|
551
|
-
|
|
552
|
-
| text
|
|
707
|
+
| Parameter | Type | Default | Description |
|
|
708
|
+
| --------- | ------ | -------- | ----------------------------------------- |
|
|
709
|
+
| text | string | required | The input string to validate as Hex color |
|
|
553
710
|
|
|
554
|
-
|
|
711
|
+
#### <a id="ispalindrome"></a>`isPalindrome(text)`
|
|
712
|
+
|
|
713
|
+
Checks if a string is a palindrome.
|
|
714
|
+
The check is case-insensitive and ignores spaces and punctuation.
|
|
715
|
+
|
|
716
|
+
```javascript
|
|
717
|
+
import { isPalindrome } from 'stringzy';
|
|
718
|
+
|
|
719
|
+
isPalindrome('racecar'); // true
|
|
720
|
+
isPalindrome('A man, a plan, a canal: Panama'); // true
|
|
721
|
+
isPalindrome('No lemon, no melon'); // true
|
|
722
|
+
isPalindrome('hello'); // false
|
|
723
|
+
isPalindrome('Was it a car or a cat I saw?'); // true
|
|
724
|
+
```
|
|
725
|
+
|
|
726
|
+
| Parameter | Type | Default | Description |
|
|
727
|
+
| --------- | ------ | -------- | ---------------------------------------- |
|
|
728
|
+
| text | string | required | The input string to check for palindrome |
|
|
729
|
+
|
|
730
|
+
#### <a id="iscoordinates"></a>`isCoordinates(latitude, longitude)`
|
|
731
|
+
|
|
732
|
+
Checks if given latitude and longitude are valid coordinates.
|
|
733
|
+
|
|
734
|
+
```javascript
|
|
735
|
+
import { isCoordinates } from 'stringzy';
|
|
736
|
+
|
|
737
|
+
isCoordinates(48.8582, 2.2945); // true
|
|
738
|
+
isCoordinates(40.748817, -73.985428); // true
|
|
739
|
+
isCoordinates(9999, -9999); // false
|
|
740
|
+
```
|
|
741
|
+
|
|
742
|
+
| Parameter | Type | Default | Description |
|
|
743
|
+
| --------- | ------ | -------- | --------------------- |
|
|
744
|
+
| latitude | number | required | Latitude to validate |
|
|
745
|
+
| longitude | number | required | Longitude to validate |
|
|
746
|
+
|
|
747
|
+
#### <a id="islowercase"></a>`isLowerCase(str)`
|
|
748
|
+
|
|
749
|
+
Checks whether the given string contains only lowercase alphabetic characters.
|
|
750
|
+
Ignores digits, special characters, white spaces.
|
|
751
|
+
|
|
752
|
+
```javascript
|
|
753
|
+
import { isLowerCase } from 'stringzy';
|
|
754
|
+
|
|
755
|
+
isLowerCase('hello'); // true
|
|
756
|
+
isLowerCase('hello123!'); // true
|
|
757
|
+
isLowerCase('Hello'); // false
|
|
758
|
+
isLowerCase('12345'); // false
|
|
759
|
+
```
|
|
760
|
+
|
|
761
|
+
| Parameter | Type | Default | Description |
|
|
762
|
+
| --------- | ------ | -------- | ---------------------------------------------------------------------------- |
|
|
763
|
+
| str | string | required | The input string to validate as containing lowercase alphabetic letters |
|
|
764
|
+
|
|
765
|
+
#### <a id="isuppercase"></a>`isUpperCase(str)`
|
|
555
766
|
|
|
767
|
+
Checks whether the given string contains only uppercase alphabetic characters.
|
|
768
|
+
Ignores digits, special characters, white spaces.
|
|
769
|
+
|
|
770
|
+
```javascript
|
|
771
|
+
import { isUpperCase } from 'stringzy';
|
|
772
|
+
|
|
773
|
+
isUpperCase('HELLO'); // true
|
|
774
|
+
isUpperCase('HELLO123!'); // true
|
|
775
|
+
isUpperCase('Hello'); // false
|
|
776
|
+
isUpperCase('12345'); // false
|
|
777
|
+
```
|
|
778
|
+
|
|
779
|
+
| Parameter | Type | Default | Description |
|
|
780
|
+
| --------- | ------ | -------- | ---------------------------------------------------------------------------- |
|
|
781
|
+
| str | string | required | The input string to validate as containing uppercase alphabetic letters |
|
|
782
|
+
|
|
783
|
+
#### <a id="isalphabetic"></a>`isAlphabetic(text)`
|
|
784
|
+
|
|
785
|
+
Checks if a string contains only alphabetic characters (a-z, A-Z).
|
|
786
|
+
Throws an error if the input is not a string.
|
|
787
|
+
|
|
788
|
+
```javascript
|
|
789
|
+
import { isAlphabetic } from 'stringzy';
|
|
790
|
+
|
|
791
|
+
isAlphabetic('hello'); // true
|
|
792
|
+
isAlphabetic('World'); // true
|
|
793
|
+
isAlphabetic('helloWORLD'); // true
|
|
794
|
+
isAlphabetic('abc123'); // false
|
|
795
|
+
isAlphabetic('hello!'); // false
|
|
796
|
+
isAlphabetic(''); // false
|
|
797
|
+
```
|
|
798
|
+
|
|
799
|
+
| Parameter | Type | Default | Description |
|
|
800
|
+
| --------- | ------ | -------- | --------------------------------------------- |
|
|
801
|
+
| text | string | required | The input string to check for alphabetic only |
|
|
802
|
+
|
|
803
|
+
#### <a id="isalphanumeric"></a>`isAlphaNumeric(text)`
|
|
804
|
+
|
|
805
|
+
Checks if a string contains only alphanumeric characters (letters and digits).
|
|
806
|
+
Throws an error if the input is not a string.
|
|
807
|
+
|
|
808
|
+
```javascript
|
|
809
|
+
import { isAlphaNumeric } from 'stringzy';
|
|
810
|
+
|
|
811
|
+
isAlphaNumeric('abc123'); // true
|
|
812
|
+
isAlphaNumeric('A1B2C3'); // true
|
|
813
|
+
isAlphaNumeric('123'); // true
|
|
814
|
+
isAlphaNumeric('hello'); // true
|
|
815
|
+
isAlphaNumeric('hello!'); // false
|
|
816
|
+
isAlphaNumeric('123 456'); // false
|
|
817
|
+
isAlphaNumeric(''); // false
|
|
818
|
+
```
|
|
819
|
+
|
|
820
|
+
| Parameter | Type | Default | Description |
|
|
821
|
+
| --------- | ------ | -------- | ----------------------------------------------- |
|
|
822
|
+
| text | string | required | The input string to check for alphanumeric only |
|
|
823
|
+
|
|
824
|
+
#### <a id="isanagram"></a>`isAnagram(str1, str2)`
|
|
825
|
+
|
|
826
|
+
Checks whether two strings are anagrams of each other (contain the same characters in the same frequency, regardless of order).
|
|
827
|
+
- Comparison is case-insensitive.
|
|
828
|
+
- Spaces and punctuation are ignored.
|
|
829
|
+
- Throws an error if either input is not a string.
|
|
830
|
+
|
|
831
|
+
```javascript
|
|
832
|
+
import { isAnagram } from 'stringzy';
|
|
833
|
+
|
|
834
|
+
isAnagram('listen', 'silent'); // true
|
|
835
|
+
isAnagram('Debit Card', 'Bad Credit'); // true
|
|
836
|
+
isAnagram('Astronomer', 'Moon starer'); // true
|
|
837
|
+
isAnagram('hello', 'world'); // false
|
|
838
|
+
isAnagram('a', 'b'); // false
|
|
839
|
+
isAnagram('', ''); // true
|
|
840
|
+
```
|
|
841
|
+
|
|
842
|
+
| Parameter | Type | Default | Description |
|
|
843
|
+
| --------- | ------ | -------- | ---------------------------------------- |
|
|
844
|
+
| str1 | string | required | The first string to check as an anagram |
|
|
845
|
+
| str2 | string | required | The second string to check as an anagram |
|
|
846
|
+
|
|
847
|
+
#### <a id="ismacaddress"></a>`isMacAddress(str)`
|
|
848
|
+
|
|
849
|
+
Checks whether a given string is a valid **MAC address**.
|
|
850
|
+
- A valid MAC address consists of six pairs of hexadecimal digits (`0–9`, `A–F`, case-insensitive).
|
|
851
|
+
- Returns `true` if the string is a valid MAC address, otherwise `false`.
|
|
852
|
+
- Throws an error if input is not a string.
|
|
853
|
+
|
|
854
|
+
```javascript
|
|
855
|
+
import { isMacAddress } from 'stringzy';
|
|
856
|
+
|
|
857
|
+
isMacAddress("00:1A:2B:3C:4D:5E"); // true
|
|
858
|
+
isMacAddress("00-1A-2B-3C-4D-5E"); // true
|
|
859
|
+
isMacAddress("aa:bb:cc:dd:ee:ff"); // true
|
|
860
|
+
isMacAddress("FF-FF-FF-FF-FF-FF"); // true
|
|
861
|
+
|
|
862
|
+
isMacAddress("00:1G:2B:3C:4D:5E"); // false (invalid hex digit)
|
|
863
|
+
isMacAddress("00:1A-2B:3C-4D:5E"); // false (mixed separators)
|
|
864
|
+
isMacAddress("001A:2B:3C:4D:5E"); // false (wrong group length)
|
|
865
|
+
isMacAddress("hello-world-mac"); // false (invalid format)
|
|
866
|
+
isMacAddress(""); // false (empty string)
|
|
867
|
+
```
|
|
868
|
+
|
|
869
|
+
| Parameter | Type | Default | Description |
|
|
870
|
+
| --------- | ------ | -------- | --------------------------------------- |
|
|
871
|
+
| str | string | required | The string to validate as a MAC address |
|
|
872
|
+
|
|
873
|
+
#### <a id="ispanagram"></a>`isPangram(str)`
|
|
874
|
+
|
|
875
|
+
- Checks if a given string is a **pangram** (i.e., contains every letter of the English alphabet at least once).
|
|
876
|
+
- The check is **case-insensitive**, and non-alphabetic characters (numbers, punctuation, spaces) are ignored. An empty string is not considered a pangram.
|
|
877
|
+
- Throws an error if the input is not a string.
|
|
878
|
+
|
|
879
|
+
```javascript
|
|
880
|
+
import { isPangram } from 'stringzy';
|
|
881
|
+
|
|
882
|
+
isPangram("The quick brown fox jumps over the lazy dog."); // true
|
|
883
|
+
isPangram("This is not a pangram."); // false
|
|
884
|
+
isPangram("Abcdefghijklmnopqrstuvwxyz"); // true
|
|
885
|
+
isPangram("AbCdEfGhIjKlMnOpQrStUvWxYz"); // true
|
|
886
|
+
isPangram("A-B-C-D-E-F-G-H-I-J-K-L-M-N-O-P-Q-R-S-T-U-V-W-X-Y-Z"); // true
|
|
887
|
+
isPangram(""); // false
|
|
888
|
+
isPangram("Hello world"); // false
|
|
889
|
+
```
|
|
890
|
+
|
|
891
|
+
| Parameter | Type | Default | Description |
|
|
892
|
+
| --------- | ------ | -------- | ----------------------------------------------------- |
|
|
893
|
+
| str | string | required | The input string to check for pangram characteristics |
|
|
894
|
+
---
|
|
556
895
|
|
|
557
896
|
### 📊 Analysis
|
|
558
897
|
|
|
@@ -565,21 +904,25 @@ Calculates the estimated reading duration for a given text based on an average r
|
|
|
565
904
|
```javascript
|
|
566
905
|
import { readingDuration } from 'stringzy';
|
|
567
906
|
|
|
568
|
-
readingDuration(
|
|
907
|
+
readingDuration(
|
|
908
|
+
'This is a sample text with twenty-three words to test the reading duration function.'
|
|
909
|
+
);
|
|
569
910
|
// Returns: 0 (23 words / 230 words per minute ≈ 0 minutes)
|
|
570
911
|
|
|
571
|
-
readingDuration(
|
|
912
|
+
readingDuration(
|
|
913
|
+
'This text contains fifty words. It is designed to test the reading duration function with a larger input.',
|
|
914
|
+
200
|
|
915
|
+
);
|
|
572
916
|
// Returns: 1 (50 words / 200 words per minute ≈ 1 minute)
|
|
573
917
|
|
|
574
918
|
readingDuration(Array(9999).fill('Word').join(' '));
|
|
575
919
|
// Returns: 43 (9999 words / 230 words per minute ≈ 43 minutes)
|
|
576
920
|
```
|
|
577
921
|
|
|
578
|
-
| Parameter
|
|
579
|
-
|
|
580
|
-
| text
|
|
581
|
-
| readingSpeed
|
|
582
|
-
|
|
922
|
+
| Parameter | Type | Default | Description |
|
|
923
|
+
| ------------ | ------ | -------- | ------------------------------------------------------------------------------ |
|
|
924
|
+
| text | string | required | The input text for which the reading duration is to be calculated |
|
|
925
|
+
| readingSpeed | number | 230 | The reading speed in words per minute. Defaults to 230 (average reading speed) |
|
|
583
926
|
|
|
584
927
|
#### <a id="wordcount"></a>`wordCount(text)`
|
|
585
928
|
|
|
@@ -590,9 +933,9 @@ wordCount('Hello world'); // 2
|
|
|
590
933
|
wordCount(''); // 0
|
|
591
934
|
```
|
|
592
935
|
|
|
593
|
-
| Parameter | Type
|
|
594
|
-
|
|
595
|
-
| text
|
|
936
|
+
| Parameter | Type | Default | Description |
|
|
937
|
+
| --------- | ------ | -------- | ---------------------------------- |
|
|
938
|
+
| text | string | required | The input string to count words in |
|
|
596
939
|
|
|
597
940
|
#### <a id="charactercount"></a>`characterCount(text)`
|
|
598
941
|
|
|
@@ -602,9 +945,9 @@ Counts the number of characters in a string.
|
|
|
602
945
|
characterCount('Hello'); // 5
|
|
603
946
|
```
|
|
604
947
|
|
|
605
|
-
| Parameter | Type
|
|
606
|
-
|
|
607
|
-
| text
|
|
948
|
+
| Parameter | Type | Default | Description |
|
|
949
|
+
| --------- | ------ | -------- | --------------------------------------- |
|
|
950
|
+
| text | string | required | The input string to count characters in |
|
|
608
951
|
|
|
609
952
|
#### <a id="characterfrequency"></a>`characterFrequency(text)`
|
|
610
953
|
|
|
@@ -614,14 +957,15 @@ Analyzes character frequency in a string (excluding spaces).
|
|
|
614
957
|
characterFrequency('hello'); // { h: 1, e: 1, l: 2, o: 1 }
|
|
615
958
|
```
|
|
616
959
|
|
|
617
|
-
| Parameter | Type
|
|
618
|
-
|
|
619
|
-
| text
|
|
960
|
+
| Parameter | Type | Default | Description |
|
|
961
|
+
| --------- | ------ | -------- | ----------------------------------------------- |
|
|
962
|
+
| text | string | required | The input string to analyze character frequency |
|
|
620
963
|
|
|
621
964
|
#### <a id="stringsimilarity"></a>`stringSimilarity(textA, textB, algorithm = 'Levenshtein')`
|
|
622
965
|
|
|
623
966
|
Calculates the percentage similarity between two texts using the selected algorithm.
|
|
624
967
|
Method returns a percentage (0–100) value indicating how similar the two strings are.
|
|
968
|
+
|
|
625
969
|
```javascript
|
|
626
970
|
stringSimilarity('kitten', 'sitting'); // Returns: 57.14
|
|
627
971
|
|
|
@@ -630,11 +974,219 @@ stringSimilarity('hello', 'hello'); // Returns: 100
|
|
|
630
974
|
stringSimilarity('flaw', 'lawn', 'Damerau-Levenshtein'); // Returns: 50
|
|
631
975
|
```
|
|
632
976
|
|
|
633
|
-
| Parameter
|
|
634
|
-
|
|
635
|
-
| textA
|
|
636
|
-
| textB
|
|
637
|
-
| algorithm
|
|
977
|
+
| Parameter | Type | Default | Description |
|
|
978
|
+
| --------- | ------ | ------------- | ------------------------------------------------------------- |
|
|
979
|
+
| textA | string | required | The first text to compare. |
|
|
980
|
+
| textB | string | required | The second text to compare. |
|
|
981
|
+
| algorithm | string | 'Levenshtein' | The algorithm to use: 'Levenshtein' or 'Damerau-Levenshtein'. |
|
|
982
|
+
|
|
983
|
+
#### <a id="complexity"></a>`complexity(text)`
|
|
984
|
+
|
|
985
|
+
Analyzes the complexity of a string, returning an object with detailed metrics.
|
|
986
|
+
|
|
987
|
+
```javascript
|
|
988
|
+
import { complexity } from 'stringzy';
|
|
989
|
+
|
|
990
|
+
complexity('abc');
|
|
991
|
+
// Returns: { score: [number], uniqueness: [number], length: 3 }
|
|
992
|
+
|
|
993
|
+
complexity('aA1!aA1!');
|
|
994
|
+
// Returns: { score: [number], uniqueness: [number], length: 8 }
|
|
995
|
+
|
|
996
|
+
complexity('');
|
|
997
|
+
// Returns: { score: 0, uniqueness: 0, length: 0 }
|
|
998
|
+
```
|
|
999
|
+
|
|
1000
|
+
| Parameter | Type | Default | Description |
|
|
1001
|
+
| --------- | ------ | -------- | -------------------------------------- |
|
|
1002
|
+
| text | string | required | The input string to analyze complexity |
|
|
1003
|
+
|
|
1004
|
+
**Returns:** An object containing:
|
|
1005
|
+
|
|
1006
|
+
- `score` (number): Overall complexity score
|
|
1007
|
+
- `uniqueness` (number): Measure of character uniqueness
|
|
1008
|
+
- `length` (number): Length of the input string
|
|
1009
|
+
|
|
1010
|
+
feature/content-words
|
|
1011
|
+
|
|
1012
|
+
#### <a id="contentwordcount"></a>`contentWordCount(text)`
|
|
1013
|
+
|
|
1014
|
+
Counts the number of content words (nouns, verbs, adjectives, adverbs, etc.) in a string.
|
|
1015
|
+
|
|
1016
|
+
```javascript
|
|
1017
|
+
|
|
1018
|
+
import { contentWordCount } from 'stringzy';
|
|
1019
|
+
|
|
1020
|
+
contentWordCount("Learning JavaScript improves coding skills!");
|
|
1021
|
+
// Returns: { count: 5 }
|
|
1022
|
+
|
|
1023
|
+
contentWordCount("The cat sleeps on the warm windowsill.");
|
|
1024
|
+
// Returns: { count: 5 }
|
|
1025
|
+
|
|
1026
|
+
contentWordCount("Wow! Such a beautiful day.");
|
|
1027
|
+
// Returns: { count: 4 }
|
|
1028
|
+
```
|
|
1029
|
+
|
|
1030
|
+
| Parameter | Type | Default | Description |
|
|
1031
|
+
| --------- | ------ | -------- | -------------------------------------- |
|
|
1032
|
+
| text | string | required | The input string to analyze content words |
|
|
1033
|
+
|
|
1034
|
+
**Returns:** An object containing:
|
|
1035
|
+
|
|
1036
|
+
- `count` (number): Total number of content words in the string
|
|
1037
|
+
|
|
1038
|
+
|
|
1039
|
+
#### <a id="functionwordcount"></a>`functionWordCount(text)`
|
|
1040
|
+
|
|
1041
|
+
Counts the number of function words (prepositions, pronouns, conjunctions, articles, etc.) in a string.
|
|
1042
|
+
|
|
1043
|
+
```javascript
|
|
1044
|
+
|
|
1045
|
+
import { functionWordCount } from 'stringzy';
|
|
1046
|
+
|
|
1047
|
+
functionWordCount("She and I are going to the park.");
|
|
1048
|
+
// Returns: { count: 7 }
|
|
1049
|
+
|
|
1050
|
+
functionWordCount("It is an example of proper grammar usage.");
|
|
1051
|
+
// Returns: { count: 8 }
|
|
1052
|
+
|
|
1053
|
+
functionWordCount("Can you see the stars tonight?");
|
|
1054
|
+
// Returns: { count: 5 }
|
|
1055
|
+
```
|
|
1056
|
+
|
|
1057
|
+
| Parameter | Type | Default | Description |
|
|
1058
|
+
| --------- | ------ | -------- | -------------------------------------- |
|
|
1059
|
+
| text | string | required | The input string to analyze function words |
|
|
1060
|
+
|
|
1061
|
+
**Returns:** An object containing:
|
|
1062
|
+
|
|
1063
|
+
- `count` (number): Total number of function words in the string
|
|
1064
|
+
|
|
1065
|
+
#### <a id="patterncount"></a>`patternCount(text, pattern)`
|
|
1066
|
+
|
|
1067
|
+
Counts the number of times a substring (pattern) occurs in a string, including overlapping occurrences.
|
|
1068
|
+
This function uses the **Knuth–Morris–Pratt (KMP)** algorithm for efficient matching.
|
|
1069
|
+
|
|
1070
|
+
```javascript
|
|
1071
|
+
patternCount('aaaa', 'aa'); // 3
|
|
1072
|
+
patternCount('abababa', 'aba'); // 3
|
|
1073
|
+
patternCount('hello world', 'o'); // 2
|
|
1074
|
+
patternCount('hello world', 'x'); // 0
|
|
1075
|
+
```
|
|
1076
|
+
|
|
1077
|
+
| Parameter | Type | Default | Description |
|
|
1078
|
+
| --------- | ------ | -------- | ---------------------------------------------- |
|
|
1079
|
+
| text | string | required | The input string to search in |
|
|
1080
|
+
| pattern | string | required | The substring (pattern) to count (overlapping) |
|
|
1081
|
+
|
|
1082
|
+
#### <a id="vowelconsonantcount"></a>`vowelConsonantCount(str)`
|
|
1083
|
+
|
|
1084
|
+
Counts the number of vowels and consonants in a given string.
|
|
1085
|
+
This function is case-insensitive and ignores non-alphabetic characters.
|
|
1086
|
+
|
|
1087
|
+
```javascript
|
|
1088
|
+
vowelConsonantCount('hello');
|
|
1089
|
+
// { vowels: 2, consonants: 3 }
|
|
1090
|
+
|
|
1091
|
+
vowelConsonantCount('stringzy');
|
|
1092
|
+
// { vowels: 1, consonants: 7 }
|
|
1093
|
+
|
|
1094
|
+
vowelConsonantCount('');
|
|
1095
|
+
// { vowels: 0, consonants: 0 }
|
|
1096
|
+
```
|
|
1097
|
+
|
|
1098
|
+
| Parameter | Type | Default | Description |
|
|
1099
|
+
| --------- | ------ | -------- | -------------------------------------------------- |
|
|
1100
|
+
| str | string | required | The input string to count vowels and consonants in |
|
|
1101
|
+
|
|
1102
|
+
feature/content-words
|
|
1103
|
+
|
|
1104
|
+
#### <a id="checkmultiplepatterns"></a>`checkMultiplePatterns(text, patterns)`
|
|
1105
|
+
|
|
1106
|
+
Finds occurrences of multiple patterns within a given text using the Rabin–Karp algorithm. <br>
|
|
1107
|
+
Accepts an array of patterns.<br>
|
|
1108
|
+
Returns all matches of each pattern along with starting indices.<br>
|
|
1109
|
+
Handles hash collisions by verifying actual substrings.<br>
|
|
1110
|
+
Pattern matching is case sensitive.
|
|
1111
|
+
|
|
1112
|
+
```javascript
|
|
1113
|
+
checkMultiplePatterns('abracadabra', ['abra', 'cad']);
|
|
1114
|
+
// { abra: [0, 7], cad: [4] }
|
|
1115
|
+
|
|
1116
|
+
checkMultiplePatterns('aaaa', ['aa', 'aaa']);
|
|
1117
|
+
// { aa: [0, 1, 2], aaa: [0, 1] }
|
|
1118
|
+
|
|
1119
|
+
checkMultiplePatterns('hello world', ['xyz', '123']);
|
|
1120
|
+
// { xyz: [], 123: [] }
|
|
1121
|
+
```
|
|
1122
|
+
| Parameter | Type | Default | Description |
|
|
1123
|
+
| --------- | --------- | -------- | ----------------------------------------------------------- |
|
|
1124
|
+
| text | string | required | The text to search within. |
|
|
1125
|
+
| patterns | string\[ ] | required | An array of patterns to search for (each must be a string). |
|
|
1126
|
+
|
|
1127
|
+
#### <a id="checksubsequence"></a>`checkSubsequence(str, sub)`
|
|
1128
|
+
|
|
1129
|
+
Checks whether a given string sub is a subsequence of another string str.
|
|
1130
|
+
A subsequence maintains the relative order of characters, but they do not need to be consecutive.
|
|
1131
|
+
Case-sensitive comparison is performed.
|
|
1132
|
+
Spaces and all characters are treated literally.
|
|
1133
|
+
|
|
1134
|
+
```javascript
|
|
1135
|
+
isSubsequence('abcde', 'ace');
|
|
1136
|
+
// true → 'a', 'c', 'e' appear in order
|
|
1137
|
+
|
|
1138
|
+
isSubsequence('abracadabra', 'aaa');
|
|
1139
|
+
// true → multiple 'a's in correct order
|
|
1140
|
+
|
|
1141
|
+
isSubsequence('abcde', 'aec');
|
|
1142
|
+
// false → order is broken (e comes before c)
|
|
1143
|
+
|
|
1144
|
+
isSubsequence('anything', '');
|
|
1145
|
+
// true → empty subsequence is always valid
|
|
1146
|
+
|
|
1147
|
+
isSubsequence('AbC', 'AC');
|
|
1148
|
+
// true → exact case matches
|
|
1149
|
+
|
|
1150
|
+
isSubsequence('a b c', 'abc');
|
|
1151
|
+
// false → spaces count as characters
|
|
1152
|
+
```
|
|
1153
|
+
| Parameter | Type | Default | Description |
|
|
1154
|
+
| --------- | ------ | -------- | ----------------------------------------------- |
|
|
1155
|
+
| str | string | required | The main string to check within. |
|
|
1156
|
+
| sub | string | required | The subsequence string to verify against `str`. |
|
|
1157
|
+
|
|
1158
|
+
#### <a id="stringrotation"></a>`checkStringRotations(str1, str2)`
|
|
1159
|
+
Checks whether a given string `str2` is a rotation of another string `str1`.
|
|
1160
|
+
Case-sensitive comparison is performed. Both strings must be of equal length to be considered rotations.
|
|
1161
|
+
Spaces and all characters are treated literally.
|
|
1162
|
+
|
|
1163
|
+
```javascript
|
|
1164
|
+
isRotation('waterbottle', 'erbottlewat');
|
|
1165
|
+
// true → rotation at position 3
|
|
1166
|
+
|
|
1167
|
+
isRotation('abcde', 'cdeab');
|
|
1168
|
+
// true → rotation at position 2
|
|
1169
|
+
|
|
1170
|
+
isRotation('abc', 'abc');
|
|
1171
|
+
// true → no rotation, identical strings
|
|
1172
|
+
|
|
1173
|
+
isRotation('abc', 'cab');
|
|
1174
|
+
// true → rotation at position 2
|
|
1175
|
+
|
|
1176
|
+
isRotation('abc', 'bac');
|
|
1177
|
+
// false → not a valid rotation
|
|
1178
|
+
|
|
1179
|
+
isRotation('ArB', 'Bar');
|
|
1180
|
+
// false → case-sensitive mismatch
|
|
1181
|
+
|
|
1182
|
+
isRotation('abcd', 'abc');
|
|
1183
|
+
// false → lengths differ
|
|
1184
|
+
```
|
|
1185
|
+
|
|
1186
|
+
| Parameter | Type | Default | Description |
|
|
1187
|
+
| --------- | ------ | -------- | --------------------------------------------------- |
|
|
1188
|
+
| str1 | string | required | The original string. |
|
|
1189
|
+
| str2 | string | required | The string to verify if it is a rotation of `str1`. |
|
|
638
1190
|
|
|
639
1191
|
---
|
|
640
1192
|
|
|
@@ -651,9 +1203,9 @@ capitalize('hello world'); // 'Hello World'
|
|
|
651
1203
|
capitalize('javaScript programming'); // 'Javascript Programming'
|
|
652
1204
|
```
|
|
653
1205
|
|
|
654
|
-
| Parameter | Type
|
|
655
|
-
|
|
656
|
-
| text
|
|
1206
|
+
| Parameter | Type | Default | Description |
|
|
1207
|
+
| --------- | ------ | -------- | ------------------------------ |
|
|
1208
|
+
| text | string | required | The input string to capitalize |
|
|
657
1209
|
|
|
658
1210
|
#### <a id="formatnumber"></a>`formatNumber(number, separator = ',')`
|
|
659
1211
|
|
|
@@ -664,10 +1216,10 @@ formatNumber('1234567'); // '1,234,567'
|
|
|
664
1216
|
formatNumber('1234567', '.'); // '1.234.567'
|
|
665
1217
|
```
|
|
666
1218
|
|
|
667
|
-
| Parameter | Type
|
|
668
|
-
|
|
669
|
-
| number
|
|
670
|
-
| separator | string
|
|
1219
|
+
| Parameter | Type | Default | Description |
|
|
1220
|
+
| --------- | -------------- | -------- | ---------------------------------- |
|
|
1221
|
+
| number | string\|number | required | The number to format |
|
|
1222
|
+
| separator | string | ',' | The separator to use for thousands |
|
|
671
1223
|
|
|
672
1224
|
#### <a id="formatphone"></a>`formatPhone(phone, format = 'us')`
|
|
673
1225
|
|
|
@@ -678,14 +1230,15 @@ formatPhone('1234567890'); // '(123) 456-7890'
|
|
|
678
1230
|
formatPhone('11234567890', 'international'); // '+1 (123) 456-7890'
|
|
679
1231
|
```
|
|
680
1232
|
|
|
681
|
-
| Parameter | Type
|
|
682
|
-
|
|
683
|
-
| phone
|
|
684
|
-
| format
|
|
1233
|
+
| Parameter | Type | Default | Description |
|
|
1234
|
+
| --------- | ------ | -------- | ------------------------------------ |
|
|
1235
|
+
| phone | string | required | The phone number string to format |
|
|
1236
|
+
| format | string | 'us' | Format type: 'us' or 'international' |
|
|
685
1237
|
|
|
686
1238
|
## 🔧 Usage Patterns
|
|
687
1239
|
|
|
688
1240
|
### Individual Function Imports
|
|
1241
|
+
|
|
689
1242
|
```javascript
|
|
690
1243
|
import { isEmail, wordCount, capitalize } from 'stringzy';
|
|
691
1244
|
|
|
@@ -696,6 +1249,7 @@ if (isEmail(email)) {
|
|
|
696
1249
|
```
|
|
697
1250
|
|
|
698
1251
|
### Namespace Imports
|
|
1252
|
+
|
|
699
1253
|
```javascript
|
|
700
1254
|
import { validate, analyze, format } from 'stringzy';
|
|
701
1255
|
|
|
@@ -706,6 +1260,7 @@ const formatted = format.capitalize('hello world');
|
|
|
706
1260
|
```
|
|
707
1261
|
|
|
708
1262
|
### Default Import (All Functions)
|
|
1263
|
+
|
|
709
1264
|
```javascript
|
|
710
1265
|
import stringzy from 'stringzy';
|
|
711
1266
|
|
|
@@ -746,19 +1301,19 @@ import { validate } from 'stringzy';
|
|
|
746
1301
|
|
|
747
1302
|
function validateForm(formData) {
|
|
748
1303
|
const errors = {};
|
|
749
|
-
|
|
1304
|
+
|
|
750
1305
|
if (!validate.isEmail(formData.email)) {
|
|
751
1306
|
errors.email = 'Please enter a valid email address';
|
|
752
1307
|
}
|
|
753
|
-
|
|
1308
|
+
|
|
754
1309
|
if (!validate.isURL(formData.website)) {
|
|
755
1310
|
errors.website = 'Please enter a valid URL';
|
|
756
1311
|
}
|
|
757
|
-
|
|
1312
|
+
|
|
758
1313
|
if (validate.isEmpty(formData.name)) {
|
|
759
1314
|
errors.name = 'Name is required';
|
|
760
1315
|
}
|
|
761
|
-
|
|
1316
|
+
|
|
762
1317
|
return errors;
|
|
763
1318
|
}
|
|
764
1319
|
```
|
|
@@ -773,7 +1328,7 @@ function getContentStats(text) {
|
|
|
773
1328
|
words: analyze.wordCount(text),
|
|
774
1329
|
characters: analyze.characterCount(text),
|
|
775
1330
|
frequency: analyze.characterFrequency(text),
|
|
776
|
-
readingTime: Math.ceil(analyze.wordCount(text) / 200)
|
|
1331
|
+
readingTime: Math.ceil(analyze.wordCount(text) / 200),
|
|
777
1332
|
};
|
|
778
1333
|
}
|
|
779
1334
|
```
|
|
@@ -787,7 +1342,7 @@ function formatUserData(userData) {
|
|
|
787
1342
|
return {
|
|
788
1343
|
name: format.capitalize(userData.name),
|
|
789
1344
|
phone: format.formatPhone(userData.phone),
|
|
790
|
-
revenue: format.formatNumber(userData.revenue)
|
|
1345
|
+
revenue: format.formatNumber(userData.revenue),
|
|
791
1346
|
};
|
|
792
1347
|
}
|
|
793
1348
|
```
|
|
@@ -810,7 +1365,7 @@ const formatted: string = format.capitalize('hello world');
|
|
|
810
1365
|
stringzy is organized into four specialized modules:
|
|
811
1366
|
|
|
812
1367
|
- **`transformations.js`** - Core string transformations
|
|
813
|
-
- **`validations.js`** - String validation utilities
|
|
1368
|
+
- **`validations.js`** - String validation utilities
|
|
814
1369
|
- **`analysis.js`** - String analysis and metrics
|
|
815
1370
|
- **`formatting.js`** - String formatting functions
|
|
816
1371
|
|
|
@@ -820,7 +1375,6 @@ Each module can be imported individually or accessed through the main entry poin
|
|
|
820
1375
|
|
|
821
1376
|
Contributions are welcome! Please read our [contribution guidelines](CONTRIBUTING.md) before submitting a pull request.
|
|
822
1377
|
|
|
823
|
-
|
|
824
1378
|
## <a id="contri"></a>`Contributors`
|
|
825
1379
|
|
|
826
1380
|
<table>
|
|
@@ -928,6 +1482,100 @@ Contributions are welcome! Please read our [contribution guidelines](CONTRIBUTIN
|
|
|
928
1482
|
</sub>
|
|
929
1483
|
</a>
|
|
930
1484
|
</td>
|
|
1485
|
+
<td align="center">
|
|
1486
|
+
<a href="https://github.com/Thenlie">
|
|
1487
|
+
<img src="https://avatars.githubusercontent.com/Thenlie" width="100px;"
|
|
1488
|
+
alt="Thenlie" />
|
|
1489
|
+
<br />
|
|
1490
|
+
<sub>
|
|
1491
|
+
<b>Leithen</b>
|
|
1492
|
+
</sub>
|
|
1493
|
+
</a>
|
|
1494
|
+
</td>
|
|
1495
|
+
<td align="center">
|
|
1496
|
+
<a href="https://github.com/rickyryden">
|
|
1497
|
+
<img src="https://avatars.githubusercontent.com/rickyryden" width="100px;"
|
|
1498
|
+
alt="Ricky Ryden" />
|
|
1499
|
+
<br />
|
|
1500
|
+
<sub>
|
|
1501
|
+
<b>Ricky Ryden</b>
|
|
1502
|
+
</sub>
|
|
1503
|
+
</a>
|
|
1504
|
+
</td>
|
|
1505
|
+
</tr>
|
|
1506
|
+
<tr>
|
|
1507
|
+
<td align="center">
|
|
1508
|
+
<a href="https://github.com/adityaatre26">
|
|
1509
|
+
<img src="https://avatars.githubusercontent.com/adityaatre26" width="100px;"
|
|
1510
|
+
alt="Aditya Atre" />
|
|
1511
|
+
<br />
|
|
1512
|
+
<sub>
|
|
1513
|
+
<b>Aditya Atre</b>
|
|
1514
|
+
</sub>
|
|
1515
|
+
</a>
|
|
1516
|
+
</td>
|
|
1517
|
+
<td align="center">
|
|
1518
|
+
<a href="https://github.com/kittenwarrior-qb">
|
|
1519
|
+
<img src="https://avatars.githubusercontent.com/kittenwarrior-qb" width="100px;"
|
|
1520
|
+
alt="quocbui05" />
|
|
1521
|
+
<br />
|
|
1522
|
+
<sub>
|
|
1523
|
+
<b>quocbui05</b>
|
|
1524
|
+
</sub>
|
|
1525
|
+
</a>
|
|
1526
|
+
</td>
|
|
1527
|
+
<td align="center">
|
|
1528
|
+
<a href="https://github.com/MariamEwas">
|
|
1529
|
+
<img src="https://avatars.githubusercontent.com/MariamEwas" width="100px;"
|
|
1530
|
+
alt="Mariam Hasan" />
|
|
1531
|
+
<br />
|
|
1532
|
+
<sub>
|
|
1533
|
+
<b>Mariam Hasan</b>
|
|
1534
|
+
</sub>
|
|
1535
|
+
</a>
|
|
1536
|
+
</td>
|
|
1537
|
+
<td align="center">
|
|
1538
|
+
<a href="https://github.com/milendrakumarbaghel">
|
|
1539
|
+
<img src="https://avatars.githubusercontent.com/milendrakumarbaghel" width="100px;"
|
|
1540
|
+
alt="Milendra Kumar Baghel" />
|
|
1541
|
+
<br />
|
|
1542
|
+
<sub>
|
|
1543
|
+
<b>Milendra Kumar Baghel</b>
|
|
1544
|
+
</sub>
|
|
1545
|
+
</a>
|
|
1546
|
+
</td>
|
|
1547
|
+
<td align="center">
|
|
1548
|
+
<a href="https://github.com/Farkhanda-Dalal">
|
|
1549
|
+
<img src="https://avatars.githubusercontent.com/Farkhanda-Dalal" width="100px;"
|
|
1550
|
+
alt="Farkhanda Dalal" />
|
|
1551
|
+
<br />
|
|
1552
|
+
<sub>
|
|
1553
|
+
<b>Farkhanda Dalal</b>
|
|
1554
|
+
</sub>
|
|
1555
|
+
</a>
|
|
1556
|
+
</td>
|
|
1557
|
+
<td align="center">
|
|
1558
|
+
<a href="https://github.com/S">
|
|
1559
|
+
<img src="https://avatars.githubusercontent.com/satyasrisundarapalli" width="100px;"
|
|
1560
|
+
alt="Sundarapalli Lakshmi Satya Sri" />
|
|
1561
|
+
<br />
|
|
1562
|
+
<sub>
|
|
1563
|
+
<b>Sundarapalli Lakshmi Satya Sri</b>
|
|
1564
|
+
</sub>
|
|
1565
|
+
</a>
|
|
1566
|
+
</td>
|
|
1567
|
+
</tr>
|
|
1568
|
+
<tr>
|
|
1569
|
+
<td align="center">
|
|
1570
|
+
<a href="https://github.com/S">
|
|
1571
|
+
<img src="https://avatars.githubusercontent.com/itspavant" width="100px;"
|
|
1572
|
+
alt="T Pavan Teja" />
|
|
1573
|
+
<br />
|
|
1574
|
+
<sub>
|
|
1575
|
+
<b>T Pavan Teja</b>
|
|
1576
|
+
</sub>
|
|
1577
|
+
</a>
|
|
1578
|
+
</td>
|
|
931
1579
|
</tr>
|
|
932
1580
|
</tbody>
|
|
933
1581
|
</table>
|