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
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
1
|
+
export * from './analyzing';
|
|
2
|
+
export * from './formatting';
|
|
3
|
+
export * from './transformations';
|
|
4
|
+
export * from './validations';
|
|
5
5
|
declare const _default: {
|
|
6
6
|
analyzing: {
|
|
7
7
|
characterCount: typeof import("./analyzing").characterCount;
|
|
@@ -10,6 +10,8 @@ declare const _default: {
|
|
|
10
10
|
readingDuration: typeof import("./analyzing").readingDuration;
|
|
11
11
|
wordCount: typeof import("./analyzing").wordCount;
|
|
12
12
|
stringSimilarity: typeof import("./analyzing").stringSimilarity;
|
|
13
|
+
patternCount: typeof import("./analyzing").patternCount;
|
|
14
|
+
vowelConsonantCount: typeof import("./analyzing").vowelConsonantCount;
|
|
13
15
|
};
|
|
14
16
|
formatting: {
|
|
15
17
|
capitalize: typeof import("./formatting").capitalize;
|
|
@@ -33,8 +35,10 @@ declare const _default: {
|
|
|
33
35
|
escapeHtml: typeof import("./transformations").escapeHtml;
|
|
34
36
|
maskSegment: typeof import("./transformations").maskSegment;
|
|
35
37
|
deburr: typeof import("./transformations/deburr").deburr;
|
|
38
|
+
numberToText: typeof import("./transformations").numberToText;
|
|
36
39
|
};
|
|
37
40
|
validations: {
|
|
41
|
+
isCoordinates: typeof import("./validations").isCoordinates;
|
|
38
42
|
isDate: typeof import("./validations").isDate;
|
|
39
43
|
isEmail: typeof import("./validations").isEmail;
|
|
40
44
|
isEmpty: typeof import("./validations").isEmpty;
|
|
@@ -42,6 +46,7 @@ declare const _default: {
|
|
|
42
46
|
isURL: typeof import("./validations").isURL;
|
|
43
47
|
isIPv4: typeof import("./validations").isIPv4;
|
|
44
48
|
isHexColor: typeof import("./validations").isHexColor;
|
|
49
|
+
isPalindrome: typeof import("./validations").isPalindrome;
|
|
45
50
|
};
|
|
46
51
|
};
|
|
47
52
|
export default _default;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,34 @@
|
|
|
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
|
+
const node_test_1 = require("node:test");
|
|
7
|
+
const node_assert_1 = __importDefault(require("node:assert"));
|
|
8
|
+
const patternCount_1 = require("../../analyzing/patternCount");
|
|
9
|
+
(0, node_test_1.describe)('patternCount', () => {
|
|
10
|
+
(0, node_test_1.it)('returns 0 for empty string', () => {
|
|
11
|
+
node_assert_1.default.deepStrictEqual((0, patternCount_1.patternCount)('', 'aa'), 0);
|
|
12
|
+
});
|
|
13
|
+
(0, node_test_1.it)('returns 0 for empty pattern', () => {
|
|
14
|
+
node_assert_1.default.deepStrictEqual((0, patternCount_1.patternCount)('abc', ''), 0);
|
|
15
|
+
});
|
|
16
|
+
(0, node_test_1.it)('returns 0 for empty string and empty pattern', () => {
|
|
17
|
+
node_assert_1.default.deepStrictEqual((0, patternCount_1.patternCount)('', ''), 0);
|
|
18
|
+
});
|
|
19
|
+
(0, node_test_1.it)('returns correct count for single character pattern', () => {
|
|
20
|
+
node_assert_1.default.strictEqual((0, patternCount_1.patternCount)('abcabcabc', 'a'), 3);
|
|
21
|
+
});
|
|
22
|
+
(0, node_test_1.it)('returns correct count for multi-character pattern', () => {
|
|
23
|
+
node_assert_1.default.strictEqual((0, patternCount_1.patternCount)('abcabcabc', 'ab'), 3);
|
|
24
|
+
});
|
|
25
|
+
(0, node_test_1.it)('returns correct count for overlapping patterns', () => {
|
|
26
|
+
node_assert_1.default.strictEqual((0, patternCount_1.patternCount)('ababababa', 'aba'), 4);
|
|
27
|
+
});
|
|
28
|
+
(0, node_test_1.it)('returns correct count for non-overlapping patterns', () => {
|
|
29
|
+
node_assert_1.default.strictEqual((0, patternCount_1.patternCount)('abababab', 'ab'), 4);
|
|
30
|
+
});
|
|
31
|
+
(0, node_test_1.it)('returns 0 for pattern not found', () => {
|
|
32
|
+
node_assert_1.default.strictEqual((0, patternCount_1.patternCount)('abcdefg', 'xyz'), 0);
|
|
33
|
+
});
|
|
34
|
+
});
|
|
@@ -6,39 +6,39 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const node_test_1 = require("node:test");
|
|
7
7
|
const node_assert_1 = __importDefault(require("node:assert"));
|
|
8
8
|
const readingDuration_1 = require("../../analyzing/readingDuration");
|
|
9
|
-
(0, node_test_1.describe)(
|
|
9
|
+
(0, node_test_1.describe)('readingDuration', () => {
|
|
10
10
|
const testCases = [
|
|
11
|
-
{ text:
|
|
12
|
-
{ text:
|
|
11
|
+
{ text: '', expectedDuration: 0 }, // Empty string
|
|
12
|
+
{ text: 'This is a short text', expectedDuration: 0 }, // 5 words
|
|
13
13
|
{
|
|
14
|
-
text:
|
|
14
|
+
text: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',
|
|
15
15
|
expectedDuration: 0, // 19 words
|
|
16
16
|
},
|
|
17
|
-
{ text:
|
|
18
|
-
{ text:
|
|
17
|
+
{ text: ' This text has extra spaces ', expectedDuration: 0 }, // 6 words
|
|
18
|
+
{ text: 'Word', expectedDuration: 0 }, // 1 word
|
|
19
19
|
{
|
|
20
|
-
text:
|
|
20
|
+
text: 'A longer text with exactly twenty-three words to test the calculation properly.',
|
|
21
21
|
expectedDuration: 0, // 23 words
|
|
22
22
|
},
|
|
23
23
|
{
|
|
24
|
-
text:
|
|
24
|
+
text: 'This text contains fifty words. It is designed to test the reading duration function with a larger input. The function should calculate the duration accurately based on the average reading speed.',
|
|
25
25
|
expectedDuration: 0, // 50 words
|
|
26
26
|
},
|
|
27
27
|
{
|
|
28
|
-
text: Array(9999).fill(
|
|
28
|
+
text: Array(9999).fill('Word').join(' '), // Generates a text with 9999 words
|
|
29
29
|
expectedDuration: 43, // 9999 words / 230 words per minute ≈ 43 minutes
|
|
30
30
|
},
|
|
31
31
|
{
|
|
32
|
-
text: Array(230).fill(
|
|
32
|
+
text: Array(230).fill('Word').join(' '), // Generates a text with 230 words
|
|
33
33
|
expectedDuration: 1, // 230 words / 230 words per minute = 1 minute
|
|
34
34
|
},
|
|
35
35
|
{
|
|
36
|
-
text: Array(460).fill(
|
|
36
|
+
text: Array(460).fill('Word').join(' '), // Generates a text with 460 words
|
|
37
37
|
expectedDuration: 2, // 460 words / 230 words per minute = 2 minutes
|
|
38
38
|
},
|
|
39
39
|
];
|
|
40
40
|
testCases.forEach(({ text, expectedDuration }) => {
|
|
41
|
-
(0, node_test_1.it)(`returns ${expectedDuration} for text with ${text.split(
|
|
41
|
+
(0, node_test_1.it)(`returns ${expectedDuration} for text with ${text.split(' ').length} words`, () => {
|
|
42
42
|
node_assert_1.default.strictEqual((0, readingDuration_1.readingDuration)(text), expectedDuration);
|
|
43
43
|
});
|
|
44
44
|
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
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
|
+
const node_test_1 = require("node:test");
|
|
7
|
+
const node_assert_1 = __importDefault(require("node:assert"));
|
|
8
|
+
const vowelConsonantCount_1 = require("../../analyzing/vowelConsonantCount");
|
|
9
|
+
(0, node_test_1.describe)('vowelConsonantCount', () => {
|
|
10
|
+
(0, node_test_1.it)('returns 0s for empty string', () => {
|
|
11
|
+
node_assert_1.default.deepStrictEqual((0, vowelConsonantCount_1.vowelConsonantCount)(''), { vowels: 0, consonants: 0 });
|
|
12
|
+
});
|
|
13
|
+
(0, node_test_1.it)('counts lowercase vowels and consonants', () => {
|
|
14
|
+
node_assert_1.default.deepStrictEqual((0, vowelConsonantCount_1.vowelConsonantCount)('hello'), { vowels: 2, consonants: 3 });
|
|
15
|
+
});
|
|
16
|
+
(0, node_test_1.it)('counts uppercase vowels and consonants', () => {
|
|
17
|
+
node_assert_1.default.deepStrictEqual((0, vowelConsonantCount_1.vowelConsonantCount)('HELLO'), { vowels: 2, consonants: 3 });
|
|
18
|
+
});
|
|
19
|
+
(0, node_test_1.it)('counts vowels and consonants ignoring special characters and whitespaces', () => {
|
|
20
|
+
node_assert_1.default.deepStrictEqual((0, vowelConsonantCount_1.vowelConsonantCount)('Hello, World!'), { vowels: 3, consonants: 7 });
|
|
21
|
+
});
|
|
22
|
+
(0, node_test_1.it)('throws if input is not a string', () => {
|
|
23
|
+
node_assert_1.default.throws(() => (0, vowelConsonantCount_1.vowelConsonantCount)(123), /Input must be a string/);
|
|
24
|
+
});
|
|
25
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,60 @@
|
|
|
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
|
+
const node_test_1 = require("node:test");
|
|
7
|
+
const node_assert_1 = __importDefault(require("node:assert"));
|
|
8
|
+
const transformations_1 = require("../../transformations");
|
|
9
|
+
(0, node_test_1.describe)("numberToText", () => {
|
|
10
|
+
(0, node_test_1.describe)("Param error handling", () => {
|
|
11
|
+
node_assert_1.default.throws(() => (0, transformations_1.numberToText)("aaaa"), /Num param should be number/i);
|
|
12
|
+
node_assert_1.default.throws(() => (0, transformations_1.numberToText)(1000000000001), RangeError);
|
|
13
|
+
node_assert_1.default.throws(() => (0, transformations_1.numberToText)(-1000000000001), RangeError);
|
|
14
|
+
const validLanguages = ['en', 'pl'];
|
|
15
|
+
const errorMessage = `Language must be one of: ${validLanguages.join(', ')}`;
|
|
16
|
+
node_assert_1.default.throws(() => (0, transformations_1.numberToText)(123, "invalid"), new RegExp(errorMessage, "i"));
|
|
17
|
+
});
|
|
18
|
+
(0, node_test_1.describe)("Conversion cases - en", () => {
|
|
19
|
+
node_assert_1.default.strictEqual((0, transformations_1.numberToText)(0), "zero");
|
|
20
|
+
node_assert_1.default.strictEqual((0, transformations_1.numberToText)(1), "one");
|
|
21
|
+
node_assert_1.default.strictEqual((0, transformations_1.numberToText)(5), "five");
|
|
22
|
+
node_assert_1.default.strictEqual((0, transformations_1.numberToText)(10), "ten");
|
|
23
|
+
node_assert_1.default.strictEqual((0, transformations_1.numberToText)(15), "fifteen");
|
|
24
|
+
node_assert_1.default.strictEqual((0, transformations_1.numberToText)(21), "twenty-one");
|
|
25
|
+
node_assert_1.default.strictEqual((0, transformations_1.numberToText)(99), "ninety-nine");
|
|
26
|
+
node_assert_1.default.strictEqual((0, transformations_1.numberToText)(100), "one hundred");
|
|
27
|
+
node_assert_1.default.strictEqual((0, transformations_1.numberToText)(101), "one hundred one");
|
|
28
|
+
node_assert_1.default.strictEqual((0, transformations_1.numberToText)(215), "two hundred fifteen");
|
|
29
|
+
node_assert_1.default.strictEqual((0, transformations_1.numberToText)(1000), "one thousand");
|
|
30
|
+
node_assert_1.default.strictEqual((0, transformations_1.numberToText)(2023), "two thousand twenty-three");
|
|
31
|
+
node_assert_1.default.strictEqual((0, transformations_1.numberToText)(1000000), "one million");
|
|
32
|
+
node_assert_1.default.strictEqual((0, transformations_1.numberToText)(1200000), "one million two hundred thousand");
|
|
33
|
+
node_assert_1.default.strictEqual((0, transformations_1.numberToText)(1000000000), "one billion");
|
|
34
|
+
node_assert_1.default.strictEqual((0, transformations_1.numberToText)(1000000000000), "one trillion");
|
|
35
|
+
node_assert_1.default.strictEqual((0, transformations_1.numberToText)(-1), "minus one");
|
|
36
|
+
node_assert_1.default.strictEqual((0, transformations_1.numberToText)(-215), "minus two hundred fifteen");
|
|
37
|
+
node_assert_1.default.strictEqual((0, transformations_1.numberToText)(-1000000), "minus one million");
|
|
38
|
+
});
|
|
39
|
+
(0, node_test_1.describe)("Conversion cases - pl", () => {
|
|
40
|
+
node_assert_1.default.strictEqual((0, transformations_1.numberToText)(0, 'pl'), "zero");
|
|
41
|
+
node_assert_1.default.strictEqual((0, transformations_1.numberToText)(1, 'pl'), "jeden");
|
|
42
|
+
node_assert_1.default.strictEqual((0, transformations_1.numberToText)(5, 'pl'), "pięć");
|
|
43
|
+
node_assert_1.default.strictEqual((0, transformations_1.numberToText)(10, 'pl'), "dziesięć");
|
|
44
|
+
node_assert_1.default.strictEqual((0, transformations_1.numberToText)(15, 'pl'), "piętnaście");
|
|
45
|
+
node_assert_1.default.strictEqual((0, transformations_1.numberToText)(21, 'pl'), "dwadzieścia jeden");
|
|
46
|
+
node_assert_1.default.strictEqual((0, transformations_1.numberToText)(99, 'pl'), "dziewięćdziesiąt dziewięć");
|
|
47
|
+
node_assert_1.default.strictEqual((0, transformations_1.numberToText)(100, 'pl'), "sto");
|
|
48
|
+
node_assert_1.default.strictEqual((0, transformations_1.numberToText)(101, 'pl'), "sto jeden");
|
|
49
|
+
node_assert_1.default.strictEqual((0, transformations_1.numberToText)(215, 'pl'), "dwieście piętnaście");
|
|
50
|
+
node_assert_1.default.strictEqual((0, transformations_1.numberToText)(1000, 'pl'), "tysiąc");
|
|
51
|
+
node_assert_1.default.strictEqual((0, transformations_1.numberToText)(2023, 'pl'), "dwa tysiące dwadzieścia trzy");
|
|
52
|
+
node_assert_1.default.strictEqual((0, transformations_1.numberToText)(1000000, 'pl'), "milion");
|
|
53
|
+
node_assert_1.default.strictEqual((0, transformations_1.numberToText)(1200000, 'pl'), "milion dwieście tysięcy");
|
|
54
|
+
node_assert_1.default.strictEqual((0, transformations_1.numberToText)(1000000000, 'pl'), "miliard");
|
|
55
|
+
node_assert_1.default.strictEqual((0, transformations_1.numberToText)(1000000000000, 'pl'), "bilion");
|
|
56
|
+
node_assert_1.default.strictEqual((0, transformations_1.numberToText)(-1, 'pl'), "minus jeden");
|
|
57
|
+
node_assert_1.default.strictEqual((0, transformations_1.numberToText)(-215, 'pl'), "minus dwieście piętnaście");
|
|
58
|
+
node_assert_1.default.strictEqual((0, transformations_1.numberToText)(-1000000, 'pl'), "minus milion");
|
|
59
|
+
});
|
|
60
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
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
|
+
const node_test_1 = require("node:test");
|
|
7
|
+
const node_assert_1 = __importDefault(require("node:assert"));
|
|
8
|
+
const splitChunks_1 = require("../../transformations/splitChunks");
|
|
9
|
+
(0, node_test_1.describe)('splitChunks', () => {
|
|
10
|
+
(0, node_test_1.it)('creates chunks of size 3', () => {
|
|
11
|
+
node_assert_1.default.deepStrictEqual((0, splitChunks_1.splitChunks)('hello world', 3), ['hel', 'lo ', 'wor', 'ld']);
|
|
12
|
+
});
|
|
13
|
+
(0, node_test_1.it)('creates chunks of size 2', () => {
|
|
14
|
+
node_assert_1.default.deepStrictEqual((0, splitChunks_1.splitChunks)('hello world', 2), ['he', 'll', 'o ', 'wo', 'rl', 'd']);
|
|
15
|
+
});
|
|
16
|
+
(0, node_test_1.it)('creates chunks of size 1', () => {
|
|
17
|
+
node_assert_1.default.deepStrictEqual((0, splitChunks_1.splitChunks)('hello world'), [
|
|
18
|
+
'h',
|
|
19
|
+
'e',
|
|
20
|
+
'l',
|
|
21
|
+
'l',
|
|
22
|
+
'o',
|
|
23
|
+
' ',
|
|
24
|
+
'w',
|
|
25
|
+
'o',
|
|
26
|
+
'r',
|
|
27
|
+
'l',
|
|
28
|
+
'd',
|
|
29
|
+
]);
|
|
30
|
+
});
|
|
31
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
const node_test_1 = require("node:test");
|
|
7
|
+
const node_assert_1 = __importDefault(require("node:assert"));
|
|
8
|
+
const isCoordinates_1 = require("../../validations/isCoordinates");
|
|
9
|
+
(0, node_test_1.describe)('isCoordinates', () => {
|
|
10
|
+
(0, node_test_1.it)('returns true for valid coordinates', () => {
|
|
11
|
+
node_assert_1.default.strictEqual((0, isCoordinates_1.isCoordinates)(48.8582, 2.2945), true);
|
|
12
|
+
node_assert_1.default.strictEqual((0, isCoordinates_1.isCoordinates)(40.748817, -73.985428), true);
|
|
13
|
+
});
|
|
14
|
+
(0, node_test_1.it)('returns false for invalid coordinates', () => {
|
|
15
|
+
node_assert_1.default.strictEqual((0, isCoordinates_1.isCoordinates)(200, 200), false);
|
|
16
|
+
node_assert_1.default.strictEqual((0, isCoordinates_1.isCoordinates)(-200, -200), false);
|
|
17
|
+
});
|
|
18
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
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
|
+
const node_test_1 = require("node:test");
|
|
7
|
+
const node_assert_1 = __importDefault(require("node:assert"));
|
|
8
|
+
const isEmail_1 = require("../../validations/isEmail");
|
|
9
|
+
(0, node_test_1.describe)('isEmail (SMTPUTF8)', () => {
|
|
10
|
+
(0, node_test_1.it)('accepts emoji in local-part by default', () => {
|
|
11
|
+
node_assert_1.default.strictEqual((0, isEmail_1.isEmail)('I❤️CHOCOLATE@example.com'), true);
|
|
12
|
+
});
|
|
13
|
+
(0, node_test_1.it)('rejects emoji in local-part when smtpUTF8 is explicitly disabled', () => {
|
|
14
|
+
node_assert_1.default.strictEqual((0, isEmail_1.isEmail)('I❤️CHOCOLATE@example.com', { smtpUTF8: false }), false);
|
|
15
|
+
});
|
|
16
|
+
});
|
|
@@ -6,12 +6,62 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const node_test_1 = require("node:test");
|
|
7
7
|
const node_assert_1 = __importDefault(require("node:assert"));
|
|
8
8
|
const isEmail_1 = require("../../validations/isEmail");
|
|
9
|
-
(0, node_test_1.describe)(
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
(0, node_test_1.describe)("isEmail", () => {
|
|
10
|
+
//
|
|
11
|
+
// ✅ Basic valid emails
|
|
12
|
+
//
|
|
13
|
+
(0, node_test_1.it)("returns true for basic valid emails", () => {
|
|
14
|
+
node_assert_1.default.strictEqual((0, isEmail_1.isEmail)("foo@bar.com"), true);
|
|
15
|
+
node_assert_1.default.strictEqual((0, isEmail_1.isEmail)("test@example.org"), true);
|
|
16
|
+
node_assert_1.default.strictEqual((0, isEmail_1.isEmail)("very.common@example.com"), true);
|
|
17
|
+
node_assert_1.default.strictEqual((0, isEmail_1.isEmail)("long.email-address-with-hyphens@and.subdomains.example.com"), true);
|
|
12
18
|
});
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
19
|
+
//
|
|
20
|
+
// ✅ Special characters in local-part
|
|
21
|
+
//
|
|
22
|
+
(0, node_test_1.it)("returns true for special characters", () => {
|
|
23
|
+
node_assert_1.default.strictEqual((0, isEmail_1.isEmail)("test+tag@example.com"), true);
|
|
24
|
+
node_assert_1.default.strictEqual((0, isEmail_1.isEmail)("user.name+tag+sorting@example.com"), true);
|
|
25
|
+
node_assert_1.default.strictEqual((0, isEmail_1.isEmail)("test/test@example.com"), true);
|
|
26
|
+
});
|
|
27
|
+
//
|
|
28
|
+
// ✅ IPv4 address literal
|
|
29
|
+
//
|
|
30
|
+
(0, node_test_1.it)("returns true for IPv4 address literal", () => {
|
|
31
|
+
node_assert_1.default.strictEqual((0, isEmail_1.isEmail)("user@[192.168.1.1]"), true);
|
|
32
|
+
});
|
|
33
|
+
//
|
|
34
|
+
// ✅ Quoted local-parts (RFC 5322)
|
|
35
|
+
//
|
|
36
|
+
(0, node_test_1.it)("returns true for quoted local-parts", () => {
|
|
37
|
+
node_assert_1.default.strictEqual((0, isEmail_1.isEmail)('"much.more unusual"@example.com'), true);
|
|
38
|
+
node_assert_1.default.strictEqual((0, isEmail_1.isEmail)('"very.unusual.@.unusual.com"@example.com'), true);
|
|
39
|
+
node_assert_1.default.strictEqual((0, isEmail_1.isEmail)('"very.(),:;<>[]".VERY."very@\\ "very".unusual"@strange.example.com'), true);
|
|
40
|
+
});
|
|
41
|
+
//
|
|
42
|
+
// ✅ IPv6 domain literal
|
|
43
|
+
//
|
|
44
|
+
(0, node_test_1.it)("returns true for IPv6 domain literals", () => {
|
|
45
|
+
node_assert_1.default.strictEqual((0, isEmail_1.isEmail)("user@[IPv6:2001:db8::1]"), true);
|
|
46
|
+
});
|
|
47
|
+
//
|
|
48
|
+
// ❌ Invalid emails
|
|
49
|
+
//
|
|
50
|
+
(0, node_test_1.it)("returns false for invalid emails", () => {
|
|
51
|
+
node_assert_1.default.strictEqual((0, isEmail_1.isEmail)(""), false);
|
|
52
|
+
node_assert_1.default.strictEqual((0, isEmail_1.isEmail)("@example.com"), false);
|
|
53
|
+
node_assert_1.default.strictEqual((0, isEmail_1.isEmail)("test@"), false);
|
|
54
|
+
node_assert_1.default.strictEqual((0, isEmail_1.isEmail)("test"), false);
|
|
55
|
+
node_assert_1.default.strictEqual((0, isEmail_1.isEmail)("test@.com"), false);
|
|
56
|
+
node_assert_1.default.strictEqual((0, isEmail_1.isEmail)("test..test@example.com"), false);
|
|
57
|
+
node_assert_1.default.strictEqual((0, isEmail_1.isEmail)(".test@example.com"), false);
|
|
58
|
+
node_assert_1.default.strictEqual((0, isEmail_1.isEmail)("test.@example.com"), false);
|
|
59
|
+
});
|
|
60
|
+
//
|
|
61
|
+
// ❌ Invalid quoted emails
|
|
62
|
+
//
|
|
63
|
+
(0, node_test_1.it)("returns false for invalid quoted local-parts", () => {
|
|
64
|
+
node_assert_1.default.strictEqual((0, isEmail_1.isEmail)('"unclosed-quote@example.com'), false);
|
|
65
|
+
node_assert_1.default.strictEqual((0, isEmail_1.isEmail)('"missing"quotes@@example.com'), false);
|
|
16
66
|
});
|
|
17
67
|
});
|
|
@@ -6,27 +6,27 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const node_test_1 = require("node:test");
|
|
7
7
|
const node_assert_1 = __importDefault(require("node:assert"));
|
|
8
8
|
const isHexColor_1 = require("../../validations/isHexColor");
|
|
9
|
-
(0, node_test_1.describe)(
|
|
10
|
-
(0, node_test_1.it)(
|
|
11
|
-
node_assert_1.default.strictEqual((0, isHexColor_1.isHexColor)(
|
|
12
|
-
node_assert_1.default.strictEqual((0, isHexColor_1.isHexColor)(
|
|
13
|
-
node_assert_1.default.strictEqual((0, isHexColor_1.isHexColor)(
|
|
14
|
-
node_assert_1.default.strictEqual((0, isHexColor_1.isHexColor)(
|
|
15
|
-
node_assert_1.default.strictEqual((0, isHexColor_1.isHexColor)(
|
|
16
|
-
node_assert_1.default.strictEqual((0, isHexColor_1.isHexColor)(
|
|
9
|
+
(0, node_test_1.describe)('isHexColor', () => {
|
|
10
|
+
(0, node_test_1.it)('returns true for valid hex colors', () => {
|
|
11
|
+
node_assert_1.default.strictEqual((0, isHexColor_1.isHexColor)('#abc'), true);
|
|
12
|
+
node_assert_1.default.strictEqual((0, isHexColor_1.isHexColor)('abc'), true);
|
|
13
|
+
node_assert_1.default.strictEqual((0, isHexColor_1.isHexColor)('#a1b2c3'), true);
|
|
14
|
+
node_assert_1.default.strictEqual((0, isHexColor_1.isHexColor)('a1b2c3'), true);
|
|
15
|
+
node_assert_1.default.strictEqual((0, isHexColor_1.isHexColor)('#A1B2C3'), true);
|
|
16
|
+
node_assert_1.default.strictEqual((0, isHexColor_1.isHexColor)(' #fff '), true);
|
|
17
17
|
});
|
|
18
|
-
(0, node_test_1.it)(
|
|
19
|
-
node_assert_1.default.strictEqual((0, isHexColor_1.isHexColor)(
|
|
20
|
-
node_assert_1.default.strictEqual((0, isHexColor_1.isHexColor)(
|
|
21
|
-
node_assert_1.default.strictEqual((0, isHexColor_1.isHexColor)(
|
|
22
|
-
node_assert_1.default.strictEqual((0, isHexColor_1.isHexColor)(
|
|
23
|
-
node_assert_1.default.strictEqual((0, isHexColor_1.isHexColor)(
|
|
24
|
-
node_assert_1.default.strictEqual((0, isHexColor_1.isHexColor)(
|
|
25
|
-
node_assert_1.default.strictEqual((0, isHexColor_1.isHexColor)(
|
|
26
|
-
node_assert_1.default.strictEqual((0, isHexColor_1.isHexColor)(
|
|
27
|
-
node_assert_1.default.strictEqual((0, isHexColor_1.isHexColor)(
|
|
28
|
-
node_assert_1.default.strictEqual((0, isHexColor_1.isHexColor)(
|
|
29
|
-
node_assert_1.default.strictEqual((0, isHexColor_1.isHexColor)(
|
|
30
|
-
node_assert_1.default.strictEqual((0, isHexColor_1.isHexColor)(
|
|
18
|
+
(0, node_test_1.it)('returns false for invalid hex colors', () => {
|
|
19
|
+
node_assert_1.default.strictEqual((0, isHexColor_1.isHexColor)('#12G'), false);
|
|
20
|
+
node_assert_1.default.strictEqual((0, isHexColor_1.isHexColor)('xyz'), false);
|
|
21
|
+
node_assert_1.default.strictEqual((0, isHexColor_1.isHexColor)('#ab'), false);
|
|
22
|
+
node_assert_1.default.strictEqual((0, isHexColor_1.isHexColor)('#12345'), false);
|
|
23
|
+
node_assert_1.default.strictEqual((0, isHexColor_1.isHexColor)('12345'), false);
|
|
24
|
+
node_assert_1.default.strictEqual((0, isHexColor_1.isHexColor)('#1234567'), false);
|
|
25
|
+
node_assert_1.default.strictEqual((0, isHexColor_1.isHexColor)('1234567'), false);
|
|
26
|
+
node_assert_1.default.strictEqual((0, isHexColor_1.isHexColor)('#1234g6'), false);
|
|
27
|
+
node_assert_1.default.strictEqual((0, isHexColor_1.isHexColor)('1234g6'), false);
|
|
28
|
+
node_assert_1.default.strictEqual((0, isHexColor_1.isHexColor)(''), false);
|
|
29
|
+
node_assert_1.default.strictEqual((0, isHexColor_1.isHexColor)(' '), false);
|
|
30
|
+
node_assert_1.default.strictEqual((0, isHexColor_1.isHexColor)('blue'), false);
|
|
31
31
|
});
|
|
32
32
|
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,39 @@
|
|
|
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
|
+
const node_test_1 = require("node:test");
|
|
7
|
+
const node_assert_1 = __importDefault(require("node:assert"));
|
|
8
|
+
const isPalindrome_1 = require("../../validations/isPalindrome");
|
|
9
|
+
(0, node_test_1.describe)('isPalindrome', () => {
|
|
10
|
+
(0, node_test_1.it)('returns true for simple palindromes', () => {
|
|
11
|
+
node_assert_1.default.strictEqual((0, isPalindrome_1.isPalindrome)('racecar'), true);
|
|
12
|
+
node_assert_1.default.strictEqual((0, isPalindrome_1.isPalindrome)('madam'), true);
|
|
13
|
+
});
|
|
14
|
+
(0, node_test_1.it)('returns false for non-palindromes', () => {
|
|
15
|
+
node_assert_1.default.strictEqual((0, isPalindrome_1.isPalindrome)('hello'), false);
|
|
16
|
+
node_assert_1.default.strictEqual((0, isPalindrome_1.isPalindrome)('world'), false);
|
|
17
|
+
});
|
|
18
|
+
(0, node_test_1.it)('is case-insensitive', () => {
|
|
19
|
+
node_assert_1.default.strictEqual((0, isPalindrome_1.isPalindrome)('RaceCar'), true);
|
|
20
|
+
node_assert_1.default.strictEqual((0, isPalindrome_1.isPalindrome)('MadAm'), true);
|
|
21
|
+
});
|
|
22
|
+
(0, node_test_1.it)('ignores punctuation and spaces', () => {
|
|
23
|
+
node_assert_1.default.strictEqual((0, isPalindrome_1.isPalindrome)('A man, a plan, a canal: Panama'), true);
|
|
24
|
+
node_assert_1.default.strictEqual((0, isPalindrome_1.isPalindrome)('No lemon, no melon!'), true);
|
|
25
|
+
});
|
|
26
|
+
(0, node_test_1.it)('returns true for empty string and single characters', () => {
|
|
27
|
+
node_assert_1.default.strictEqual((0, isPalindrome_1.isPalindrome)(''), true);
|
|
28
|
+
node_assert_1.default.strictEqual((0, isPalindrome_1.isPalindrome)('x'), true);
|
|
29
|
+
});
|
|
30
|
+
(0, node_test_1.it)('handles strings with only special characters', () => {
|
|
31
|
+
node_assert_1.default.strictEqual((0, isPalindrome_1.isPalindrome)('?!'), true); // cleans to ''
|
|
32
|
+
node_assert_1.default.strictEqual((0, isPalindrome_1.isPalindrome)('!@#$$#@!'), true); // also cleans to ''
|
|
33
|
+
});
|
|
34
|
+
(0, node_test_1.it)('throws an error if input is not a string', () => {
|
|
35
|
+
node_assert_1.default.throws(() => (0, isPalindrome_1.isPalindrome)(123), /Input must be a string/);
|
|
36
|
+
node_assert_1.default.throws(() => (0, isPalindrome_1.isPalindrome)(null), /Input must be a string/);
|
|
37
|
+
node_assert_1.default.throws(() => (0, isPalindrome_1.isPalindrome)(undefined), /Input must be a string/);
|
|
38
|
+
});
|
|
39
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
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
|
+
const node_test_1 = require("node:test");
|
|
7
|
+
const node_assert_1 = __importDefault(require("node:assert"));
|
|
8
|
+
const isTypeOf_1 = require("../../validations/isTypeOf");
|
|
9
|
+
(0, node_test_1.describe)('isType', () => {
|
|
10
|
+
(0, node_test_1.it)('returns true for valid file', () => {
|
|
11
|
+
node_assert_1.default.strictEqual((0, isTypeOf_1.isTypeOf)('photo.PNG', 'image'), true);
|
|
12
|
+
});
|
|
13
|
+
(0, node_test_1.it)('returns false for unknown extension', () => {
|
|
14
|
+
node_assert_1.default.strictEqual((0, isTypeOf_1.isTypeOf)('unknown.xyz', 'document'), false);
|
|
15
|
+
});
|
|
16
|
+
(0, node_test_1.it)('returns false for unknown type category', () => {
|
|
17
|
+
node_assert_1.default.strictEqual((0, isTypeOf_1.isTypeOf)('photo.png', 'media'), false);
|
|
18
|
+
});
|
|
19
|
+
(0, node_test_1.it)('returns false for mismatched type', () => {
|
|
20
|
+
node_assert_1.default.strictEqual((0, isTypeOf_1.isTypeOf)('video.mp4', 'document'), false);
|
|
21
|
+
});
|
|
22
|
+
(0, node_test_1.it)('returns false for missing extension', () => {
|
|
23
|
+
node_assert_1.default.strictEqual((0, isTypeOf_1.isTypeOf)('filewithoutextension', 'image'), false);
|
|
24
|
+
});
|
|
25
|
+
(0, node_test_1.it)('handles URL with query and hash fragments', () => {
|
|
26
|
+
node_assert_1.default.strictEqual((0, isTypeOf_1.isTypeOf)('https://example.com/pic.jpeg?version=2#section', 'image'), true);
|
|
27
|
+
});
|
|
28
|
+
});
|
|
@@ -1 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a given string into camelCase format.
|
|
3
|
+
*
|
|
4
|
+
* This function normalizes the input by:
|
|
5
|
+
* - Converting it to lowercase
|
|
6
|
+
* - Removing special characters (except alphanumeric and underscores)
|
|
7
|
+
* - Replacing underscores and multiple spaces with single spaces
|
|
8
|
+
* - Capitalizing each word except the first
|
|
9
|
+
* - Removing all spaces to form a camelCased result
|
|
10
|
+
*
|
|
11
|
+
* If the input is `null` or `undefined`, an empty string is returned.
|
|
12
|
+
*
|
|
13
|
+
* @param {string} text - The input string to convert.
|
|
14
|
+
* @returns {string} The camelCased version of the input string.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* camelCase("Hello world"); // "helloWorld"
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* camelCase(" convert_to-camel case!! "); // "convertToCamelCase"
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* camelCase(""); // ""
|
|
24
|
+
*/
|
|
1
25
|
export declare function camelCase(text: string): string;
|
|
@@ -1,6 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.camelCase = camelCase;
|
|
4
|
+
/**
|
|
5
|
+
* Converts a given string into camelCase format.
|
|
6
|
+
*
|
|
7
|
+
* This function normalizes the input by:
|
|
8
|
+
* - Converting it to lowercase
|
|
9
|
+
* - Removing special characters (except alphanumeric and underscores)
|
|
10
|
+
* - Replacing underscores and multiple spaces with single spaces
|
|
11
|
+
* - Capitalizing each word except the first
|
|
12
|
+
* - Removing all spaces to form a camelCased result
|
|
13
|
+
*
|
|
14
|
+
* If the input is `null` or `undefined`, an empty string is returned.
|
|
15
|
+
*
|
|
16
|
+
* @param {string} text - The input string to convert.
|
|
17
|
+
* @returns {string} The camelCased version of the input string.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* camelCase("Hello world"); // "helloWorld"
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* camelCase(" convert_to-camel case!! "); // "convertToCamelCase"
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* camelCase(""); // ""
|
|
27
|
+
*/
|
|
4
28
|
function camelCase(text) {
|
|
5
29
|
if (text == null)
|
|
6
30
|
return '';
|
|
@@ -1 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Capitalizes the first letter of every word in a given string.
|
|
3
|
+
*
|
|
4
|
+
* A word is identified by word boundaries (`\b`), and only the first character
|
|
5
|
+
* of each word is converted to uppercase. The rest of the characters remain unchanged.
|
|
6
|
+
*
|
|
7
|
+
* Throws an error if the input is not a string.
|
|
8
|
+
*
|
|
9
|
+
* @param {string} text - The input string whose words will be capitalized.
|
|
10
|
+
* @returns {string} A new string with each word's first character in uppercase.
|
|
11
|
+
* @throws {Error} If the input is not a string.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* capitalizeWords("hello world"); // "Hello World"
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* capitalizeWords("javaScript is fun!"); // "JavaScript Is Fun!"
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* capitalizeWords(""); // ""
|
|
21
|
+
*/
|
|
1
22
|
export declare function capitalizeWords(text: string): string;
|
|
@@ -1,9 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.capitalizeWords = capitalizeWords;
|
|
4
|
+
/**
|
|
5
|
+
* Capitalizes the first letter of every word in a given string.
|
|
6
|
+
*
|
|
7
|
+
* A word is identified by word boundaries (`\b`), and only the first character
|
|
8
|
+
* of each word is converted to uppercase. The rest of the characters remain unchanged.
|
|
9
|
+
*
|
|
10
|
+
* Throws an error if the input is not a string.
|
|
11
|
+
*
|
|
12
|
+
* @param {string} text - The input string whose words will be capitalized.
|
|
13
|
+
* @returns {string} A new string with each word's first character in uppercase.
|
|
14
|
+
* @throws {Error} If the input is not a string.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* capitalizeWords("hello world"); // "Hello World"
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* capitalizeWords("javaScript is fun!"); // "JavaScript Is Fun!"
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* capitalizeWords(""); // ""
|
|
24
|
+
*/
|
|
4
25
|
function capitalizeWords(text) {
|
|
5
|
-
if (typeof text !==
|
|
6
|
-
throw new Error(
|
|
26
|
+
if (typeof text !== 'string') {
|
|
27
|
+
throw new Error('Invalid argument. Expected a string.');
|
|
7
28
|
}
|
|
8
29
|
return text.replace(/\b\w/g, (char) => char.toUpperCase());
|
|
9
30
|
}
|