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.
Files changed (111) hide show
  1. package/.prettierignore +4 -0
  2. package/.prettierrc +7 -0
  3. package/CONTRIBUTING.md +41 -29
  4. package/README.md +397 -160
  5. package/dist/analyzing/characterCount.d.ts +19 -0
  6. package/dist/analyzing/characterCount.js +21 -2
  7. package/dist/analyzing/characterFrequency.d.ts +19 -0
  8. package/dist/analyzing/characterFrequency.js +22 -3
  9. package/dist/analyzing/complexity.d.ts +33 -0
  10. package/dist/analyzing/complexity.js +35 -2
  11. package/dist/analyzing/index.d.ts +18 -12
  12. package/dist/analyzing/index.js +10 -2
  13. package/dist/analyzing/patternCount.d.ts +10 -0
  14. package/dist/analyzing/patternCount.js +52 -0
  15. package/dist/analyzing/stringSimilarity.js +1 -1
  16. package/dist/analyzing/vowelConsonantCount.d.ts +22 -0
  17. package/dist/analyzing/vowelConsonantCount.js +38 -0
  18. package/dist/analyzing/wordCount.d.ts +22 -0
  19. package/dist/analyzing/wordCount.js +24 -2
  20. package/dist/formatting/capitalize.d.ts +21 -0
  21. package/dist/formatting/capitalize.js +22 -1
  22. package/dist/formatting/index.d.ts +6 -6
  23. package/dist/formatting/number.d.ts +23 -0
  24. package/dist/formatting/number.js +24 -1
  25. package/dist/formatting/phone.d.ts +23 -0
  26. package/dist/formatting/phone.js +23 -0
  27. package/dist/index.d.ts +9 -4
  28. package/dist/tests/analyzing/patternCount.test.d.ts +1 -0
  29. package/dist/tests/analyzing/patternCount.test.js +34 -0
  30. package/dist/tests/analyzing/readingDuration.test.js +12 -12
  31. package/dist/tests/analyzing/vowelConsonantCount.test.d.ts +1 -0
  32. package/dist/tests/analyzing/vowelConsonantCount.test.js +25 -0
  33. package/dist/tests/transformations/numberToText.test.d.ts +1 -0
  34. package/dist/tests/transformations/numberToText.test.js +60 -0
  35. package/dist/tests/transformations/splitChunks.test.d.ts +1 -0
  36. package/dist/tests/transformations/splitChunks.test.js +31 -0
  37. package/dist/tests/validations/isCoordinates.test.d.ts +1 -0
  38. package/dist/tests/validations/isCoordinates.test.js +18 -0
  39. package/dist/tests/validations/isEmail.smtpUTF8.test.d.ts +1 -0
  40. package/dist/tests/validations/isEmail.smtpUTF8.test.js +16 -0
  41. package/dist/tests/validations/isEmail.test.js +56 -6
  42. package/dist/tests/validations/isHexColor.test.js +21 -21
  43. package/dist/tests/validations/isPalindrome.test.d.ts +1 -0
  44. package/dist/tests/validations/isPalindrome.test.js +39 -0
  45. package/dist/tests/validations/isTypeOf.test.d.ts +1 -0
  46. package/dist/tests/validations/isTypeOf.test.js +28 -0
  47. package/dist/transformations/camelCase.d.ts +24 -0
  48. package/dist/transformations/camelCase.js +24 -0
  49. package/dist/transformations/capitalizeWords.d.ts +21 -0
  50. package/dist/transformations/capitalizeWords.js +23 -2
  51. package/dist/transformations/constantCase.d.ts +26 -0
  52. package/dist/transformations/constantCase.js +26 -0
  53. package/dist/transformations/escapeHTML.d.ts +23 -0
  54. package/dist/transformations/escapeHTML.js +24 -2
  55. package/dist/transformations/index.d.ts +3 -0
  56. package/dist/transformations/index.js +6 -2
  57. package/dist/transformations/initials.d.ts +27 -0
  58. package/dist/transformations/initials.js +38 -8
  59. package/dist/transformations/kebabCase.d.ts +26 -0
  60. package/dist/transformations/kebabCase.js +26 -0
  61. package/dist/transformations/maskSegment.js +4 -6
  62. package/dist/transformations/numberToText/helpers.d.ts +10 -0
  63. package/dist/transformations/numberToText/helpers.js +31 -0
  64. package/dist/transformations/numberToText/implementation_EN.d.ts +10 -0
  65. package/dist/transformations/numberToText/implementation_EN.js +45 -0
  66. package/dist/transformations/numberToText/implementation_PL.d.ts +10 -0
  67. package/dist/transformations/numberToText/implementation_PL.js +79 -0
  68. package/dist/transformations/numberToText/main.d.ts +19 -0
  69. package/dist/transformations/numberToText/main.js +67 -0
  70. package/dist/transformations/numberToText/types.d.ts +3 -0
  71. package/dist/transformations/numberToText/types.js +82 -0
  72. package/dist/transformations/pascalCase.d.ts +25 -0
  73. package/dist/transformations/pascalCase.js +25 -0
  74. package/dist/transformations/removeDuplicates.d.ts +21 -0
  75. package/dist/transformations/removeDuplicates.js +25 -4
  76. package/dist/transformations/removeSpecialChars.d.ts +22 -0
  77. package/dist/transformations/removeSpecialChars.js +26 -4
  78. package/dist/transformations/removeWords.d.ts +27 -0
  79. package/dist/transformations/removeWords.js +31 -4
  80. package/dist/transformations/snakeCase.d.ts +26 -0
  81. package/dist/transformations/snakeCase.js +26 -0
  82. package/dist/transformations/splitChunks.d.ts +8 -0
  83. package/dist/transformations/splitChunks.js +24 -0
  84. package/dist/transformations/titleCase.d.ts +25 -0
  85. package/dist/transformations/titleCase.js +25 -0
  86. package/dist/transformations/toSlug.d.ts +24 -0
  87. package/dist/transformations/toSlug.js +28 -4
  88. package/dist/transformations/truncateText.d.ts +25 -0
  89. package/dist/transformations/truncateText.js +28 -3
  90. package/dist/validations/index.d.ts +6 -0
  91. package/dist/validations/index.js +10 -2
  92. package/dist/validations/isCoordinates.d.ts +8 -0
  93. package/dist/validations/isCoordinates.js +19 -0
  94. package/dist/validations/isDate.d.ts +1 -1
  95. package/dist/validations/isDate.js +6 -8
  96. package/dist/validations/isEmail.d.ts +13 -1
  97. package/dist/validations/isEmail.js +176 -3
  98. package/dist/validations/isEmpty.d.ts +9 -0
  99. package/dist/validations/isEmpty.js +9 -0
  100. package/dist/validations/isHexColor.js +1 -1
  101. package/dist/validations/isIPv4.d.ts +21 -0
  102. package/dist/validations/isIPv4.js +22 -2
  103. package/dist/validations/isPalindrome.d.ts +10 -0
  104. package/dist/validations/isPalindrome.js +21 -0
  105. package/dist/validations/isSlug.d.ts +27 -0
  106. package/dist/validations/isSlug.js +27 -0
  107. package/dist/validations/isTypeOf.d.ts +9 -0
  108. package/dist/validations/isTypeOf.js +30 -0
  109. package/dist/validations/isURL.d.ts +21 -0
  110. package/dist/validations/isURL.js +21 -0
  111. package/package.json +5 -3
