stringzy 2.2.1 → 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/.github/workflows/publish.yml +29 -0
- package/.github/workflows/test-on-pr.yml +23 -0
- package/.prettierignore +4 -0
- package/.prettierrc +7 -0
- package/CONTRIBUTING.md +99 -0
- package/LICENSE +21 -21
- package/README.md +1189 -723
- package/changelog.txt +110 -110
- package/dist/analyzing/characterCount.d.ts +20 -0
- package/dist/analyzing/characterCount.js +28 -0
- package/dist/analyzing/characterFrequency.d.ts +20 -0
- package/dist/analyzing/characterFrequency.js +35 -0
- package/dist/analyzing/complexity.d.ts +39 -0
- package/dist/analyzing/complexity.js +63 -0
- package/dist/analyzing/index.d.ts +26 -0
- package/dist/analyzing/index.js +37 -0
- package/dist/analyzing/patternCount.d.ts +10 -0
- package/dist/analyzing/patternCount.js +52 -0
- package/dist/analyzing/readingDuration.d.ts +10 -0
- package/dist/analyzing/readingDuration.js +17 -0
- package/dist/analyzing/stringSimilarity.d.ts +8 -0
- package/dist/analyzing/stringSimilarity.js +145 -0
- package/dist/analyzing/vowelConsonantCount.d.ts +22 -0
- package/dist/analyzing/vowelConsonantCount.js +38 -0
- package/dist/analyzing/wordCount.d.ts +23 -0
- package/dist/analyzing/wordCount.js +33 -0
- package/dist/formatting/capitalize.d.ts +22 -0
- package/dist/formatting/capitalize.js +33 -0
- package/dist/formatting/index.d.ts +11 -0
- package/dist/formatting/index.js +17 -0
- package/dist/formatting/number.d.ts +24 -0
- package/dist/formatting/number.js +30 -0
- package/dist/formatting/phone.d.ts +25 -0
- package/dist/formatting/phone.js +48 -0
- package/dist/index.d.ts +52 -0
- package/dist/index.js +30 -0
- package/dist/tests/analyzing/characterCount.test.d.ts +1 -0
- package/dist/tests/analyzing/characterCount.test.js +19 -0
- package/dist/tests/analyzing/characterFrequency.test.d.ts +1 -0
- package/dist/tests/analyzing/characterFrequency.test.js +22 -0
- package/dist/tests/analyzing/complexity.test.d.ts +1 -0
- package/dist/tests/analyzing/complexity.test.js +28 -0
- package/dist/tests/analyzing/patternCount.test.d.ts +1 -0
- package/dist/tests/analyzing/patternCount.test.js +34 -0
- package/dist/tests/analyzing/readingDuration.test.d.ts +1 -0
- package/dist/tests/analyzing/readingDuration.test.js +45 -0
- package/dist/tests/analyzing/stringSimilarity.test.d.ts +1 -0
- package/dist/tests/analyzing/stringSimilarity.test.js +61 -0
- package/dist/tests/analyzing/vowelConsonantCount.test.d.ts +1 -0
- package/dist/tests/analyzing/vowelConsonantCount.test.js +25 -0
- package/dist/tests/analyzing/wordCount.test.d.ts +1 -0
- package/dist/tests/analyzing/wordCount.test.js +22 -0
- package/dist/tests/formatting/capitalize.test.d.ts +1 -0
- package/dist/tests/formatting/capitalize.test.js +22 -0
- package/dist/tests/formatting/number.test.d.ts +1 -0
- package/dist/tests/formatting/number.test.js +19 -0
- package/dist/tests/formatting/phone.test.d.ts +1 -0
- package/dist/tests/formatting/phone.test.js +25 -0
- package/dist/tests/transformations/camelCase.test.d.ts +1 -0
- package/dist/tests/transformations/camelCase.test.js +19 -0
- package/dist/tests/transformations/capitalizeWords.test.d.ts +1 -0
- package/dist/tests/transformations/capitalizeWords.test.js +19 -0
- package/dist/tests/transformations/constantCase.test.d.ts +1 -0
- package/dist/tests/transformations/constantCase.test.js +19 -0
- package/dist/tests/transformations/deburr.test.d.ts +1 -0
- package/dist/tests/transformations/deburr.test.js +27 -0
- package/dist/tests/transformations/escapeHTML.test.d.ts +1 -0
- package/dist/tests/transformations/escapeHTML.test.js +46 -0
- package/dist/tests/transformations/initials.test.d.ts +1 -0
- package/dist/tests/transformations/initials.test.js +25 -0
- package/dist/tests/transformations/kebabCase.test.d.ts +1 -0
- package/dist/tests/transformations/kebabCase.test.js +19 -0
- package/dist/tests/transformations/maskSegment.test.d.ts +1 -0
- package/dist/tests/transformations/maskSegment.test.js +30 -0
- package/dist/tests/transformations/numberToText.test.d.ts +1 -0
- package/dist/tests/transformations/numberToText.test.js +60 -0
- package/dist/tests/transformations/pascalCase.test.d.ts +1 -0
- package/dist/tests/transformations/pascalCase.test.js +19 -0
- package/dist/tests/transformations/removeDuplicates.test.d.ts +1 -0
- package/dist/tests/transformations/removeDuplicates.test.js +19 -0
- package/dist/tests/transformations/removeSpecialChars.test.d.ts +1 -0
- package/dist/tests/transformations/removeSpecialChars.test.js +22 -0
- package/dist/tests/transformations/removeWords.test.d.ts +1 -0
- package/dist/tests/transformations/removeWords.test.js +25 -0
- package/dist/tests/transformations/snakeCase.test.d.ts +1 -0
- package/dist/tests/transformations/snakeCase.test.js +19 -0
- package/dist/tests/transformations/splitChunks.test.d.ts +1 -0
- package/dist/tests/transformations/splitChunks.test.js +31 -0
- package/dist/tests/transformations/titleCase.test.d.ts +1 -0
- package/dist/tests/transformations/titleCase.test.js +19 -0
- package/dist/tests/transformations/toSlug.test.d.ts +1 -0
- package/dist/tests/transformations/toSlug.test.js +22 -0
- package/dist/tests/transformations/truncateText.test.d.ts +1 -0
- package/dist/tests/transformations/truncateText.test.js +31 -0
- package/dist/tests/validations/isCoordinates.test.d.ts +1 -0
- package/dist/tests/validations/isCoordinates.test.js +18 -0
- package/dist/tests/validations/isDate.test.d.ts +1 -0
- package/dist/tests/validations/isDate.test.js +55 -0
- package/dist/tests/validations/isEmail.smtpUTF8.test.d.ts +1 -0
- package/dist/tests/validations/isEmail.smtpUTF8.test.js +16 -0
- package/dist/tests/validations/isEmail.test.d.ts +1 -0
- package/dist/tests/validations/isEmail.test.js +67 -0
- package/dist/tests/validations/isEmpty.test.d.ts +1 -0
- package/dist/tests/validations/isEmpty.test.js +19 -0
- package/dist/tests/validations/isHexColor.test.d.ts +1 -0
- package/dist/tests/validations/isHexColor.test.js +32 -0
- package/dist/tests/validations/isIPv4.test.d.ts +1 -0
- package/dist/tests/validations/isIPv4.test.js +59 -0
- package/dist/tests/validations/isPalindrome.test.d.ts +1 -0
- package/dist/tests/validations/isPalindrome.test.js +39 -0
- package/dist/tests/validations/isSlug.test.d.ts +1 -0
- package/dist/tests/validations/isSlug.test.js +22 -0
- package/dist/tests/validations/isTypeOf.test.d.ts +1 -0
- package/dist/tests/validations/isTypeOf.test.js +28 -0
- package/dist/tests/validations/isURL.test.d.ts +1 -0
- package/dist/tests/validations/isURL.test.js +18 -0
- package/dist/transformations/camelCase.d.ts +25 -0
- package/dist/transformations/camelCase.js +39 -0
- package/dist/transformations/capitalizeWords.d.ts +22 -0
- package/dist/transformations/capitalizeWords.js +30 -0
- package/dist/transformations/constantCase.d.ts +27 -0
- package/dist/transformations/constantCase.js +41 -0
- package/dist/transformations/deburr.d.ts +7 -0
- package/dist/transformations/deburr.js +16 -0
- package/dist/transformations/escapeHTML.d.ts +24 -0
- package/dist/transformations/escapeHTML.js +36 -0
- package/dist/transformations/index.d.ts +52 -0
- package/dist/transformations/index.js +71 -0
- package/dist/transformations/initials.d.ts +28 -0
- package/dist/transformations/initials.js +49 -0
- package/dist/transformations/kebabCase.d.ts +27 -0
- package/dist/transformations/kebabCase.js +41 -0
- package/dist/transformations/maskSegment.d.ts +9 -0
- package/dist/transformations/maskSegment.js +23 -0
- 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 +26 -0
- package/dist/transformations/pascalCase.js +40 -0
- package/dist/transformations/removeDuplicates.d.ts +22 -0
- package/dist/transformations/removeDuplicates.js +34 -0
- package/dist/transformations/removeSpecialChars.d.ts +23 -0
- package/dist/transformations/removeSpecialChars.js +34 -0
- package/dist/transformations/removeWords.d.ts +28 -0
- package/dist/transformations/removeWords.js +50 -0
- package/dist/transformations/snakeCase.d.ts +27 -0
- package/dist/transformations/snakeCase.js +41 -0
- package/dist/transformations/splitChunks.d.ts +8 -0
- package/dist/transformations/splitChunks.js +24 -0
- package/dist/transformations/titleCase.d.ts +26 -0
- package/dist/transformations/titleCase.js +39 -0
- package/dist/transformations/toSlug.d.ts +25 -0
- package/dist/transformations/toSlug.js +37 -0
- package/dist/transformations/truncateText.d.ts +26 -0
- package/dist/transformations/truncateText.js +44 -0
- package/dist/validations/index.d.ts +29 -0
- package/dist/validations/index.js +41 -0
- package/dist/validations/isCoordinates.d.ts +8 -0
- package/dist/validations/isCoordinates.js +19 -0
- package/dist/validations/isDate.d.ts +18 -0
- package/dist/validations/isDate.js +61 -0
- package/dist/validations/isEmail.d.ts +13 -0
- package/dist/validations/isEmail.js +180 -0
- package/dist/validations/isEmpty.d.ts +10 -0
- package/dist/validations/isEmpty.js +15 -0
- package/dist/validations/isHexColor.d.ts +7 -0
- package/dist/validations/isHexColor.js +15 -0
- package/dist/validations/isIPv4.d.ts +22 -0
- package/dist/validations/isIPv4.js +33 -0
- package/dist/validations/isPalindrome.d.ts +10 -0
- package/dist/validations/isPalindrome.js +21 -0
- package/dist/validations/isSlug.d.ts +28 -0
- package/dist/validations/isSlug.js +37 -0
- package/dist/validations/isTypeOf.d.ts +9 -0
- package/dist/validations/isTypeOf.js +30 -0
- package/dist/validations/isURL.d.ts +22 -0
- package/dist/validations/isURL.js +33 -0
- package/package.json +12 -4
- package/analysis.js +0 -21
- package/formatting.js +0 -37
- package/index.js +0 -75
- package/transformations.js +0 -190
- package/validations.js +0 -80
|
@@ -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
|
+
};
|
|
@@ -0,0 +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
|
+
*/
|
|
26
|
+
export declare function pascalCase(text: string): string;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
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
|
+
*/
|
|
29
|
+
function pascalCase(text) {
|
|
30
|
+
if (text == null)
|
|
31
|
+
return '';
|
|
32
|
+
return text
|
|
33
|
+
.trim()
|
|
34
|
+
.toLowerCase()
|
|
35
|
+
.replace(/[^\w\s]/g, ' ')
|
|
36
|
+
.replace(/_/g, ' ')
|
|
37
|
+
.replace(/\s+/g, ' ')
|
|
38
|
+
.replace(/(^|\s)(.)/g, (_, prefix, character) => character.toUpperCase())
|
|
39
|
+
.replace(/\s/g, '');
|
|
40
|
+
}
|
|
@@ -0,0 +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
|
+
*/
|
|
22
|
+
export declare function removeDuplicates(text: string): string;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
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
|
+
*/
|
|
25
|
+
function removeDuplicates(text) {
|
|
26
|
+
if (typeof text !== 'string') {
|
|
27
|
+
throw new TypeError('Input must be a string');
|
|
28
|
+
}
|
|
29
|
+
const wordSet = new Set();
|
|
30
|
+
text.split(' ').forEach((word) => {
|
|
31
|
+
wordSet.add(word);
|
|
32
|
+
});
|
|
33
|
+
return Array.from(wordSet).join(' ');
|
|
34
|
+
}
|
|
@@ -0,0 +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
|
+
*/
|
|
23
|
+
export declare function removeSpecialChars(text: string, replacement?: string): string;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
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
|
+
*/
|
|
26
|
+
function removeSpecialChars(text, replacement = '') {
|
|
27
|
+
if (typeof text !== 'string') {
|
|
28
|
+
throw new TypeError('Invalid argument. Expected a string.');
|
|
29
|
+
}
|
|
30
|
+
if (typeof replacement !== 'string') {
|
|
31
|
+
throw new TypeError('Replacement must be a string.');
|
|
32
|
+
}
|
|
33
|
+
return text.replace(/[^\w\s]/gi, replacement);
|
|
34
|
+
}
|
|
@@ -0,0 +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
|
+
*/
|
|
28
|
+
export declare function removeWords(str: string, wordsToRemove: string | string[]): string;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
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
|
+
*/
|
|
31
|
+
function removeWords(str, wordsToRemove) {
|
|
32
|
+
if (str === null || str === undefined) {
|
|
33
|
+
throw new TypeError('Input string cannot be null or undefined');
|
|
34
|
+
}
|
|
35
|
+
if (typeof str !== 'string') {
|
|
36
|
+
throw new TypeError('First parameter must be a string');
|
|
37
|
+
}
|
|
38
|
+
if (wordsToRemove === null || wordsToRemove === undefined) {
|
|
39
|
+
throw new TypeError('Words to remove cannot be null or undefined');
|
|
40
|
+
}
|
|
41
|
+
if (typeof wordsToRemove !== 'string' && !Array.isArray(wordsToRemove)) {
|
|
42
|
+
throw new TypeError('Second parameter must be a string or an array of strings');
|
|
43
|
+
}
|
|
44
|
+
if (str === '') {
|
|
45
|
+
return '';
|
|
46
|
+
}
|
|
47
|
+
const wordsArray = Array.isArray(wordsToRemove) ? wordsToRemove : [wordsToRemove];
|
|
48
|
+
const regex = new RegExp(`\\b(${wordsArray.join('|')})\\b`, 'gi');
|
|
49
|
+
return str.replace(regex, '').replace(/\s+/g, ' ').trim();
|
|
50
|
+
}
|
|
@@ -0,0 +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
|
+
*/
|
|
27
|
+
export declare function snakeCase(text: string): string;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
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
|
+
*/
|
|
30
|
+
function snakeCase(text) {
|
|
31
|
+
if (text == null)
|
|
32
|
+
return '';
|
|
33
|
+
return text
|
|
34
|
+
.trim()
|
|
35
|
+
.replace(/[\s-]+/g, '_')
|
|
36
|
+
.replace(/([a-z])([A-Z])/g, '$1_$2')
|
|
37
|
+
.replace(/[^\w_]/g, '_')
|
|
38
|
+
.toLowerCase()
|
|
39
|
+
.replace(/_+/g, '_')
|
|
40
|
+
.replace(/^_+|_+$/g, '');
|
|
41
|
+
}
|
|
@@ -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[];
|