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
|
@@ -1 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Removes special characters from a string, replacing them with a specified string.
|
|
3
|
+
*
|
|
4
|
+
* Special characters are any characters except alphanumeric (`a-z`, `A-Z`, `0-9`) and whitespace.
|
|
5
|
+
* The default replacement is an empty string, effectively removing these characters.
|
|
6
|
+
*
|
|
7
|
+
* Throws an error if the input `text` or `replacement` is not a string.
|
|
8
|
+
*
|
|
9
|
+
* @param {string} text - The input string to process.
|
|
10
|
+
* @param {string} [replacement=''] - The string to replace special characters with.
|
|
11
|
+
* @returns {string} The processed string with special characters replaced.
|
|
12
|
+
* @throws {TypeError} If `text` or `replacement` is not a string.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* removeSpecialChars("Hello, World!"); // "Hello World"
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* removeSpecialChars("Special #$% chars", '_'); // "Special ___ chars"
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* removeSpecialChars("CleanText123"); // "CleanText123"
|
|
22
|
+
*/
|
|
1
23
|
export declare function removeSpecialChars(text: string, replacement?: string): string;
|
|
@@ -1,12 +1,34 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.removeSpecialChars = removeSpecialChars;
|
|
4
|
+
/**
|
|
5
|
+
* Removes special characters from a string, replacing them with a specified string.
|
|
6
|
+
*
|
|
7
|
+
* Special characters are any characters except alphanumeric (`a-z`, `A-Z`, `0-9`) and whitespace.
|
|
8
|
+
* The default replacement is an empty string, effectively removing these characters.
|
|
9
|
+
*
|
|
10
|
+
* Throws an error if the input `text` or `replacement` is not a string.
|
|
11
|
+
*
|
|
12
|
+
* @param {string} text - The input string to process.
|
|
13
|
+
* @param {string} [replacement=''] - The string to replace special characters with.
|
|
14
|
+
* @returns {string} The processed string with special characters replaced.
|
|
15
|
+
* @throws {TypeError} If `text` or `replacement` is not a string.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* removeSpecialChars("Hello, World!"); // "Hello World"
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* removeSpecialChars("Special #$% chars", '_'); // "Special ___ chars"
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* removeSpecialChars("CleanText123"); // "CleanText123"
|
|
25
|
+
*/
|
|
4
26
|
function removeSpecialChars(text, replacement = '') {
|
|
5
|
-
if (typeof text !==
|
|
6
|
-
throw new
|
|
27
|
+
if (typeof text !== 'string') {
|
|
28
|
+
throw new TypeError('Invalid argument. Expected a string.');
|
|
7
29
|
}
|
|
8
|
-
if (typeof replacement !==
|
|
9
|
-
throw new
|
|
30
|
+
if (typeof replacement !== 'string') {
|
|
31
|
+
throw new TypeError('Replacement must be a string.');
|
|
10
32
|
}
|
|
11
33
|
return text.replace(/[^\w\s]/gi, replacement);
|
|
12
34
|
}
|
|
@@ -1 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Removes specified word(s) from a given string.
|
|
3
|
+
*
|
|
4
|
+
* The function accepts either a single word as a string or an array of words to remove.
|
|
5
|
+
* It removes whole word matches case-insensitively, preserving spacing by collapsing
|
|
6
|
+
* multiple spaces into a single space and trimming the result.
|
|
7
|
+
*
|
|
8
|
+
* Throws `TypeError` if inputs are invalid or missing.
|
|
9
|
+
*
|
|
10
|
+
* @param {string} str - The input string from which words will be removed.
|
|
11
|
+
* @param {string | string[]} wordsToRemove - A word or array of words to remove from the input string.
|
|
12
|
+
* @returns {string} The string after removing the specified words.
|
|
13
|
+
* @throws {TypeError} If `str` is null, undefined, or not a string.
|
|
14
|
+
* @throws {TypeError} If `wordsToRemove` is null, undefined, or not a string or array of strings.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* removeWords("The quick brown fox jumps", "quick");
|
|
18
|
+
* // "The brown fox jumps"
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* removeWords("The quick brown fox jumps over the lazy dog", ["quick", "lazy"]);
|
|
22
|
+
* // "The brown fox jumps over the dog"
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* removeWords("Hello world", "world");
|
|
26
|
+
* // "Hello"
|
|
27
|
+
*/
|
|
1
28
|
export declare function removeWords(str: string, wordsToRemove: string | string[]): string;
|
|
@@ -1,18 +1,45 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.removeWords = removeWords;
|
|
4
|
+
/**
|
|
5
|
+
* Removes specified word(s) from a given string.
|
|
6
|
+
*
|
|
7
|
+
* The function accepts either a single word as a string or an array of words to remove.
|
|
8
|
+
* It removes whole word matches case-insensitively, preserving spacing by collapsing
|
|
9
|
+
* multiple spaces into a single space and trimming the result.
|
|
10
|
+
*
|
|
11
|
+
* Throws `TypeError` if inputs are invalid or missing.
|
|
12
|
+
*
|
|
13
|
+
* @param {string} str - The input string from which words will be removed.
|
|
14
|
+
* @param {string | string[]} wordsToRemove - A word or array of words to remove from the input string.
|
|
15
|
+
* @returns {string} The string after removing the specified words.
|
|
16
|
+
* @throws {TypeError} If `str` is null, undefined, or not a string.
|
|
17
|
+
* @throws {TypeError} If `wordsToRemove` is null, undefined, or not a string or array of strings.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* removeWords("The quick brown fox jumps", "quick");
|
|
21
|
+
* // "The brown fox jumps"
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* removeWords("The quick brown fox jumps over the lazy dog", ["quick", "lazy"]);
|
|
25
|
+
* // "The brown fox jumps over the dog"
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* removeWords("Hello world", "world");
|
|
29
|
+
* // "Hello"
|
|
30
|
+
*/
|
|
4
31
|
function removeWords(str, wordsToRemove) {
|
|
5
32
|
if (str === null || str === undefined) {
|
|
6
|
-
throw new
|
|
33
|
+
throw new TypeError('Input string cannot be null or undefined');
|
|
7
34
|
}
|
|
8
35
|
if (typeof str !== 'string') {
|
|
9
|
-
throw new
|
|
36
|
+
throw new TypeError('First parameter must be a string');
|
|
10
37
|
}
|
|
11
38
|
if (wordsToRemove === null || wordsToRemove === undefined) {
|
|
12
|
-
throw new
|
|
39
|
+
throw new TypeError('Words to remove cannot be null or undefined');
|
|
13
40
|
}
|
|
14
41
|
if (typeof wordsToRemove !== 'string' && !Array.isArray(wordsToRemove)) {
|
|
15
|
-
throw new
|
|
42
|
+
throw new TypeError('Second parameter must be a string or an array of strings');
|
|
16
43
|
}
|
|
17
44
|
if (str === '') {
|
|
18
45
|
return '';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reverses the order of words in a given string while preserving the
|
|
3
|
+
* exact spacing (including multiple spaces) between them.
|
|
4
|
+
*
|
|
5
|
+
* @param {string} str - The input string whose words are to be reversed.
|
|
6
|
+
* @returns {string} The string with the order of words reversed and all original spacing intact.
|
|
7
|
+
* @throws {TypeError} If the input is not a string.
|
|
8
|
+
*/
|
|
9
|
+
export declare function reverseWordsInString(str: string): string;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.reverseWordsInString = reverseWordsInString;
|
|
4
|
+
/**
|
|
5
|
+
* Reverses the order of words in a given string while preserving the
|
|
6
|
+
* exact spacing (including multiple spaces) between them.
|
|
7
|
+
*
|
|
8
|
+
* @param {string} str - The input string whose words are to be reversed.
|
|
9
|
+
* @returns {string} The string with the order of words reversed and all original spacing intact.
|
|
10
|
+
* @throws {TypeError} If the input is not a string.
|
|
11
|
+
*/
|
|
12
|
+
function reverseWordsInString(str) {
|
|
13
|
+
if (typeof str !== 'string') {
|
|
14
|
+
throw new TypeError('Input must be a string');
|
|
15
|
+
}
|
|
16
|
+
// 1. Extract all blocks of non-whitespace characters (the words).
|
|
17
|
+
const words = str.match(/\S+/g) || [];
|
|
18
|
+
// 2. If there are no words (e.g., empty or whitespace-only string), return the original string.
|
|
19
|
+
if (words.length === 0) {
|
|
20
|
+
return str;
|
|
21
|
+
}
|
|
22
|
+
// 3. Extract all blocks of whitespace.
|
|
23
|
+
const spaces = str.match(/\s+/g) || [];
|
|
24
|
+
// 4. Reverse ONLY the array of words.
|
|
25
|
+
const reversedWords = words.reverse();
|
|
26
|
+
// 5. Stitch the reversed words and original spaces back together.
|
|
27
|
+
let result = '';
|
|
28
|
+
const startsWithSpace = /^\s/.test(str);
|
|
29
|
+
if (startsWithSpace) {
|
|
30
|
+
// If the string starts with a space, the pattern is: space, word, space, word...
|
|
31
|
+
for (let i = 0; i < reversedWords.length; i++) {
|
|
32
|
+
result += spaces[i] + reversedWords[i];
|
|
33
|
+
}
|
|
34
|
+
// Append any final trailing space block.
|
|
35
|
+
if (spaces.length > reversedWords.length) {
|
|
36
|
+
result += spaces[spaces.length - 1];
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
// If the string starts with a word, the pattern is: word, space, word, space...
|
|
41
|
+
for (let i = 0; i < reversedWords.length; i++) {
|
|
42
|
+
result += reversedWords[i];
|
|
43
|
+
if (spaces[i]) {
|
|
44
|
+
result += spaces[i];
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return result;
|
|
49
|
+
}
|
|
@@ -1 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a given string to snake_case format.
|
|
3
|
+
*
|
|
4
|
+
* The transformation includes:
|
|
5
|
+
* - Trimming whitespace from both ends.
|
|
6
|
+
* - Replacing spaces and hyphens with underscores.
|
|
7
|
+
* - Inserting underscores between lowercase and uppercase letter boundaries (e.g., `fooBar` → `foo_bar`).
|
|
8
|
+
* - Replacing all non-word characters (except underscores) with underscores.
|
|
9
|
+
* - Converting the entire string to lowercase.
|
|
10
|
+
* - Collapsing multiple consecutive underscores into one.
|
|
11
|
+
* - Removing leading and trailing underscores.
|
|
12
|
+
*
|
|
13
|
+
* If the input is `null` or `undefined`, it returns an empty string.
|
|
14
|
+
*
|
|
15
|
+
* @param {string} text - The input string to convert.
|
|
16
|
+
* @returns {string} The snake_case formatted string.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* snakeCase("Hello World"); // "hello_world"
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* snakeCase("camelCaseText"); // "camel_case_text"
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* snakeCase(" convert-to--snake.case! "); // "convert_to_snake_case"
|
|
26
|
+
*/
|
|
1
27
|
export declare function snakeCase(text: string): string;
|
|
@@ -1,6 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.snakeCase = snakeCase;
|
|
4
|
+
/**
|
|
5
|
+
* Converts a given string to snake_case format.
|
|
6
|
+
*
|
|
7
|
+
* The transformation includes:
|
|
8
|
+
* - Trimming whitespace from both ends.
|
|
9
|
+
* - Replacing spaces and hyphens with underscores.
|
|
10
|
+
* - Inserting underscores between lowercase and uppercase letter boundaries (e.g., `fooBar` → `foo_bar`).
|
|
11
|
+
* - Replacing all non-word characters (except underscores) with underscores.
|
|
12
|
+
* - Converting the entire string to lowercase.
|
|
13
|
+
* - Collapsing multiple consecutive underscores into one.
|
|
14
|
+
* - Removing leading and trailing underscores.
|
|
15
|
+
*
|
|
16
|
+
* If the input is `null` or `undefined`, it returns an empty string.
|
|
17
|
+
*
|
|
18
|
+
* @param {string} text - The input string to convert.
|
|
19
|
+
* @returns {string} The snake_case formatted string.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* snakeCase("Hello World"); // "hello_world"
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* snakeCase("camelCaseText"); // "camel_case_text"
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* snakeCase(" convert-to--snake.case! "); // "convert_to_snake_case"
|
|
29
|
+
*/
|
|
4
30
|
function snakeCase(text) {
|
|
5
31
|
if (text == null)
|
|
6
32
|
return '';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates chunks of string based on a given chunk size
|
|
3
|
+
* @param text - Input string
|
|
4
|
+
* @param Number - Size of the chunk. Must be a positive integer. Defaults to 1.
|
|
5
|
+
* @returns An array of all the chunks created from the string based on the specified chunk size.
|
|
6
|
+
* @throws Error if input text is not a string or chunk size is not a positive integer.
|
|
7
|
+
*/
|
|
8
|
+
export declare function splitChunks(text: string, chunkSize?: Number): string[];
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.splitChunks = splitChunks;
|
|
4
|
+
/**
|
|
5
|
+
* Creates chunks of string based on a given chunk size
|
|
6
|
+
* @param text - Input string
|
|
7
|
+
* @param Number - Size of the chunk. Must be a positive integer. Defaults to 1.
|
|
8
|
+
* @returns An array of all the chunks created from the string based on the specified chunk size.
|
|
9
|
+
* @throws Error if input text is not a string or chunk size is not a positive integer.
|
|
10
|
+
*/
|
|
11
|
+
function splitChunks(text, chunkSize = 1) {
|
|
12
|
+
if (typeof text !== 'string') {
|
|
13
|
+
throw new Error('Input text must be a string');
|
|
14
|
+
}
|
|
15
|
+
if (typeof chunkSize !== 'number' || !Number.isInteger(chunkSize) || chunkSize < 1) {
|
|
16
|
+
throw new Error('chunkSize must be a natural number (1, 2, 3, ...)');
|
|
17
|
+
}
|
|
18
|
+
const len = text.length;
|
|
19
|
+
const chunks = [];
|
|
20
|
+
for (let i = 0; i < len; i += chunkSize) {
|
|
21
|
+
chunks.push(text.slice(i, i + chunkSize));
|
|
22
|
+
}
|
|
23
|
+
return chunks;
|
|
24
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generates all unique combinations (subsequences) of a given string,
|
|
3
|
+
* including the empty string.
|
|
4
|
+
*
|
|
5
|
+
* Handles duplicate characters by ensuring only unique combinations are returned.
|
|
6
|
+
* The order of combinations in the output array is not guaranteed.
|
|
7
|
+
*
|
|
8
|
+
* @param {string} str - The input string to generate combinations from.
|
|
9
|
+
* @returns {string[]} An array containing all unique combinations of the string.
|
|
10
|
+
* @throws {TypeError} If the input is not a string.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* stringCombinations("ab");
|
|
14
|
+
* // ["", "a", "b", "ab"]
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* stringCombinations("abc");
|
|
18
|
+
* // ["", "a", "b", "c", "ab", "ac", "bc", "abc"]
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* stringCombinations("aab");
|
|
22
|
+
* // ["", "a", "b", "aa", "ab", "aab"]
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* stringCombinations("");
|
|
26
|
+
* // [""]
|
|
27
|
+
*/
|
|
28
|
+
export declare function stringCombinations(str: string): string[];
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.stringCombinations = stringCombinations;
|
|
4
|
+
/**
|
|
5
|
+
* Generates all unique combinations (subsequences) of a given string,
|
|
6
|
+
* including the empty string.
|
|
7
|
+
*
|
|
8
|
+
* Handles duplicate characters by ensuring only unique combinations are returned.
|
|
9
|
+
* The order of combinations in the output array is not guaranteed.
|
|
10
|
+
*
|
|
11
|
+
* @param {string} str - The input string to generate combinations from.
|
|
12
|
+
* @returns {string[]} An array containing all unique combinations of the string.
|
|
13
|
+
* @throws {TypeError} If the input is not a string.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* stringCombinations("ab");
|
|
17
|
+
* // ["", "a", "b", "ab"]
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* stringCombinations("abc");
|
|
21
|
+
* // ["", "a", "b", "c", "ab", "ac", "bc", "abc"]
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* stringCombinations("aab");
|
|
25
|
+
* // ["", "a", "b", "aa", "ab", "aab"]
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* stringCombinations("");
|
|
29
|
+
* // [""]
|
|
30
|
+
*/
|
|
31
|
+
function stringCombinations(str) {
|
|
32
|
+
if (typeof str !== 'string') {
|
|
33
|
+
throw new TypeError('Input must be a string');
|
|
34
|
+
}
|
|
35
|
+
const results = new Set();
|
|
36
|
+
function backtrack(start, path) {
|
|
37
|
+
results.add(path);
|
|
38
|
+
for (let i = start; i < str.length; i++) {
|
|
39
|
+
backtrack(i + 1, path + str[i]);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
backtrack(0, '');
|
|
43
|
+
return Array.from(results);
|
|
44
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generates all unique permutations of a given string.
|
|
3
|
+
*
|
|
4
|
+
* Handles repeated characters by ensuring only unique permutations
|
|
5
|
+
* are included in the result. The order of permutations is not guaranteed.
|
|
6
|
+
*
|
|
7
|
+
* @param {string} str - The input string to generate permutations for.
|
|
8
|
+
* @returns {string[]} An array of unique permutations of the input string.
|
|
9
|
+
* @throws {TypeError} If the input is not a string.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* stringPermutations("ab");
|
|
13
|
+
* // ["ab", "ba"]
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* stringPermutations("abc");
|
|
17
|
+
* // ["abc", "acb", "bac", "bca", "cab", "cba"]
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* stringPermutations("aab");
|
|
21
|
+
* // ["aab", "aba", "baa"]
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* stringPermutations("");
|
|
25
|
+
* // [""]
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* stringPermutations("a");
|
|
29
|
+
* // ["a"]
|
|
30
|
+
*/
|
|
31
|
+
export declare function stringPermutations(str: string): string[];
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.stringPermutations = stringPermutations;
|
|
4
|
+
/**
|
|
5
|
+
* Generates all unique permutations of a given string.
|
|
6
|
+
*
|
|
7
|
+
* Handles repeated characters by ensuring only unique permutations
|
|
8
|
+
* are included in the result. The order of permutations is not guaranteed.
|
|
9
|
+
*
|
|
10
|
+
* @param {string} str - The input string to generate permutations for.
|
|
11
|
+
* @returns {string[]} An array of unique permutations of the input string.
|
|
12
|
+
* @throws {TypeError} If the input is not a string.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* stringPermutations("ab");
|
|
16
|
+
* // ["ab", "ba"]
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* stringPermutations("abc");
|
|
20
|
+
* // ["abc", "acb", "bac", "bca", "cab", "cba"]
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* stringPermutations("aab");
|
|
24
|
+
* // ["aab", "aba", "baa"]
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* stringPermutations("");
|
|
28
|
+
* // [""]
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* stringPermutations("a");
|
|
32
|
+
* // ["a"]
|
|
33
|
+
*/
|
|
34
|
+
function stringPermutations(str) {
|
|
35
|
+
if (typeof str !== 'string') {
|
|
36
|
+
throw new TypeError('Input must be a string');
|
|
37
|
+
}
|
|
38
|
+
if (str.length === 0)
|
|
39
|
+
return [''];
|
|
40
|
+
const results = new Set();
|
|
41
|
+
const permute = (prefix, remaining) => {
|
|
42
|
+
if (remaining.length === 0) {
|
|
43
|
+
results.add(prefix);
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
for (let i = 0; i < remaining.length; i++) {
|
|
47
|
+
permute(prefix + remaining[i], remaining.slice(0, i) + remaining.slice(i + 1));
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
permute('', str);
|
|
52
|
+
return Array.from(results);
|
|
53
|
+
}
|
|
@@ -1 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a string to Title Case, capitalizing the first letter of each word.
|
|
3
|
+
*
|
|
4
|
+
* The conversion process includes:
|
|
5
|
+
* - Trimming whitespace from both ends.
|
|
6
|
+
* - Converting the entire string to lowercase.
|
|
7
|
+
* - Replacing non-word characters and underscores with spaces.
|
|
8
|
+
* - Collapsing multiple spaces into a single space.
|
|
9
|
+
* - Capitalizing the first character of each word.
|
|
10
|
+
* - Preserving spaces between words.
|
|
11
|
+
*
|
|
12
|
+
* If the input is `null` or `undefined`, it returns an empty string.
|
|
13
|
+
*
|
|
14
|
+
* @param {string} text - The input string to convert.
|
|
15
|
+
* @returns {string} The Title Case formatted string.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* titleCase("hello world"); // "Hello World"
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* titleCase("convert_to-title.case!"); // "Convert To Title Case"
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* titleCase(" multiple spaces here "); // "Multiple Spaces Here"
|
|
25
|
+
*/
|
|
1
26
|
export declare function titleCase(text: string): string;
|
|
@@ -1,6 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.titleCase = titleCase;
|
|
4
|
+
/**
|
|
5
|
+
* Converts a string to Title Case, capitalizing the first letter of each word.
|
|
6
|
+
*
|
|
7
|
+
* The conversion process includes:
|
|
8
|
+
* - Trimming whitespace from both ends.
|
|
9
|
+
* - Converting the entire string to lowercase.
|
|
10
|
+
* - Replacing non-word characters and underscores with spaces.
|
|
11
|
+
* - Collapsing multiple spaces into a single space.
|
|
12
|
+
* - Capitalizing the first character of each word.
|
|
13
|
+
* - Preserving spaces between words.
|
|
14
|
+
*
|
|
15
|
+
* If the input is `null` or `undefined`, it returns an empty string.
|
|
16
|
+
*
|
|
17
|
+
* @param {string} text - The input string to convert.
|
|
18
|
+
* @returns {string} The Title Case formatted string.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* titleCase("hello world"); // "Hello World"
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* titleCase("convert_to-title.case!"); // "Convert To Title Case"
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* titleCase(" multiple spaces here "); // "Multiple Spaces Here"
|
|
28
|
+
*/
|
|
4
29
|
function titleCase(text) {
|
|
5
30
|
if (text == null)
|
|
6
31
|
return '';
|
|
@@ -1 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a string into a URL-friendly slug.
|
|
3
|
+
*
|
|
4
|
+
* The conversion process includes:
|
|
5
|
+
* - Converting the string to lowercase.
|
|
6
|
+
* - Trimming whitespace from both ends.
|
|
7
|
+
* - Replacing one or more whitespace characters with a single hyphen (`-`).
|
|
8
|
+
* - Removing all characters except word characters (letters, digits, and underscores) and hyphens.
|
|
9
|
+
*
|
|
10
|
+
* Throws an error if the input is not a string.
|
|
11
|
+
*
|
|
12
|
+
* @param {string} text - The input string to convert into a slug.
|
|
13
|
+
* @returns {string} The URL-friendly slug string.
|
|
14
|
+
* @throws {Error} If the input is not a string.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* toSlug("Hello World!"); // "hello-world"
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* toSlug(" This is a test --- "); // "this-is-a-test"
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* toSlug("Clean_URL--Slug123"); // "clean_url--slug123"
|
|
24
|
+
*/
|
|
1
25
|
export declare function toSlug(text: string): string;
|
|
@@ -1,13 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.toSlug = toSlug;
|
|
4
|
+
/**
|
|
5
|
+
* Converts a string into a URL-friendly slug.
|
|
6
|
+
*
|
|
7
|
+
* The conversion process includes:
|
|
8
|
+
* - Converting the string to lowercase.
|
|
9
|
+
* - Trimming whitespace from both ends.
|
|
10
|
+
* - Replacing one or more whitespace characters with a single hyphen (`-`).
|
|
11
|
+
* - Removing all characters except word characters (letters, digits, and underscores) and hyphens.
|
|
12
|
+
*
|
|
13
|
+
* Throws an error if the input is not a string.
|
|
14
|
+
*
|
|
15
|
+
* @param {string} text - The input string to convert into a slug.
|
|
16
|
+
* @returns {string} The URL-friendly slug string.
|
|
17
|
+
* @throws {Error} If the input is not a string.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* toSlug("Hello World!"); // "hello-world"
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* toSlug(" This is a test --- "); // "this-is-a-test"
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* toSlug("Clean_URL--Slug123"); // "clean_url--slug123"
|
|
27
|
+
*/
|
|
4
28
|
function toSlug(text) {
|
|
5
|
-
if (typeof text !==
|
|
6
|
-
throw new Error(
|
|
29
|
+
if (typeof text !== 'string') {
|
|
30
|
+
throw new Error('Invalid argument. Expected a string.');
|
|
7
31
|
}
|
|
8
32
|
return text
|
|
9
33
|
.toLowerCase()
|
|
10
34
|
.trim()
|
|
11
|
-
.replace(/[\s]+/g,
|
|
12
|
-
.replace(/[^\w-]+/g,
|
|
35
|
+
.replace(/[\s]+/g, '-')
|
|
36
|
+
.replace(/[^\w-]+/g, '');
|
|
13
37
|
}
|
|
@@ -1 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Truncates a string to a specified maximum length and appends a suffix if truncated.
|
|
3
|
+
*
|
|
4
|
+
* If the text length is less than or equal to `maxLength`, the original text is returned.
|
|
5
|
+
* Otherwise, the text is cut off so that the total length including the suffix does not exceed `maxLength`.
|
|
6
|
+
*
|
|
7
|
+
* Throws a `TypeError` if input types are invalid or if `maxLength` is negative.
|
|
8
|
+
*
|
|
9
|
+
* @param {string} text - The input string to truncate.
|
|
10
|
+
* @param {number} maxLength - The maximum allowed length of the returned string including suffix.
|
|
11
|
+
* @param {string} [suffix='...'] - The string to append if truncation occurs.
|
|
12
|
+
* @returns {string} The truncated string with suffix if applicable.
|
|
13
|
+
* @throws {TypeError} If `text` is not a string.
|
|
14
|
+
* @throws {Error} If `maxLength` is not a non-negative number.
|
|
15
|
+
* @throws {TypeError} If `suffix` is not a string.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* truncateText("Hello World", 8); // "Hello..."
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* truncateText("Short text", 20); // "Short text"
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* truncateText("Custom suffix example", 10, "---"); // "Custom---"
|
|
25
|
+
*/
|
|
1
26
|
export declare function truncateText(text: string, maxLength: number, suffix?: string): string;
|
|
@@ -1,15 +1,40 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.truncateText = truncateText;
|
|
4
|
+
/**
|
|
5
|
+
* Truncates a string to a specified maximum length and appends a suffix if truncated.
|
|
6
|
+
*
|
|
7
|
+
* If the text length is less than or equal to `maxLength`, the original text is returned.
|
|
8
|
+
* Otherwise, the text is cut off so that the total length including the suffix does not exceed `maxLength`.
|
|
9
|
+
*
|
|
10
|
+
* Throws a `TypeError` if input types are invalid or if `maxLength` is negative.
|
|
11
|
+
*
|
|
12
|
+
* @param {string} text - The input string to truncate.
|
|
13
|
+
* @param {number} maxLength - The maximum allowed length of the returned string including suffix.
|
|
14
|
+
* @param {string} [suffix='...'] - The string to append if truncation occurs.
|
|
15
|
+
* @returns {string} The truncated string with suffix if applicable.
|
|
16
|
+
* @throws {TypeError} If `text` is not a string.
|
|
17
|
+
* @throws {Error} If `maxLength` is not a non-negative number.
|
|
18
|
+
* @throws {TypeError} If `suffix` is not a string.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* truncateText("Hello World", 8); // "Hello..."
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* truncateText("Short text", 20); // "Short text"
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* truncateText("Custom suffix example", 10, "---"); // "Custom---"
|
|
28
|
+
*/
|
|
4
29
|
function truncateText(text, maxLength, suffix = '...') {
|
|
5
30
|
if (typeof text !== 'string') {
|
|
6
|
-
throw new
|
|
31
|
+
throw new TypeError('Input text must be a string.');
|
|
7
32
|
}
|
|
8
33
|
if (typeof maxLength !== 'number' || maxLength < 0) {
|
|
9
|
-
throw new Error(
|
|
34
|
+
throw new Error('maxLength must be a non-negative number.');
|
|
10
35
|
}
|
|
11
36
|
if (typeof suffix !== 'string') {
|
|
12
|
-
throw new
|
|
37
|
+
throw new TypeError('Suffix must be a string.');
|
|
13
38
|
}
|
|
14
39
|
if (text.length <= maxLength) {
|
|
15
40
|
return text;
|