@@ -1 +1,20 @@
1
+ /**
2
+ * Returns the number of characters in a given string.
3
+ *
4
+ * This function counts all characters in the string, including whitespace,
5
+ * punctuation, and special characters. It throws a `TypeError` if the input is not a string.
6
+ *
7
+ * @param {string} str - The string whose characters will be counted.
8
+ * @returns {number} The number of characters in the input string.
9
+ * @throws {TypeError} If the input is not of type string.
10
+ *
11
+ * @example
12
+ * characterCount("Hello, world!"); // 13
13
+ *
14
+ * @example
15
+ * characterCount(" "); // 2
16
+ *
17
+ * @example
18
+ * characterCount(""); // 0
19
+ */
1
20
  export declare function characterCount(str: string): number;
@@ -1,9 +1,28 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.characterCount = characterCount;
4
+ /**
5
+ * Returns the number of characters in a given string.
6
+ *
7
+ * This function counts all characters in the string, including whitespace,
8
+ * punctuation, and special characters. It throws a `TypeError` if the input is not a string.
9
+ *
10
+ * @param {string} str - The string whose characters will be counted.
11
+ * @returns {number} The number of characters in the input string.
12
+ * @throws {TypeError} If the input is not of type string.
13
+ *
14
+ * @example
15
+ * characterCount("Hello, world!"); // 13
16
+ *
17
+ * @example
18
+ * characterCount(" "); // 2
19
+ *
20
+ * @example
21
+ * characterCount(""); // 0
22
+ */
4
23
  function characterCount(str) {
5
- if (typeof str !== "string") {
6
- throw new TypeError("Input must be a string");
24
+ if (typeof str !== 'string') {
25
+ throw new TypeError('Input must be a string');
7
26
  }
8
27
  return str.length;
9
28
  }
@@ -1 +1,20 @@
1
+ /**
2
+ * Calculates the frequency of each non-space character in a string.
3
+ *
4
+ * This function returns an object mapping each lowercase character (excluding spaces)
5
+ * to the number of times it appears in the input string. The input is case-insensitive,
6
+ * meaning 'A' and 'a' are treated the same. It throws a `TypeError` if the input is not a string.
7
+ *
8
+ * @param {string} str - The string to analyze.
9
+ * @returns {Record<string, number>} An object where keys are characters and values are their counts.
10
+ * @throws {TypeError} If the input is not a string.
11
+ *
12
+ * @example
13
+ * characterFrequency("Hello World");
14
+ * // Returns: { h: 1, e: 1, l: 3, o: 2, w: 1, r: 1, d: 1 }
15
+ *
16
+ * @example
17
+ * characterFrequency("AaBb");
18
+ * // Returns: { a: 2, b: 2 }
19
+ */
1
20
  export declare function characterFrequency(str: string): Record<string, number>;
@@ -1,13 +1,32 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.characterFrequency = characterFrequency;
4
+ /**
5
+ * Calculates the frequency of each non-space character in a string.
6
+ *
7
+ * This function returns an object mapping each lowercase character (excluding spaces)
8
+ * to the number of times it appears in the input string. The input is case-insensitive,
9
+ * meaning 'A' and 'a' are treated the same. It throws a `TypeError` if the input is not a string.
10
+ *
11
+ * @param {string} str - The string to analyze.
12
+ * @returns {Record<string, number>} An object where keys are characters and values are their counts.
13
+ * @throws {TypeError} If the input is not a string.
14
+ *
15
+ * @example
16
+ * characterFrequency("Hello World");
17
+ * // Returns: { h: 1, e: 1, l: 3, o: 2, w: 1, r: 1, d: 1 }
18
+ *
19
+ * @example
20
+ * characterFrequency("AaBb");
21
+ * // Returns: { a: 2, b: 2 }
22
+ */
4
23
  function characterFrequency(str) {
5
- if (typeof str !== "string") {
6
- throw new TypeError("Input must be a string");
24
+ if (typeof str !== 'string') {
25
+ throw new TypeError('Input must be a string');
7
26
  }
8
27
  const frequency = {};
9
28
  for (const char of str.toLowerCase()) {
10
- if (char !== " ") {
29
+ if (char !== ' ') {
11
30
  // Exclude spaces for cleaner analysis
12
31
  frequency[char] = (frequency[char] || 0) + 1;
13
32
  }
@@ -3,4 +3,37 @@ export type ComplexityResult = {
3
3
  uniqueness: number;
4
4
  length: number;
5
5
  };
6
+ /**
7
+ * Evaluates the complexity of a given string based on length, character uniqueness,
8
+ * and character type diversity (lowercase, uppercase, numbers, symbols).
9
+ *
10
+ * The returned score ranges from 0 to 1, where a higher score indicates greater complexity.
11
+ * It also returns the raw length of the string and its uniqueness ratio (unique chars / total length).
12
+ *
13
+ * - `uniqueness`: Measures how varied the characters are.
14
+ * - `score`: Combines uniqueness, type diversity, and length into a weighted value.
15
+ * - `length`: The total number of characters in the input.
16
+ *
17
+ * Throws a `TypeError` if the input is not a string.
18
+ *
19
+ * @param {string} str - The input string to evaluate.
20
+ * @returns {ComplexityResult} An object containing `score`, `uniqueness`, and `length`.
21
+ * @throws {TypeError} If the input is not a string.
22
+ *
23
+ * @example
24
+ * complexity("abcABC123!");
25
+ * // {
26
+ * // score: 0.93,
27
+ * // uniqueness: 1.00,
28
+ * // length: 10
29
+ * // }
30
+ *
31
+ * @example
32
+ * complexity("aaaa");
33
+ * // {
34
+ * // score: 0.25,
35
+ * // uniqueness: 0.25,
36
+ * // length: 4
37
+ * // }
38
+ */
6
39
  export declare function complexity(str: string): ComplexityResult;
@@ -1,11 +1,44 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.complexity = complexity;
4
+ /**
5
+ * Evaluates the complexity of a given string based on length, character uniqueness,
6
+ * and character type diversity (lowercase, uppercase, numbers, symbols).
7
+ *
8
+ * The returned score ranges from 0 to 1, where a higher score indicates greater complexity.
9
+ * It also returns the raw length of the string and its uniqueness ratio (unique chars / total length).
10
+ *
11
+ * - `uniqueness`: Measures how varied the characters are.
12
+ * - `score`: Combines uniqueness, type diversity, and length into a weighted value.
13
+ * - `length`: The total number of characters in the input.
14
+ *
15
+ * Throws a `TypeError` if the input is not a string.
16
+ *
17
+ * @param {string} str - The input string to evaluate.
18
+ * @returns {ComplexityResult} An object containing `score`, `uniqueness`, and `length`.
19
+ * @throws {TypeError} If the input is not a string.
20
+ *
21
+ * @example
22
+ * complexity("abcABC123!");
23
+ * // {
24
+ * // score: 0.93,
25
+ * // uniqueness: 1.00,
26
+ * // length: 10
27
+ * // }
28
+ *
29
+ * @example
30
+ * complexity("aaaa");
31
+ * // {
32
+ * // score: 0.25,
33
+ * // uniqueness: 0.25,
34
+ * // length: 4
35
+ * // }
36
+ */
4
37
  function complexity(str) {
5
38
  if (!str)
6
39
  return { score: 0, uniqueness: 0, length: 0 };
7
- if (typeof str !== "string") {
8
- throw new TypeError("Input must be a string");
40
+ if (typeof str !== 'string') {
41
+ throw new TypeError('Input must be a string');
9
42
  }
10
43
  const length = str.length;
11
44
  const unique = new Set(str).size;
@@ -1,15 +1,19 @@
1
- export { characterCount } from "./characterCount";
2
- export { characterFrequency } from "./characterFrequency";
3
- export { complexity } from "./complexity";
4
- export { readingDuration } from "./readingDuration";
5
- export { wordCount } from "./wordCount";
6
- export { stringSimilarity } from "./stringSimilarity";
7
- import { characterCount } from "./characterCount";
8
- import { characterFrequency } from "./characterFrequency";
9
- import { complexity } from "./complexity";
10
- import { readingDuration } from "./readingDuration";
11
- import { wordCount } from "./wordCount";
12
- import { stringSimilarity } from "./stringSimilarity";
1
+ export { characterCount } from './characterCount';
2
+ export { characterFrequency } from './characterFrequency';
3
+ export { complexity } from './complexity';
4
+ export { readingDuration } from './readingDuration';
5
+ export { wordCount } from './wordCount';
6
+ export { stringSimilarity } from './stringSimilarity';
7
+ export { patternCount } from './patternCount';
8
+ export { vowelConsonantCount } from './vowelConsonantCount';
9
+ import { characterCount } from './characterCount';
10
+ import { characterFrequency } from './characterFrequency';
11
+ import { complexity } from './complexity';
12
+ import { readingDuration } from './readingDuration';
13
+ import { wordCount } from './wordCount';
14
+ import { stringSimilarity } from './stringSimilarity';
15
+ import { patternCount } from './patternCount';
16
+ import { vowelConsonantCount } from './vowelConsonantCount';
13
17
  export declare const analyzing: {
14
18
  characterCount: typeof characterCount;
15
19
  characterFrequency: typeof characterFrequency;
@@ -17,4 +21,6 @@ export declare const analyzing: {
17
21
  readingDuration: typeof readingDuration;
18
22
  wordCount: typeof wordCount;
19
23
  stringSimilarity: typeof stringSimilarity;
24
+ patternCount: typeof patternCount;
25
+ vowelConsonantCount: typeof vowelConsonantCount;
20
26
  };
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.analyzing = exports.stringSimilarity = exports.wordCount = exports.readingDuration = exports.complexity = exports.characterFrequency = exports.characterCount = void 0;
3
+ exports.analyzing = exports.vowelConsonantCount = exports.patternCount = exports.stringSimilarity = exports.wordCount = exports.readingDuration = exports.complexity = exports.characterFrequency = exports.characterCount = void 0;
4
4
  var characterCount_1 = require("./characterCount");
5
5
  Object.defineProperty(exports, "characterCount", { enumerable: true, get: function () { return characterCount_1.characterCount; } });
6
6
  var characterFrequency_1 = require("./characterFrequency");
@@ -13,17 +13,25 @@ var wordCount_1 = require("./wordCount");
13
13
  Object.defineProperty(exports, "wordCount", { enumerable: true, get: function () { return wordCount_1.wordCount; } });
14
14
  var stringSimilarity_1 = require("./stringSimilarity");
15
15
  Object.defineProperty(exports, "stringSimilarity", { enumerable: true, get: function () { return stringSimilarity_1.stringSimilarity; } });
16
+ var patternCount_1 = require("./patternCount");
17
+ Object.defineProperty(exports, "patternCount", { enumerable: true, get: function () { return patternCount_1.patternCount; } });
18
+ var vowelConsonantCount_1 = require("./vowelConsonantCount");
19
+ Object.defineProperty(exports, "vowelConsonantCount", { enumerable: true, get: function () { return vowelConsonantCount_1.vowelConsonantCount; } });
16
20
  const characterCount_2 = require("./characterCount");
17
21
  const characterFrequency_2 = require("./characterFrequency");
18
22
  const complexity_2 = require("./complexity");
19
23
  const readingDuration_2 = require("./readingDuration");
20
24
  const wordCount_2 = require("./wordCount");
21
25
  const stringSimilarity_2 = require("./stringSimilarity");
26
+ const patternCount_2 = require("./patternCount");
27
+ const vowelConsonantCount_2 = require("./vowelConsonantCount");
22
28
  exports.analyzing = {
23
29
  characterCount: characterCount_2.characterCount,
24
30
  characterFrequency: characterFrequency_2.characterFrequency,
25
31
  complexity: complexity_2.complexity,
26
32
  readingDuration: readingDuration_2.readingDuration,
27
33
  wordCount: wordCount_2.wordCount,
28
- stringSimilarity: stringSimilarity_2.stringSimilarity
34
+ stringSimilarity: stringSimilarity_2.stringSimilarity,
35
+ patternCount: patternCount_2.patternCount,
36
+ vowelConsonantCount: vowelConsonantCount_2.vowelConsonantCount
29
37
  };
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Calculates the number of times a specific pattern occurs in a given text, including overlapping occurrences
3
+ *
4
+ * The algorithm used here is based on the Knuth-Morris-Pratt (KMP) pattern matching algorithm for better performance
5
+ *
6
+ * @param {string} text - The text for which we want to count the occurrences of a specific pattern.
7
+ * @param {string} pattern - The pattern to search for within the text.
8
+ * @returns {number} - The number of times the pattern occurs in the text (overlapping).
9
+ */
10
+ export declare function patternCount(text: string, pattern: string): number;
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.patternCount = patternCount;
4
+ /**
5
+ * Calculates the number of times a specific pattern occurs in a given text, including overlapping occurrences
6
+ *
7
+ * The algorithm used here is based on the Knuth-Morris-Pratt (KMP) pattern matching algorithm for better performance
8
+ *
9
+ * @param {string} text - The text for which we want to count the occurrences of a specific pattern.
10
+ * @param {string} pattern - The pattern to search for within the text.
11
+ * @returns {number} - The number of times the pattern occurs in the text (overlapping).
12
+ */
13
+ function patternCount(text, pattern) {
14
+ if (pattern.length === 0) {
15
+ return 0; // No pattern to search for
16
+ }
17
+ const prefixFunction = computePrefixFunction(pattern);
18
+ let count = 0;
19
+ let j = 0; // Index for pattern
20
+ for (let i = 0; i < text.length; i++) {
21
+ while (j > 0 && text[i] !== pattern[j]) {
22
+ j = prefixFunction[j - 1];
23
+ }
24
+ if (text[i] === pattern[j]) {
25
+ j++;
26
+ }
27
+ if (j === pattern.length) {
28
+ count++;
29
+ j = prefixFunction[j - 1]; // Allow for overlapping matches
30
+ }
31
+ }
32
+ return count;
33
+ }
34
+ /**
35
+ * Computes the prefix function (partial match table) for KMP algorithm.
36
+ * @param {string} pattern - The pattern string.
37
+ * @returns {number[]} - The prefix function array.
38
+ */
39
+ function computePrefixFunction(pattern) {
40
+ const prefixFunction = new Array(pattern.length).fill(0);
41
+ let j = 0;
42
+ for (let i = 1; i < pattern.length; i++) {
43
+ while (j > 0 && pattern[i] !== pattern[j]) {
44
+ j = prefixFunction[j - 1];
45
+ }
46
+ if (pattern[i] === pattern[j]) {
47
+ j++;
48
+ }
49
+ prefixFunction[i] = j;
50
+ }
51
+ return prefixFunction;
52
+ }
@@ -33,7 +33,7 @@ function stringSimilarity(textA, textB, algorithm = 'Levenshtein') {
33
33
  * @returns Similarity percentage (0-100).
34
34
  */
35
35
  function calculateSimilarityScore(distance, textA, textB) {
36
- const similarityScore = 1 - (distance / Math.max(textA.length, textB.length));
36
+ const similarityScore = 1 - distance / Math.max(textA.length, textB.length);
37
37
  return parseFloat((similarityScore * 100).toFixed(2));
38
38
  }
39
39
  /**
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Returns the number of vowels and consonants in a given string.
3
+ *
4
+ * This function counts the number of vowels and consonants in the string, ignoring whitespace,
5
+ * punctuation, and special characters. It throws a `TypeError` if the input is not a string.
6
+ *
7
+ * @param {string} str - The string whose vowels and consonants will be counted.
8
+ * @returns {{ vowels: number, consonants: number }} An object containing the counts of vowels and consonants.
9
+ * @throws {TypeError} If the input is not of type string
10
+ *
11
+ * @example
12
+ * vowelConsonantCount("hello");
13
+ * // { vowels: 2, consonants: 3 }
14
+ *
15
+ * @example
16
+ * vowelConsonantCount("stringzy");
17
+ * // { vowels: 1, consonants: 7 }
18
+ */
19
+ export declare function vowelConsonantCount(str: string): {
20
+ vowels: number;
21
+ consonants: number;
22
+ };
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.vowelConsonantCount = vowelConsonantCount;
4
+ /**
5
+ * Returns the number of vowels and consonants in a given string.
6
+ *
7
+ * This function counts the number of vowels and consonants in the string, ignoring whitespace,
8
+ * punctuation, and special characters. It throws a `TypeError` if the input is not a string.
9
+ *
10
+ * @param {string} str - The string whose vowels and consonants will be counted.
11
+ * @returns {{ vowels: number, consonants: number }} An object containing the counts of vowels and consonants.
12
+ * @throws {TypeError} If the input is not of type string
13
+ *
14
+ * @example
15
+ * vowelConsonantCount("hello");
16
+ * // { vowels: 2, consonants: 3 }
17
+ *
18
+ * @example
19
+ * vowelConsonantCount("stringzy");
20
+ * // { vowels: 1, consonants: 7 }
21
+ */
22
+ function vowelConsonantCount(str) {
23
+ if (typeof str !== 'string') {
24
+ throw new TypeError('Input must be a string');
25
+ }
26
+ const vowels = 'aeiouAEIOU';
27
+ let vowelCount = 0;
28
+ let consonantCount = 0;
29
+ for (const char of str) {
30
+ if (vowels.includes(char)) {
31
+ vowelCount++;
32
+ }
33
+ else if (char.toLowerCase() >= 'a' && char.toLowerCase() <= 'z') {
34
+ consonantCount++;
35
+ }
36
+ }
37
+ return { vowels: vowelCount, consonants: consonantCount };
38
+ }
@@ -1 +1,23 @@
1
+ /**
2
+ * Counts the number of words in a given string.
3
+ *
4
+ * Words are defined as sequences of non-whitespace characters separated by one or more
5
+ * whitespace characters (spaces, tabs, newlines, etc.). Leading and trailing whitespace
6
+ * is trimmed before counting.
7
+ *
8
+ * Throws a `TypeError` if the input is not a string.
9
+ *
10
+ * @param {string} str - The string to analyze.
11
+ * @returns {number} The number of words in the input string.
12
+ * @throws {TypeError} If the input is not a string.
13
+ *
14
+ * @example
15
+ * wordCount("Hello world"); // 2
16
+ *
17
+ * @example
18
+ * wordCount(" This is a test\nwith multiple lines "); // 7
19
+ *
20
+ * @example
21
+ * wordCount(" "); // 0
22
+ */
1
23
  export declare function wordCount(str: string): number;
@@ -1,9 +1,31 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.wordCount = wordCount;
4
+ /**
5
+ * Counts the number of words in a given string.
6
+ *
7
+ * Words are defined as sequences of non-whitespace characters separated by one or more
8
+ * whitespace characters (spaces, tabs, newlines, etc.). Leading and trailing whitespace
9
+ * is trimmed before counting.
10
+ *
11
+ * Throws a `TypeError` if the input is not a string.
12
+ *
13
+ * @param {string} str - The string to analyze.
14
+ * @returns {number} The number of words in the input string.
15
+ * @throws {TypeError} If the input is not a string.
16
+ *
17
+ * @example
18
+ * wordCount("Hello world"); // 2
19
+ *
20
+ * @example
21
+ * wordCount(" This is a test\nwith multiple lines "); // 7
22
+ *
23
+ * @example
24
+ * wordCount(" "); // 0
25
+ */
4
26
  function wordCount(str) {
5
- if (typeof str !== "string") {
6
- throw new TypeError("Input must be a string");
27
+ if (typeof str !== 'string') {
28
+ throw new TypeError('Input must be a string');
7
29
  }
8
30
  if (!str.trim())
9
31
  return 0;
@@ -1 +1,22 @@
1
+ /**
2
+ * Capitalizes the first letter of each word in a string.
3
+ *
4
+ * Converts the first character of each word to uppercase and the remaining characters to lowercase.
5
+ * Words are assumed to be separated by spaces. Handles multiple words and mixed casing.
6
+ *
7
+ * Throws a `TypeError` if the input is not a string.
8
+ *
9
+ * @param {string} str - The input string to capitalize.
10
+ * @returns {string} A new string with each word capitalized.
11
+ * @throws {TypeError} If the input is not a string.
12
+ *
13
+ * @example
14
+ * capitalize("hello world"); // "Hello World"
15
+ *
16
+ * @example
17
+ * capitalize("mIxEd CaSe tExT"); // "Mixed Case Text"
18
+ *
19
+ * @example
20
+ * capitalize(" multiple spaces "); // "Multiple Spaces"
21
+ */
1
22
  export declare function capitalize(str: string): string;
@@ -1,12 +1,33 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.capitalize = capitalize;
4
+ /**
5
+ * Capitalizes the first letter of each word in a string.
6
+ *
7
+ * Converts the first character of each word to uppercase and the remaining characters to lowercase.
8
+ * Words are assumed to be separated by spaces. Handles multiple words and mixed casing.
9
+ *
10
+ * Throws a `TypeError` if the input is not a string.
11
+ *
12
+ * @param {string} str - The input string to capitalize.
13
+ * @returns {string} A new string with each word capitalized.
14
+ * @throws {TypeError} If the input is not a string.
15
+ *
16
+ * @example
17
+ * capitalize("hello world"); // "Hello World"
18
+ *
19
+ * @example
20
+ * capitalize("mIxEd CaSe tExT"); // "Mixed Case Text"
21
+ *
22
+ * @example
23
+ * capitalize(" multiple spaces "); // "Multiple Spaces"
24
+ */
4
25
  function capitalize(str) {
5
26
  if (typeof str !== 'string') {
6
27
  throw new TypeError('Input must be a string');
7
28
  }
8
29
  return str
9
30
  .split(' ')
10
- .map(word => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())
31
+ .map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())
11
32
  .join(' ');
12
33
  }
@@ -1,9 +1,9 @@
1
- export { capitalize } from "./capitalize";
2
- export { formatNumber } from "./number";
3
- export { formatPhone } from "./phone";
4
- import { capitalize } from "./capitalize";
5
- import { formatNumber } from "./number";
6
- import { formatPhone } from "./phone";
1
+ export { capitalize } from './capitalize';
2
+ export { formatNumber } from './number';
3
+ export { formatPhone } from './phone';
4
+ import { capitalize } from './capitalize';
5
+ import { formatNumber } from './number';
6
+ import { formatPhone } from './phone';
7
7
  export declare const formatting: {
8
8
  capitalize: typeof capitalize;
9
9
  formatNumber: typeof formatNumber;
@@ -1 +1,24 @@
1
+ /**
2
+ * Formats a number with a thousands separator.
3
+ *
4
+ * Converts a number or numeric string into a more readable format by inserting the specified
5
+ * thousands separator (either `','` or `'.'`). This function does not round or localize
6
+ * decimals — it only adds the separator between every three digits from the right.
7
+ *
8
+ * The input is first converted to a string before formatting. If the input is not a valid
9
+ * number or numeric string, the output may be incorrect.
10
+ *
11
+ * @param {string | number} num - The number or numeric string to format.
12
+ * @param {'.' | ','} [thousendsSeperator=','] - The character to use as the thousands separator.
13
+ * @returns {string} The formatted string with the separator added.
14
+ *
15
+ * @example
16
+ * formatNumber(1234567); // "1,234,567"
17
+ *
18
+ * @example
19
+ * formatNumber("987654321", '.'); // "987.654.321"
20
+ *
21
+ * @example
22
+ * formatNumber(12345.67); // "12,345.67" (decimals preserved as-is)
23
+ */
1
24
  export declare function formatNumber(num: string | number, thousendsSeperator?: '.' | ','): string;
@@ -1,7 +1,30 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.formatNumber = formatNumber;
4
- function formatNumber(num, thousendsSeperator = ",") {
4
+ /**
5
+ * Formats a number with a thousands separator.
6
+ *
7
+ * Converts a number or numeric string into a more readable format by inserting the specified
8
+ * thousands separator (either `','` or `'.'`). This function does not round or localize
9
+ * decimals — it only adds the separator between every three digits from the right.
10
+ *
11
+ * The input is first converted to a string before formatting. If the input is not a valid
12
+ * number or numeric string, the output may be incorrect.
13
+ *
14
+ * @param {string | number} num - The number or numeric string to format.
15
+ * @param {'.' | ','} [thousendsSeperator=','] - The character to use as the thousands separator.
16
+ * @returns {string} The formatted string with the separator added.
17
+ *
18
+ * @example
19
+ * formatNumber(1234567); // "1,234,567"
20
+ *
21
+ * @example
22
+ * formatNumber("987654321", '.'); // "987.654.321"
23
+ *
24
+ * @example
25
+ * formatNumber(12345.67); // "12,345.67" (decimals preserved as-is)
26
+ */
27
+ function formatNumber(num, thousendsSeperator = ',') {
5
28
  const numStr = num.toString();
6
29
  return numStr.replace(/\B(?=(\d{3})+(?!\d))/g, thousendsSeperator);
7
30
  }
@@ -1,2 +1,25 @@
1
1
  export type PhoneFormat = 'us' | 'in' | 'international';
2
+ /**
3
+ * Formats a phone number string into a readable format based on the given region.
4
+ *
5
+ * Strips all non-digit characters before formatting. Supports formatting for:
6
+ * - `'us'`: U.S. numbers with 10 digits → `(123) 456-7890`
7
+ * - `'in'`: Indian numbers with 10 digits or 12 digits starting with '91' → `+91-12345-67890`
8
+ * - `'international'`: Generic international format assuming last 10 digits are the local number.
9
+ *
10
+ * If the number does not match expected formats, it returns the original input.
11
+ *
12
+ * @param {string} phone - The phone number string to format.
13
+ * @param {PhoneFormat} [format='us'] - The desired formatting style: `'us'`, `'in'`, or `'international'`.
14
+ * @returns {string} The formatted phone number, or the original input if formatting fails.
15
+ *
16
+ * @example
17
+ * formatPhone("1234567890"); // "(123) 456-7890"
18
+ *
19
+ * @example
20
+ * formatPhone("+91 9876543210", "in"); // "+91-98765-43210"
21
+ *
22
+ * @example
23
+ * formatPhone("009199876543210", "international"); // "+0091 (998) 765-43210"
24
+ */
2
25
  export declare function formatPhone(phone: string, format?: PhoneFormat): string;
@@ -1,6 +1,29 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.formatPhone = formatPhone;
4
+ /**
5
+ * Formats a phone number string into a readable format based on the given region.
6
+ *
7
+ * Strips all non-digit characters before formatting. Supports formatting for:
8
+ * - `'us'`: U.S. numbers with 10 digits → `(123) 456-7890`
9
+ * - `'in'`: Indian numbers with 10 digits or 12 digits starting with '91' → `+91-12345-67890`
10
+ * - `'international'`: Generic international format assuming last 10 digits are the local number.
11
+ *
12
+ * If the number does not match expected formats, it returns the original input.
13
+ *
14
+ * @param {string} phone - The phone number string to format.
15
+ * @param {PhoneFormat} [format='us'] - The desired formatting style: `'us'`, `'in'`, or `'international'`.
16
+ * @returns {string} The formatted phone number, or the original input if formatting fails.
17
+ *
18
+ * @example
19
+ * formatPhone("1234567890"); // "(123) 456-7890"
20
+ *
21
+ * @example
22
+ * formatPhone("+91 9876543210", "in"); // "+91-98765-43210"
23
+ *
24
+ * @example
25
+ * formatPhone("009199876543210", "international"); // "+0091 (998) 765-43210"
26
+ */
4
27
  function formatPhone(phone, format = 'us') {
5
28
  const digits = phone.replace(/\D/g, '');
6
29
  if (format === 'us' && digits.length === 10) {