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,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extracts the initials from a given string.
|
|
3
|
+
*
|
|
4
|
+
* Splits the input text by whitespace, takes the first character of each word,
|
|
5
|
+
* and joins them together. Optionally limits the number of initials returned.
|
|
6
|
+
*
|
|
7
|
+
* Throws an error if the input is not a string or if the `limit` parameter
|
|
8
|
+
* is provided but not a non-negative number.
|
|
9
|
+
*
|
|
10
|
+
* @param {string} text - The input string from which to extract initials.
|
|
11
|
+
* @param {number} [limit] - Optional maximum number of initials to return.
|
|
12
|
+
* @returns {string} A string containing the initials.
|
|
13
|
+
* @throws {TypeError} If `text` is not a string.
|
|
14
|
+
* @throws {Error} If `limit` is provided and is not a non-negative number.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* initials("John Doe"); // "JD"
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* initials("John Ronald Reuel Tolkien", 2); // "JR"
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* initials(" singleWord "); // "s"
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* initials(""); // ""
|
|
27
|
+
*/
|
|
1
28
|
export declare function initials(text: string, limit?: number): string;
|
|
@@ -1,19 +1,49 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.initials = initials;
|
|
4
|
+
/**
|
|
5
|
+
* Extracts the initials from a given string.
|
|
6
|
+
*
|
|
7
|
+
* Splits the input text by whitespace, takes the first character of each word,
|
|
8
|
+
* and joins them together. Optionally limits the number of initials returned.
|
|
9
|
+
*
|
|
10
|
+
* Throws an error if the input is not a string or if the `limit` parameter
|
|
11
|
+
* is provided but not a non-negative number.
|
|
12
|
+
*
|
|
13
|
+
* @param {string} text - The input string from which to extract initials.
|
|
14
|
+
* @param {number} [limit] - Optional maximum number of initials to return.
|
|
15
|
+
* @returns {string} A string containing the initials.
|
|
16
|
+
* @throws {TypeError} If `text` is not a string.
|
|
17
|
+
* @throws {Error} If `limit` is provided and is not a non-negative number.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* initials("John Doe"); // "JD"
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* initials("John Ronald Reuel Tolkien", 2); // "JR"
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* initials(" singleWord "); // "s"
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* initials(""); // ""
|
|
30
|
+
*/
|
|
4
31
|
function initials(text, limit) {
|
|
5
|
-
if (typeof text !==
|
|
6
|
-
throw new
|
|
32
|
+
if (typeof text !== 'string') {
|
|
33
|
+
throw new TypeError('Input must be a string');
|
|
7
34
|
}
|
|
8
|
-
if (limit !== undefined && (typeof limit !==
|
|
9
|
-
throw new Error(
|
|
35
|
+
if (limit !== undefined && (typeof limit !== 'number' || isNaN(limit))) {
|
|
36
|
+
throw new Error('Limit must be a valid number');
|
|
10
37
|
}
|
|
11
38
|
if (limit !== undefined && limit < 0) {
|
|
12
|
-
throw new Error(
|
|
39
|
+
throw new Error('Limit must be a non-negative number');
|
|
13
40
|
}
|
|
14
|
-
const words = text
|
|
41
|
+
const words = text
|
|
42
|
+
.trim()
|
|
43
|
+
.split(/\s+/)
|
|
44
|
+
.filter((word) => word.length > 0);
|
|
15
45
|
if (words.length === 0)
|
|
16
|
-
return
|
|
46
|
+
return '';
|
|
17
47
|
const initialsArray = words.map((word) => word.charAt(0)).slice(0, limit !== null && limit !== void 0 ? limit : words.length);
|
|
18
|
-
return initialsArray.join(
|
|
48
|
+
return initialsArray.join('');
|
|
19
49
|
}
|
|
@@ -1 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a given string to kebab-case format.
|
|
3
|
+
*
|
|
4
|
+
* The conversion process includes:
|
|
5
|
+
* - Trimming whitespace from both ends.
|
|
6
|
+
* - Replacing spaces and underscores with hyphens.
|
|
7
|
+
* - Inserting hyphens between lowercase and uppercase letter boundaries (e.g., `fooBar` → `foo-bar`).
|
|
8
|
+
* - Replacing all non-word characters (except hyphens) with hyphens.
|
|
9
|
+
* - Converting the entire string to lowercase.
|
|
10
|
+
* - Collapsing multiple consecutive hyphens into a single one.
|
|
11
|
+
* - Removing leading and trailing hyphens.
|
|
12
|
+
*
|
|
13
|
+
* If the input is `null` or `undefined`, an empty string is returned.
|
|
14
|
+
*
|
|
15
|
+
* @param {string} text - The input string to convert.
|
|
16
|
+
* @returns {string} The kebab-case formatted string.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* kebabCase("Hello World"); // "hello-world"
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* kebabCase("camelCaseText"); // "camel-case-text"
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* kebabCase(" convert_to--kebab.case! "); // "convert-to-kebab-case"
|
|
26
|
+
*/
|
|
1
27
|
export declare function kebabCase(text: string): string;
|
|
@@ -1,6 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.kebabCase = kebabCase;
|
|
4
|
+
/**
|
|
5
|
+
* Converts a given string to kebab-case format.
|
|
6
|
+
*
|
|
7
|
+
* The conversion process includes:
|
|
8
|
+
* - Trimming whitespace from both ends.
|
|
9
|
+
* - Replacing spaces and underscores with hyphens.
|
|
10
|
+
* - Inserting hyphens between lowercase and uppercase letter boundaries (e.g., `fooBar` → `foo-bar`).
|
|
11
|
+
* - Replacing all non-word characters (except hyphens) with hyphens.
|
|
12
|
+
* - Converting the entire string to lowercase.
|
|
13
|
+
* - Collapsing multiple consecutive hyphens into a single one.
|
|
14
|
+
* - Removing leading and trailing hyphens.
|
|
15
|
+
*
|
|
16
|
+
* If the input is `null` or `undefined`, an empty string is returned.
|
|
17
|
+
*
|
|
18
|
+
* @param {string} text - The input string to convert.
|
|
19
|
+
* @returns {string} The kebab-case formatted string.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* kebabCase("Hello World"); // "hello-world"
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* kebabCase("camelCaseText"); // "camel-case-text"
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* kebabCase(" convert_to--kebab.case! "); // "convert-to-kebab-case"
|
|
29
|
+
*/
|
|
4
30
|
function kebabCase(text) {
|
|
5
31
|
if (text == null)
|
|
6
32
|
return '';
|
|
@@ -9,17 +9,15 @@
|
|
|
9
9
|
*/
|
|
10
10
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
11
|
exports.maskSegment = maskSegment;
|
|
12
|
-
function maskSegment(text, maskStart = 0, maskEnd = text.length, maskChar =
|
|
12
|
+
function maskSegment(text, maskStart = 0, maskEnd = text.length, maskChar = '*') {
|
|
13
13
|
if (maskStart < 0 || maskEnd > text.length || maskStart >= maskEnd) {
|
|
14
|
-
throw new Error(
|
|
14
|
+
throw new Error('Invalid mask segment range');
|
|
15
15
|
}
|
|
16
16
|
if (maskChar.length !== 1) {
|
|
17
|
-
throw new Error(
|
|
17
|
+
throw new Error('Mask character must be a single character');
|
|
18
18
|
}
|
|
19
19
|
if (maskStart === 0 && maskEnd === text.length) {
|
|
20
20
|
return maskChar.repeat(text.length);
|
|
21
21
|
}
|
|
22
|
-
return
|
|
23
|
-
maskChar.repeat(maskEnd - maskStart) +
|
|
24
|
-
text.slice(maskEnd));
|
|
22
|
+
return text.slice(0, maskStart) + maskChar.repeat(maskEnd - maskStart) + text.slice(maskEnd);
|
|
25
23
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if a number is negative
|
|
3
|
+
*/
|
|
4
|
+
export declare function isNegative(num: number): boolean;
|
|
5
|
+
/**
|
|
6
|
+
* Gets the highest order of magnitude for a number
|
|
7
|
+
* @example getOrderOfMagnitude(1234) returns 1000
|
|
8
|
+
* @example getOrderOfMagnitude(567) returns 100
|
|
9
|
+
*/
|
|
10
|
+
export declare function getOrderOfMagnitude(num: number): number;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isNegative = isNegative;
|
|
4
|
+
exports.getOrderOfMagnitude = getOrderOfMagnitude;
|
|
5
|
+
/**
|
|
6
|
+
* Checks if a number is negative
|
|
7
|
+
*/
|
|
8
|
+
function isNegative(num) {
|
|
9
|
+
return num < 0;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Gets the highest order of magnitude for a number
|
|
13
|
+
* @example getOrderOfMagnitude(1234) returns 1000
|
|
14
|
+
* @example getOrderOfMagnitude(567) returns 100
|
|
15
|
+
*/
|
|
16
|
+
function getOrderOfMagnitude(num) {
|
|
17
|
+
const absNum = Math.abs(num);
|
|
18
|
+
if (absNum >= 1000000000000)
|
|
19
|
+
return 1000000000000;
|
|
20
|
+
if (absNum >= 1000000000)
|
|
21
|
+
return 1000000000;
|
|
22
|
+
if (absNum >= 1000000)
|
|
23
|
+
return 1000000;
|
|
24
|
+
if (absNum >= 1000)
|
|
25
|
+
return 1000;
|
|
26
|
+
if (absNum >= 100)
|
|
27
|
+
return 100;
|
|
28
|
+
if (absNum >= 10)
|
|
29
|
+
return 10;
|
|
30
|
+
return 1;
|
|
31
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a number to its English textual representation.
|
|
3
|
+
*
|
|
4
|
+
* Handles negative numbers, numbers from 0 to 20, tens, hundreds, thousands, and larger magnitudes.
|
|
5
|
+
*
|
|
6
|
+
* @param num The number to convert.
|
|
7
|
+
* @returns The textual representation of the number in English.
|
|
8
|
+
*/
|
|
9
|
+
declare function numberToTextEn(num: number): string;
|
|
10
|
+
export default numberToTextEn;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const types_1 = require("./types");
|
|
4
|
+
const helpers_1 = require("./helpers");
|
|
5
|
+
/**
|
|
6
|
+
* Converts a number to its English textual representation.
|
|
7
|
+
*
|
|
8
|
+
* Handles negative numbers, numbers from 0 to 20, tens, hundreds, thousands, and larger magnitudes.
|
|
9
|
+
*
|
|
10
|
+
* @param num The number to convert.
|
|
11
|
+
* @returns The textual representation of the number in English.
|
|
12
|
+
*/
|
|
13
|
+
function numberToTextEn(num) {
|
|
14
|
+
if ((0, helpers_1.isNegative)(num)) {
|
|
15
|
+
return `minus ${numberToTextEn(Math.abs(num))}`;
|
|
16
|
+
}
|
|
17
|
+
// 0-20
|
|
18
|
+
if (num <= 20 && types_1.NUMBERS_EN[num]) {
|
|
19
|
+
return types_1.NUMBERS_EN[num];
|
|
20
|
+
}
|
|
21
|
+
// 21-99
|
|
22
|
+
if (num < 100) {
|
|
23
|
+
const tens = Math.floor(num / 10) * 10;
|
|
24
|
+
const ones = num % 10;
|
|
25
|
+
if (ones === 0) {
|
|
26
|
+
return types_1.NUMBERS_EN[tens];
|
|
27
|
+
}
|
|
28
|
+
return `${types_1.NUMBERS_EN[tens]}-${types_1.NUMBERS_EN[ones]}`;
|
|
29
|
+
}
|
|
30
|
+
// 100+
|
|
31
|
+
const magnitude = (0, helpers_1.getOrderOfMagnitude)(num);
|
|
32
|
+
const quotient = Math.floor(num / magnitude);
|
|
33
|
+
const remainder = num % magnitude;
|
|
34
|
+
// Special handling for hundreds
|
|
35
|
+
if (magnitude === 100) {
|
|
36
|
+
const result = `${numberToTextEn(quotient)} hundred`;
|
|
37
|
+
return remainder === 0 ? result : `${result} ${numberToTextEn(remainder)}`;
|
|
38
|
+
}
|
|
39
|
+
// 1000+
|
|
40
|
+
const magnitudeName = types_1.NUMBERS_EN[magnitude];
|
|
41
|
+
const quotientText = numberToTextEn(quotient);
|
|
42
|
+
const result = `${quotientText} ${magnitudeName}`;
|
|
43
|
+
return remainder === 0 ? result : `${result} ${numberToTextEn(remainder)}`;
|
|
44
|
+
}
|
|
45
|
+
exports.default = numberToTextEn;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a number to its Polish textual representation.
|
|
3
|
+
*
|
|
4
|
+
* Handles negative numbers, numbers from 0 to billions, and applies correct Polish grammatical forms.
|
|
5
|
+
*
|
|
6
|
+
* @param num The number to convert.
|
|
7
|
+
* @returns The textual representation of the number in Polish.
|
|
8
|
+
*/
|
|
9
|
+
declare function numberToTextPl(num: number): string;
|
|
10
|
+
export default numberToTextPl;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const types_1 = require("./types");
|
|
4
|
+
const helpers_1 = require("./helpers");
|
|
5
|
+
/**
|
|
6
|
+
* Converts a number to its Polish textual representation.
|
|
7
|
+
*
|
|
8
|
+
* Handles negative numbers, numbers from 0 to billions, and applies correct Polish grammatical forms.
|
|
9
|
+
*
|
|
10
|
+
* @param num The number to convert.
|
|
11
|
+
* @returns The textual representation of the number in Polish.
|
|
12
|
+
*/
|
|
13
|
+
function numberToTextPl(num) {
|
|
14
|
+
if ((0, helpers_1.isNegative)(num)) {
|
|
15
|
+
return `minus ${numberToTextPl(Math.abs(num))}`;
|
|
16
|
+
}
|
|
17
|
+
// 0-20
|
|
18
|
+
if (num <= 20 && types_1.NUMBERS_PL[num]) {
|
|
19
|
+
return types_1.NUMBERS_PL[num];
|
|
20
|
+
}
|
|
21
|
+
// 21-99
|
|
22
|
+
if (num < 100) {
|
|
23
|
+
const tens = Math.floor(num / 10) * 10;
|
|
24
|
+
const ones = num % 10;
|
|
25
|
+
if (ones === 0) {
|
|
26
|
+
return types_1.NUMBERS_PL[tens];
|
|
27
|
+
}
|
|
28
|
+
return `${types_1.NUMBERS_PL[tens]} ${types_1.NUMBERS_PL[ones]}`;
|
|
29
|
+
}
|
|
30
|
+
// 100+
|
|
31
|
+
const magnitude = (0, helpers_1.getOrderOfMagnitude)(num);
|
|
32
|
+
const quotient = Math.floor(num / magnitude);
|
|
33
|
+
const remainder = num % magnitude;
|
|
34
|
+
// Special handling for hundreds
|
|
35
|
+
if (magnitude === 100) {
|
|
36
|
+
const hundredsForm = quotient * 100;
|
|
37
|
+
const result = types_1.NUMBERS_PL[hundredsForm];
|
|
38
|
+
return remainder === 0 ? result : `${result} ${numberToTextPl(remainder)}`;
|
|
39
|
+
}
|
|
40
|
+
// 1000+
|
|
41
|
+
let prefix = '';
|
|
42
|
+
if (quotient !== 1) {
|
|
43
|
+
prefix = numberToTextPl(quotient) + ' ';
|
|
44
|
+
}
|
|
45
|
+
const magnitudeForm = getPolishGrammaticalForm(magnitude, quotient);
|
|
46
|
+
const result = `${prefix}${magnitudeForm}`.trim();
|
|
47
|
+
return remainder === 0 ? result : `${result} ${numberToTextPl(remainder)}`;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Gets the correct grammatical form for Polish magnitude words
|
|
51
|
+
* based on the number (singular, few, many)
|
|
52
|
+
*/
|
|
53
|
+
function getPolishGrammaticalForm(magnitude, count) {
|
|
54
|
+
const forms = {
|
|
55
|
+
1000: ['tysiąc', 'tysiące', 'tysięcy'],
|
|
56
|
+
1000000: ['milion', 'miliony', 'milionów'],
|
|
57
|
+
1000000000: ['miliard', 'miliardy', 'miliardów'],
|
|
58
|
+
1000000000000: ['bilion', 'biliony', 'bilionów']
|
|
59
|
+
};
|
|
60
|
+
const formArray = forms[magnitude];
|
|
61
|
+
if (!formArray) {
|
|
62
|
+
throw new Error(`No grammatical forms defined for magnitude ${magnitude}`);
|
|
63
|
+
}
|
|
64
|
+
const lastTwoDigits = count % 100;
|
|
65
|
+
const lastDigit = count % 10;
|
|
66
|
+
if (lastTwoDigits >= 11 && lastTwoDigits <= 19) {
|
|
67
|
+
return formArray[2];
|
|
68
|
+
}
|
|
69
|
+
if (lastDigit === 1) {
|
|
70
|
+
return formArray[0];
|
|
71
|
+
}
|
|
72
|
+
else if (lastDigit >= 2 && lastDigit <= 4) {
|
|
73
|
+
return formArray[1];
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
return formArray[2];
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
exports.default = numberToTextPl;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { NumberToTextLanguage } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Converts a number to its text representation in the specified language.
|
|
4
|
+
*
|
|
5
|
+
* @param num - The number to convert (integer between -1,000,000,000,000 and 1,000,000,000,000)
|
|
6
|
+
* @param lang - The target language ('en' for English, 'pl' for Polish)
|
|
7
|
+
* @returns The text representation of the number
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* numberToText(123) // "one hundred twenty-three"
|
|
11
|
+
* numberToText(123, 'pl') // "sto dwadzieścia trzy"
|
|
12
|
+
* numberToText(-45) // "minus forty-five"
|
|
13
|
+
* numberToText(1000000) // "one million"
|
|
14
|
+
* numberToText(1000000, 'pl') // "milion"
|
|
15
|
+
*
|
|
16
|
+
* @throws {TypeError} If num is not a valid integer or lang is not supported
|
|
17
|
+
* @throws {RangeError} If num is outside the supported range
|
|
18
|
+
*/
|
|
19
|
+
export declare function numberToText(num: number, lang?: NumberToTextLanguage): string;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.numberToText = numberToText;
|
|
7
|
+
const implementation_PL_1 = __importDefault(require("./implementation_PL"));
|
|
8
|
+
const implementation_EN_1 = __importDefault(require("./implementation_EN"));
|
|
9
|
+
/**
|
|
10
|
+
* Converts a number to its text representation in the specified language.
|
|
11
|
+
*
|
|
12
|
+
* @param num - The number to convert (integer between -1,000,000,000,000 and 1,000,000,000,000)
|
|
13
|
+
* @param lang - The target language ('en' for English, 'pl' for Polish)
|
|
14
|
+
* @returns The text representation of the number
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* numberToText(123) // "one hundred twenty-three"
|
|
18
|
+
* numberToText(123, 'pl') // "sto dwadzieścia trzy"
|
|
19
|
+
* numberToText(-45) // "minus forty-five"
|
|
20
|
+
* numberToText(1000000) // "one million"
|
|
21
|
+
* numberToText(1000000, 'pl') // "milion"
|
|
22
|
+
*
|
|
23
|
+
* @throws {TypeError} If num is not a valid integer or lang is not supported
|
|
24
|
+
* @throws {RangeError} If num is outside the supported range
|
|
25
|
+
*/
|
|
26
|
+
function numberToText(num, lang = 'en') {
|
|
27
|
+
validateNumber(num);
|
|
28
|
+
validateLanguage(lang);
|
|
29
|
+
const langMap = {
|
|
30
|
+
en: implementation_EN_1.default,
|
|
31
|
+
pl: implementation_PL_1.default,
|
|
32
|
+
};
|
|
33
|
+
if (!langMap[lang]) {
|
|
34
|
+
throw new TypeError('Unsupported language');
|
|
35
|
+
}
|
|
36
|
+
return langMap[lang](num);
|
|
37
|
+
}
|
|
38
|
+
/////////////////////////////////////////
|
|
39
|
+
//// Validation
|
|
40
|
+
/////////////////////////////////////////
|
|
41
|
+
/**
|
|
42
|
+
* Checks if the provided value is an integer within the allowed range.
|
|
43
|
+
*
|
|
44
|
+
* @param num - The value to check
|
|
45
|
+
* @throws {TypeError} If num is not an integer
|
|
46
|
+
* @throws {RangeError} If num is outside the range -1,000,000,000,000 to 1,000,000,000,000
|
|
47
|
+
*/
|
|
48
|
+
function validateNumber(num) {
|
|
49
|
+
if (typeof num !== 'number' || !Number.isInteger(num) || isNaN(num)) {
|
|
50
|
+
throw new TypeError('Num param should be number');
|
|
51
|
+
}
|
|
52
|
+
if (num < -1000000000000 || num > 1000000000000) {
|
|
53
|
+
throw new RangeError('Number must be between -1,000,000,000,000 and 1,000,000,000,000');
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Checks if the provided language is supported.
|
|
58
|
+
*
|
|
59
|
+
* @param lang - The language code to check
|
|
60
|
+
* @throws {TypeError} If lang is not one of the supported languages
|
|
61
|
+
*/
|
|
62
|
+
function validateLanguage(lang) {
|
|
63
|
+
const validLanguages = ['en', 'pl'];
|
|
64
|
+
if (!validLanguages.includes(lang)) {
|
|
65
|
+
throw new TypeError(`Language must be one of: ${validLanguages.join(', ')}`);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -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
|
}
|