stringzy 3.0.0 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.prettierignore +4 -0
- package/.prettierrc +7 -0
- package/CONTRIBUTING.md +41 -29
- package/README.md +397 -160
- 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/complexity.d.ts +33 -0
- package/dist/analyzing/complexity.js +35 -2
- package/dist/analyzing/index.d.ts +18 -12
- package/dist/analyzing/index.js +10 -2
- package/dist/analyzing/patternCount.d.ts +10 -0
- package/dist/analyzing/patternCount.js +52 -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 +9 -4
- 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/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/splitChunks.test.d.ts +1 -0
- package/dist/tests/transformations/splitChunks.test.js +31 -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/isPalindrome.test.d.ts +1 -0
- package/dist/tests/validations/isPalindrome.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/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 +3 -0
- package/dist/transformations/index.js +6 -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/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/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 +6 -0
- package/dist/validations/index.js +10 -2
- 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/isPalindrome.d.ts +10 -0
- package/dist/validations/isPalindrome.js +21 -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/package.json +5 -3
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/////////////////////////////////////////
|
|
3
|
+
//// Type Definitions
|
|
4
|
+
/////////////////////////////////////////
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.NUMBERS_PL = exports.NUMBERS_EN = void 0;
|
|
7
|
+
/////////////////////////////////////////
|
|
8
|
+
//// Language Dictionaries
|
|
9
|
+
/////////////////////////////////////////
|
|
10
|
+
exports.NUMBERS_EN = {
|
|
11
|
+
0: 'zero',
|
|
12
|
+
1: 'one',
|
|
13
|
+
2: 'two',
|
|
14
|
+
3: 'three',
|
|
15
|
+
4: 'four',
|
|
16
|
+
5: 'five',
|
|
17
|
+
6: 'six',
|
|
18
|
+
7: 'seven',
|
|
19
|
+
8: 'eight',
|
|
20
|
+
9: 'nine',
|
|
21
|
+
10: 'ten',
|
|
22
|
+
11: 'eleven',
|
|
23
|
+
12: 'twelve',
|
|
24
|
+
13: 'thirteen',
|
|
25
|
+
14: 'fourteen',
|
|
26
|
+
15: 'fifteen',
|
|
27
|
+
16: 'sixteen',
|
|
28
|
+
17: 'seventeen',
|
|
29
|
+
18: 'eighteen',
|
|
30
|
+
19: 'nineteen',
|
|
31
|
+
20: 'twenty',
|
|
32
|
+
30: 'thirty',
|
|
33
|
+
40: 'forty',
|
|
34
|
+
50: 'fifty',
|
|
35
|
+
60: 'sixty',
|
|
36
|
+
70: 'seventy',
|
|
37
|
+
80: 'eighty',
|
|
38
|
+
90: 'ninety',
|
|
39
|
+
1000: 'thousand',
|
|
40
|
+
1000000: 'million',
|
|
41
|
+
1000000000: 'billion',
|
|
42
|
+
1000000000000: 'trillion'
|
|
43
|
+
};
|
|
44
|
+
exports.NUMBERS_PL = {
|
|
45
|
+
0: 'zero',
|
|
46
|
+
1: 'jeden',
|
|
47
|
+
2: 'dwa',
|
|
48
|
+
3: 'trzy',
|
|
49
|
+
4: 'cztery',
|
|
50
|
+
5: 'pięć',
|
|
51
|
+
6: 'sześć',
|
|
52
|
+
7: 'siedem',
|
|
53
|
+
8: 'osiem',
|
|
54
|
+
9: 'dziewięć',
|
|
55
|
+
10: 'dziesięć',
|
|
56
|
+
11: 'jedenaście',
|
|
57
|
+
12: 'dwanaście',
|
|
58
|
+
13: 'trzynaście',
|
|
59
|
+
14: 'czternaście',
|
|
60
|
+
15: 'piętnaście',
|
|
61
|
+
16: 'szesnaście',
|
|
62
|
+
17: 'siedemnaście',
|
|
63
|
+
18: 'osiemnaście',
|
|
64
|
+
19: 'dziewiętnaście',
|
|
65
|
+
20: 'dwadzieścia',
|
|
66
|
+
30: 'trzydzieści',
|
|
67
|
+
40: 'czterdzieści',
|
|
68
|
+
50: 'pięćdziesiąt',
|
|
69
|
+
60: 'sześćdziesiąt',
|
|
70
|
+
70: 'siedemdziesiąt',
|
|
71
|
+
80: 'osiemdziesiąt',
|
|
72
|
+
90: 'dziewięćdziesiąt',
|
|
73
|
+
100: 'sto',
|
|
74
|
+
200: 'dwieście',
|
|
75
|
+
300: 'trzysta',
|
|
76
|
+
400: 'czterysta',
|
|
77
|
+
500: 'pięćset',
|
|
78
|
+
600: 'sześćset',
|
|
79
|
+
700: 'siedemset',
|
|
80
|
+
800: 'osiemset',
|
|
81
|
+
900: 'dziewięćset'
|
|
82
|
+
};
|
|
@@ -1 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a given string to PascalCase format.
|
|
3
|
+
*
|
|
4
|
+
* The conversion process includes:
|
|
5
|
+
* - Trimming whitespace from both ends.
|
|
6
|
+
* - Converting all characters to lowercase.
|
|
7
|
+
* - Replacing non-word characters and underscores with spaces.
|
|
8
|
+
* - Collapsing multiple spaces into a single space.
|
|
9
|
+
* - Capitalizing the first letter of each word.
|
|
10
|
+
* - Removing all spaces to produce the PascalCase output.
|
|
11
|
+
*
|
|
12
|
+
* If the input is `null` or `undefined`, an empty string is returned.
|
|
13
|
+
*
|
|
14
|
+
* @param {string} text - The input string to convert.
|
|
15
|
+
* @returns {string} The PascalCase formatted string.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* pascalCase("hello world"); // "HelloWorld"
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* pascalCase("convert_to-pascal.case"); // "ConvertToPascalCase"
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* pascalCase(" multiple spaces here "); // "MultipleSpacesHere"
|
|
25
|
+
*/
|
|
1
26
|
export declare function pascalCase(text: string): string;
|
|
@@ -1,6 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.pascalCase = pascalCase;
|
|
4
|
+
/**
|
|
5
|
+
* Converts a given string to PascalCase format.
|
|
6
|
+
*
|
|
7
|
+
* The conversion process includes:
|
|
8
|
+
* - Trimming whitespace from both ends.
|
|
9
|
+
* - Converting all characters to lowercase.
|
|
10
|
+
* - Replacing non-word characters and underscores with spaces.
|
|
11
|
+
* - Collapsing multiple spaces into a single space.
|
|
12
|
+
* - Capitalizing the first letter of each word.
|
|
13
|
+
* - Removing all spaces to produce the PascalCase output.
|
|
14
|
+
*
|
|
15
|
+
* If the input is `null` or `undefined`, an empty string is returned.
|
|
16
|
+
*
|
|
17
|
+
* @param {string} text - The input string to convert.
|
|
18
|
+
* @returns {string} The PascalCase formatted string.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* pascalCase("hello world"); // "HelloWorld"
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* pascalCase("convert_to-pascal.case"); // "ConvertToPascalCase"
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* pascalCase(" multiple spaces here "); // "MultipleSpacesHere"
|
|
28
|
+
*/
|
|
4
29
|
function pascalCase(text) {
|
|
5
30
|
if (text == null)
|
|
6
31
|
return '';
|
|
@@ -1 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Removes duplicate words from a string, preserving the original word order.
|
|
3
|
+
*
|
|
4
|
+
* Splits the input string by spaces, filters out duplicate words,
|
|
5
|
+
* and joins the unique words back into a string separated by spaces.
|
|
6
|
+
*
|
|
7
|
+
* Throws an error if the input is not a string.
|
|
8
|
+
*
|
|
9
|
+
* @param {string} text - The input string from which duplicate words will be removed.
|
|
10
|
+
* @returns {string} A string containing only unique words in their original order.
|
|
11
|
+
* @throws {TypeError} If the input is not a string.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* removeDuplicates("hello world hello"); // "hello world"
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* removeDuplicates("this is is a test test"); // "this is a test"
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* removeDuplicates(""); // ""
|
|
21
|
+
*/
|
|
1
22
|
export declare function removeDuplicates(text: string): string;
|
|
@@ -1,13 +1,34 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.removeDuplicates = removeDuplicates;
|
|
4
|
+
/**
|
|
5
|
+
* Removes duplicate words from a string, preserving the original word order.
|
|
6
|
+
*
|
|
7
|
+
* Splits the input string by spaces, filters out duplicate words,
|
|
8
|
+
* and joins the unique words back into a string separated by spaces.
|
|
9
|
+
*
|
|
10
|
+
* Throws an error if the input is not a string.
|
|
11
|
+
*
|
|
12
|
+
* @param {string} text - The input string from which duplicate words will be removed.
|
|
13
|
+
* @returns {string} A string containing only unique words in their original order.
|
|
14
|
+
* @throws {TypeError} If the input is not a string.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* removeDuplicates("hello world hello"); // "hello world"
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* removeDuplicates("this is is a test test"); // "this is a test"
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* removeDuplicates(""); // ""
|
|
24
|
+
*/
|
|
4
25
|
function removeDuplicates(text) {
|
|
5
|
-
if (typeof text !==
|
|
6
|
-
throw new
|
|
26
|
+
if (typeof text !== 'string') {
|
|
27
|
+
throw new TypeError('Input must be a string');
|
|
7
28
|
}
|
|
8
29
|
const wordSet = new Set();
|
|
9
|
-
text.split(
|
|
30
|
+
text.split(' ').forEach((word) => {
|
|
10
31
|
wordSet.add(word);
|
|
11
32
|
});
|
|
12
|
-
return Array.from(wordSet).join(
|
|
33
|
+
return Array.from(wordSet).join(' ');
|
|
13
34
|
}
|
|
@@ -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 '';
|
|
@@ -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
|
+
}
|
|
@@ -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;
|