stringzy 3.0.0 → 4.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (171) hide show
  1. package/.prettierignore +4 -0
  2. package/.prettierrc +7 -0
  3. package/CONTRIBUTING.md +41 -29
  4. package/README.md +811 -163
  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/checkMultiplePatterns.d.ts +14 -0
  10. package/dist/analyzing/checkMultiplePatterns.js +63 -0
  11. package/dist/analyzing/checkSubsequence.d.ts +14 -0
  12. package/dist/analyzing/checkSubsequence.js +33 -0
  13. package/dist/analyzing/complexity.d.ts +33 -0
  14. package/dist/analyzing/complexity.js +35 -2
  15. package/dist/analyzing/contentWordCount.d.ts +11 -0
  16. package/dist/analyzing/contentWordCount.js +23 -0
  17. package/dist/analyzing/functionWordCount.d.ts +11 -0
  18. package/dist/analyzing/functionWordCount.js +33 -0
  19. package/dist/analyzing/index.d.ts +29 -12
  20. package/dist/analyzing/index.js +26 -2
  21. package/dist/analyzing/patternCount.d.ts +11 -0
  22. package/dist/analyzing/patternCount.js +54 -0
  23. package/dist/analyzing/stringRotation.d.ts +29 -0
  24. package/dist/analyzing/stringRotation.js +44 -0
  25. package/dist/analyzing/stringSimilarity.js +1 -1
  26. package/dist/analyzing/vowelConsonantCount.d.ts +22 -0
  27. package/dist/analyzing/vowelConsonantCount.js +38 -0
  28. package/dist/analyzing/wordCount.d.ts +22 -0
  29. package/dist/analyzing/wordCount.js +24 -2
  30. package/dist/formatting/capitalize.d.ts +21 -0
  31. package/dist/formatting/capitalize.js +22 -1
  32. package/dist/formatting/index.d.ts +6 -6
  33. package/dist/formatting/number.d.ts +23 -0
  34. package/dist/formatting/number.js +24 -1
  35. package/dist/formatting/phone.d.ts +23 -0
  36. package/dist/formatting/phone.js +23 -0
  37. package/dist/index.d.ts +22 -4
  38. package/dist/tests/analyzing/checkMultiplePatterns.test.d.ts +1 -0
  39. package/dist/tests/analyzing/checkMultiplePatterns.test.js +81 -0
  40. package/dist/tests/analyzing/checkSubsequence.test.d.ts +1 -0
  41. package/dist/tests/analyzing/checkSubsequence.test.js +34 -0
  42. package/dist/tests/analyzing/contentWordCount.test.d.ts +1 -0
  43. package/dist/tests/analyzing/contentWordCount.test.js +20 -0
  44. package/dist/tests/analyzing/functionWordCount.test.d.ts +1 -0
  45. package/dist/tests/analyzing/functionWordCount.test.js +20 -0
  46. package/dist/tests/analyzing/patternCount.test.d.ts +1 -0
  47. package/dist/tests/analyzing/patternCount.test.js +34 -0
  48. package/dist/tests/analyzing/readingDuration.test.js +12 -12
  49. package/dist/tests/analyzing/stringRotation.test.d.ts +1 -0
  50. package/dist/tests/analyzing/stringRotation.test.js +42 -0
  51. package/dist/tests/analyzing/vowelConsonantCount.test.d.ts +1 -0
  52. package/dist/tests/analyzing/vowelConsonantCount.test.js +25 -0
  53. package/dist/tests/transformations/numberToText.test.d.ts +1 -0
  54. package/dist/tests/transformations/numberToText.test.js +60 -0
  55. package/dist/tests/transformations/reverseString.test.d.ts +1 -0
  56. package/dist/tests/transformations/reverseString.test.js +41 -0
  57. package/dist/tests/transformations/splitChunks.test.d.ts +1 -0
  58. package/dist/tests/transformations/splitChunks.test.js +31 -0
  59. package/dist/tests/transformations/stringCombinations.test.d.ts +1 -0
  60. package/dist/tests/transformations/stringCombinations.test.js +41 -0
  61. package/dist/tests/transformations/stringPermutations.test.d.ts +1 -0
  62. package/dist/tests/transformations/stringPermutations.test.js +40 -0
  63. package/dist/tests/validations/isAlphaNumeric.test.d.ts +1 -0
  64. package/dist/tests/validations/isAlphaNumeric.test.js +30 -0
  65. package/dist/tests/validations/isAlphabetic.test.d.ts +1 -0
  66. package/dist/tests/validations/isAlphabetic.test.js +32 -0
  67. package/dist/tests/validations/isAnagram.test.d.ts +1 -0
  68. package/dist/tests/validations/isAnagram.test.js +44 -0
  69. package/dist/tests/validations/isCoordinates.test.d.ts +1 -0
  70. package/dist/tests/validations/isCoordinates.test.js +18 -0
  71. package/dist/tests/validations/isEmail.smtpUTF8.test.d.ts +1 -0
  72. package/dist/tests/validations/isEmail.smtpUTF8.test.js +16 -0
  73. package/dist/tests/validations/isEmail.test.js +56 -6
  74. package/dist/tests/validations/isHexColor.test.js +21 -21
  75. package/dist/tests/validations/isLowerCase.test.d.ts +1 -0
  76. package/dist/tests/validations/isLowerCase.test.js +50 -0
  77. package/dist/tests/validations/isMacAddress.test.d.ts +1 -0
  78. package/dist/tests/validations/isMacAddress.test.js +72 -0
  79. package/dist/tests/validations/isPalindrome.test.d.ts +1 -0
  80. package/dist/tests/validations/isPalindrome.test.js +39 -0
  81. package/dist/tests/validations/isPanagram.test.d.ts +1 -0
  82. package/dist/tests/validations/isPanagram.test.js +39 -0
  83. package/dist/tests/validations/isTypeOf.test.d.ts +1 -0
  84. package/dist/tests/validations/isTypeOf.test.js +28 -0
  85. package/dist/tests/validations/isUpperCase.test.d.ts +1 -0
  86. package/dist/tests/validations/isUpperCase.test.js +50 -0
  87. package/dist/transformations/camelCase.d.ts +24 -0
  88. package/dist/transformations/camelCase.js +24 -0
  89. package/dist/transformations/capitalizeWords.d.ts +21 -0
  90. package/dist/transformations/capitalizeWords.js +23 -2
  91. package/dist/transformations/constantCase.d.ts +26 -0
  92. package/dist/transformations/constantCase.js +26 -0
  93. package/dist/transformations/escapeHTML.d.ts +23 -0
  94. package/dist/transformations/escapeHTML.js +24 -2
  95. package/dist/transformations/index.d.ts +12 -0
  96. package/dist/transformations/index.js +18 -2
  97. package/dist/transformations/initials.d.ts +27 -0
  98. package/dist/transformations/initials.js +38 -8
  99. package/dist/transformations/kebabCase.d.ts +26 -0
  100. package/dist/transformations/kebabCase.js +26 -0
  101. package/dist/transformations/maskSegment.js +4 -6
  102. package/dist/transformations/numberToText/helpers.d.ts +10 -0
  103. package/dist/transformations/numberToText/helpers.js +31 -0
  104. package/dist/transformations/numberToText/implementation_EN.d.ts +10 -0
  105. package/dist/transformations/numberToText/implementation_EN.js +45 -0
  106. package/dist/transformations/numberToText/implementation_PL.d.ts +10 -0
  107. package/dist/transformations/numberToText/implementation_PL.js +79 -0
  108. package/dist/transformations/numberToText/main.d.ts +19 -0
  109. package/dist/transformations/numberToText/main.js +67 -0
  110. package/dist/transformations/numberToText/types.d.ts +3 -0
  111. package/dist/transformations/numberToText/types.js +82 -0
  112. package/dist/transformations/pascalCase.d.ts +25 -0
  113. package/dist/transformations/pascalCase.js +25 -0
  114. package/dist/transformations/removeDuplicates.d.ts +21 -0
  115. package/dist/transformations/removeDuplicates.js +25 -4
  116. package/dist/transformations/removeSpecialChars.d.ts +22 -0
  117. package/dist/transformations/removeSpecialChars.js +26 -4
  118. package/dist/transformations/removeWords.d.ts +27 -0
  119. package/dist/transformations/removeWords.js +31 -4
  120. package/dist/transformations/reverseWordsInString .d.ts +9 -0
  121. package/dist/transformations/reverseWordsInString .js +49 -0
  122. package/dist/transformations/snakeCase.d.ts +26 -0
  123. package/dist/transformations/snakeCase.js +26 -0
  124. package/dist/transformations/splitChunks.d.ts +8 -0
  125. package/dist/transformations/splitChunks.js +24 -0
  126. package/dist/transformations/stringCombinations.d.ts +28 -0
  127. package/dist/transformations/stringCombinations.js +44 -0
  128. package/dist/transformations/stringPermutations.d.ts +31 -0
  129. package/dist/transformations/stringPermutations.js +53 -0
  130. package/dist/transformations/titleCase.d.ts +25 -0
  131. package/dist/transformations/titleCase.js +25 -0
  132. package/dist/transformations/toSlug.d.ts +24 -0
  133. package/dist/transformations/toSlug.js +28 -4
  134. package/dist/transformations/truncateText.d.ts +25 -0
  135. package/dist/transformations/truncateText.js +28 -3
  136. package/dist/validations/index.d.ts +27 -0
  137. package/dist/validations/index.js +38 -2
  138. package/dist/validations/isAlphaNumeric.d.ts +11 -0
  139. package/dist/validations/isAlphaNumeric.js +22 -0
  140. package/dist/validations/isAlphabetic.d.ts +9 -0
  141. package/dist/validations/isAlphabetic.js +21 -0
  142. package/dist/validations/isAnagram.d.ts +13 -0
  143. package/dist/validations/isAnagram.js +23 -0
  144. package/dist/validations/isCoordinates.d.ts +8 -0
  145. package/dist/validations/isCoordinates.js +19 -0
  146. package/dist/validations/isDate.d.ts +1 -1
  147. package/dist/validations/isDate.js +6 -8
  148. package/dist/validations/isEmail.d.ts +13 -1
  149. package/dist/validations/isEmail.js +176 -3
  150. package/dist/validations/isEmpty.d.ts +9 -0
  151. package/dist/validations/isEmpty.js +9 -0
  152. package/dist/validations/isHexColor.js +1 -1
  153. package/dist/validations/isIPv4.d.ts +21 -0
  154. package/dist/validations/isIPv4.js +22 -2
  155. package/dist/validations/isLowerCase.d.ts +12 -0
  156. package/dist/validations/isLowerCase.js +32 -0
  157. package/dist/validations/isMacAddress.d.ts +27 -0
  158. package/dist/validations/isMacAddress.js +43 -0
  159. package/dist/validations/isPalindrome.d.ts +10 -0
  160. package/dist/validations/isPalindrome.js +21 -0
  161. package/dist/validations/isPanagram.d.ts +20 -0
  162. package/dist/validations/isPanagram.js +35 -0
  163. package/dist/validations/isSlug.d.ts +27 -0
  164. package/dist/validations/isSlug.js +27 -0
  165. package/dist/validations/isTypeOf.d.ts +9 -0
  166. package/dist/validations/isTypeOf.js +30 -0
  167. package/dist/validations/isURL.d.ts +21 -0
  168. package/dist/validations/isURL.js +21 -0
  169. package/dist/validations/isUpperCase.d.ts +12 -0
  170. package/dist/validations/isUpperCase.js +32 -0
  171. package/package.json +6 -4
@@ -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) {
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- export * from "./analyzing";
2
- export * from "./formatting";
3
- export * from "./transformations";
4
- export * from "./validations";
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,11 @@ 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;
15
+ checkMultiplePatterns: typeof import("./analyzing").checkMultiplePatterns;
16
+ checkSubsequence: typeof import("./analyzing").checkSubsequence;
17
+ checkStringRotations: typeof import("./analyzing").checkStringRotations;
13
18
  };
14
19
  formatting: {
15
20
  capitalize: typeof import("./formatting").capitalize;
@@ -33,8 +38,13 @@ declare const _default: {
33
38
  escapeHtml: typeof import("./transformations").escapeHtml;
34
39
  maskSegment: typeof import("./transformations").maskSegment;
35
40
  deburr: typeof import("./transformations/deburr").deburr;
41
+ numberToText: typeof import("./transformations").numberToText;
42
+ reverseWordsInString: typeof import("./transformations").reverseWordsInString;
43
+ stringPermutations: typeof import("./transformations").stringPermutations;
44
+ stringCombinations: typeof import("./transformations").stringCombinations;
36
45
  };
37
46
  validations: {
47
+ isCoordinates: typeof import("./validations").isCoordinates;
38
48
  isDate: typeof import("./validations").isDate;
39
49
  isEmail: typeof import("./validations").isEmail;
40
50
  isEmpty: typeof import("./validations").isEmpty;
@@ -42,6 +52,14 @@ declare const _default: {
42
52
  isURL: typeof import("./validations").isURL;
43
53
  isIPv4: typeof import("./validations").isIPv4;
44
54
  isHexColor: typeof import("./validations").isHexColor;
55
+ isPalindrome: typeof import("./validations").isPalindrome;
56
+ isLowerCase: typeof import("./validations").isLowerCase;
57
+ isUpperCase: typeof import("./validations").isUpperCase;
58
+ isAlphabetic: typeof import("./validations").isAlphabetic;
59
+ isAlphaNumeric: typeof import("./validations").isAlphaNumeric;
60
+ isAnagram: typeof import("./validations").isAnagram;
61
+ isPanagram: typeof import("./validations").isPanagram;
62
+ isMacAddress: typeof import("./validations").isMacAddress;
45
63
  };
46
64
  };
47
65
  export default _default;
@@ -0,0 +1,81 @@
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 checkMultiplePatterns_1 = require("../../analyzing/checkMultiplePatterns");
9
+ (0, node_test_1.describe)('checkMultiplePatterns', () => {
10
+ (0, node_test_1.it)('finds multiple valid matches', () => {
11
+ const text = 'abracadabra';
12
+ const patterns = ['abra', 'cad'];
13
+ const result = (0, checkMultiplePatterns_1.checkMultiplePatterns)(text, patterns);
14
+ // "abra" occurs at index 0: "abra...cadabra"
15
+ // and again at index 7: "abracad...abra"
16
+ node_assert_1.default.deepStrictEqual(result['abra'], [0, 7]);
17
+ // "cad" occurs once starting at index 4: "abraCADabra"
18
+ node_assert_1.default.deepStrictEqual(result['cad'], [4]);
19
+ });
20
+ (0, node_test_1.it)('handles overlapping patterns', () => {
21
+ const text = 'aaaa';
22
+ const patterns = ['aa', 'aaa'];
23
+ const result = (0, checkMultiplePatterns_1.checkMultiplePatterns)(text, patterns);
24
+ // "aa" occurs at indices 0 ("aa.."), 1 (".aa."), 2 ("..aa")
25
+ node_assert_1.default.deepStrictEqual(result['aa'], [0, 1, 2]);
26
+ // "aaa" occurs at indices 0 ("aaa.") and 1 (".aaa")
27
+ node_assert_1.default.deepStrictEqual(result['aaa'], [0, 1]);
28
+ });
29
+ (0, node_test_1.it)('returns empty arrays when no matches found', () => {
30
+ const text = 'hello world';
31
+ const patterns = ['xyz', '123'];
32
+ const result = (0, checkMultiplePatterns_1.checkMultiplePatterns)(text, patterns);
33
+ // Neither "xyz" nor "123" exist in "hello world"
34
+ node_assert_1.default.deepStrictEqual(result['xyz'], []);
35
+ node_assert_1.default.deepStrictEqual(result['123'], []);
36
+ });
37
+ (0, node_test_1.it)('returns empty object when text is empty', () => {
38
+ // No text to search → nothing to return
39
+ const result = (0, checkMultiplePatterns_1.checkMultiplePatterns)('', ['a', 'b']);
40
+ node_assert_1.default.deepStrictEqual(result, {});
41
+ });
42
+ (0, node_test_1.it)('returns empty object when patterns array is empty', () => {
43
+ // No patterns given → nothing to search for
44
+ const result = (0, checkMultiplePatterns_1.checkMultiplePatterns)('hello', []);
45
+ node_assert_1.default.deepStrictEqual(result, {});
46
+ });
47
+ (0, node_test_1.it)('skips patterns longer than the text', () => {
48
+ const result = (0, checkMultiplePatterns_1.checkMultiplePatterns)('hi', ['longpattern']);
49
+ // pattern is longer than text → no match possible
50
+ node_assert_1.default.deepStrictEqual(result['longpattern'], []);
51
+ });
52
+ (0, node_test_1.it)('is case-sensitive by default', () => {
53
+ const text = 'Hello hello';
54
+ const patterns = ['Hello', 'hello'];
55
+ const result = (0, checkMultiplePatterns_1.checkMultiplePatterns)(text, patterns);
56
+ node_assert_1.default.deepStrictEqual(result['Hello'], [0]);
57
+ node_assert_1.default.deepStrictEqual(result['hello'], [6]);
58
+ });
59
+ (0, node_test_1.it)('handles spaces and special characters as part of patterns', () => {
60
+ const text = 'hi there!';
61
+ const patterns = [' ', '!'];
62
+ const result = (0, checkMultiplePatterns_1.checkMultiplePatterns)(text, patterns);
63
+ // space occurs at index 2, "!" occurs at the end
64
+ node_assert_1.default.deepStrictEqual(result[' '], [2]);
65
+ node_assert_1.default.deepStrictEqual(result['!'], [8]);
66
+ });
67
+ (0, node_test_1.it)('does not match mixed case unless exact', () => {
68
+ const text = 'RabinKarp';
69
+ const patterns = ['rabinkarp'];
70
+ const result = (0, checkMultiplePatterns_1.checkMultiplePatterns)(text, patterns);
71
+ // "rabinkarp" does not match "RabinKarp" because of case
72
+ node_assert_1.default.deepStrictEqual(result['rabinkarp'], []);
73
+ });
74
+ (0, node_test_1.it)('throws if text is not a string', () => {
75
+ node_assert_1.default.throws(() => (0, checkMultiplePatterns_1.checkMultiplePatterns)(123, ['a']), /Text must be a string/);
76
+ });
77
+ (0, node_test_1.it)('throws if patterns is not an array of strings', () => {
78
+ node_assert_1.default.throws(() => (0, checkMultiplePatterns_1.checkMultiplePatterns)('abc', 'a'), /Patterns must be an array of strings/);
79
+ node_assert_1.default.throws(() => (0, checkMultiplePatterns_1.checkMultiplePatterns)('abc', [123]), /Patterns must be an array of strings/);
80
+ });
81
+ });
@@ -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 checkSubsequence_1 = require("../../analyzing/checkSubsequence");
9
+ (0, node_test_1.describe)('checkSubsequence', () => {
10
+ (0, node_test_1.it)('returns true for valid subsequences', () => {
11
+ node_assert_1.default.strictEqual((0, checkSubsequence_1.checkSubsequence)('abcde', 'ace'), true);
12
+ node_assert_1.default.strictEqual((0, checkSubsequence_1.checkSubsequence)('abracadabra', 'aaa'), true);
13
+ node_assert_1.default.strictEqual((0, checkSubsequence_1.checkSubsequence)('hello world', 'hlo'), true);
14
+ });
15
+ (0, node_test_1.it)('returns false when order is broken', () => {
16
+ node_assert_1.default.strictEqual((0, checkSubsequence_1.checkSubsequence)('abcde', 'aec'), false);
17
+ node_assert_1.default.strictEqual((0, checkSubsequence_1.checkSubsequence)('abcdef', 'z'), false);
18
+ });
19
+ (0, node_test_1.it)('handles empty subsequence', () => {
20
+ node_assert_1.default.strictEqual((0, checkSubsequence_1.checkSubsequence)('anything', ''), true);
21
+ });
22
+ (0, node_test_1.it)('is case-sensitive', () => {
23
+ node_assert_1.default.strictEqual((0, checkSubsequence_1.checkSubsequence)('abc', 'A'), false);
24
+ node_assert_1.default.strictEqual((0, checkSubsequence_1.checkSubsequence)('AbC', 'AC'), true);
25
+ });
26
+ (0, node_test_1.it)('handles spaces as normal characters', () => {
27
+ node_assert_1.default.strictEqual((0, checkSubsequence_1.checkSubsequence)('a b c', 'abc'), true);
28
+ node_assert_1.default.strictEqual((0, checkSubsequence_1.checkSubsequence)('a b c', 'a c'), true);
29
+ });
30
+ (0, node_test_1.it)('throws if inputs are not strings', () => {
31
+ node_assert_1.default.throws(() => (0, checkSubsequence_1.checkSubsequence)(123, 'abc'), /Both inputs must be strings/);
32
+ node_assert_1.default.throws(() => (0, checkSubsequence_1.checkSubsequence)('abc', null), /Both inputs must be strings/);
33
+ });
34
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,20 @@
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 = __importDefault(require("node:test"));
7
+ const strict_1 = __importDefault(require("node:assert/strict"));
8
+ const contentWordCount_js_1 = require("../../analyzing/contentWordCount.js");
9
+ (0, node_test_1.default)("counts content words in a normal sentence", () => {
10
+ strict_1.default.equal((0, contentWordCount_js_1.contentWordCount)("This is a test of the system"), 2);
11
+ });
12
+ (0, node_test_1.default)("returns 0 when there are no content words", () => {
13
+ strict_1.default.equal((0, contentWordCount_js_1.contentWordCount)("is the at of"), 0);
14
+ });
15
+ (0, node_test_1.default)("ignores case and punctuation", () => {
16
+ strict_1.default.equal((0, contentWordCount_js_1.contentWordCount)("Elephants, ELEPHANTS, elephants!"), 3);
17
+ });
18
+ (0, node_test_1.default)("returns 0 for empty string", () => {
19
+ strict_1.default.equal((0, contentWordCount_js_1.contentWordCount)(""), 0);
20
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,20 @@
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 = __importDefault(require("node:test"));
7
+ const strict_1 = __importDefault(require("node:assert/strict"));
8
+ const functionWordCount_js_1 = require("../../analyzing/functionWordCount.js");
9
+ (0, node_test_1.default)("counts function words in a normal sentence", () => {
10
+ strict_1.default.equal((0, functionWordCount_js_1.functionWordCount)("This is a test of the system"), 5);
11
+ });
12
+ (0, node_test_1.default)("returns 0 when there are no function words", () => {
13
+ strict_1.default.equal((0, functionWordCount_js_1.functionWordCount)("Elephants run fast"), 0);
14
+ });
15
+ (0, node_test_1.default)("ignores case and punctuation", () => {
16
+ strict_1.default.equal((0, functionWordCount_js_1.functionWordCount)("The, THE, the!"), 3);
17
+ });
18
+ (0, node_test_1.default)("returns 0 for empty string", () => {
19
+ strict_1.default.equal((0, functionWordCount_js_1.functionWordCount)(""), 0);
20
+ });
@@ -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)("readingDuration", () => {
9
+ (0, node_test_1.describe)('readingDuration', () => {
10
10
  const testCases = [
11
- { text: "", expectedDuration: 0 }, // Empty string
12
- { text: "This is a short text", expectedDuration: 0 }, // 5 words
11
+ { text: '', expectedDuration: 0 }, // Empty string
12
+ { text: 'This is a short text', expectedDuration: 0 }, // 5 words
13
13
  {
14
- text: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.",
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: " This text has extra spaces ", expectedDuration: 0 }, // 6 words
18
- { text: "Word", expectedDuration: 0 }, // 1 word
17
+ { text: ' This text has extra spaces ', expectedDuration: 0 }, // 6 words
18
+ { text: 'Word', expectedDuration: 0 }, // 1 word
19
19
  {
20
- text: "A longer text with exactly twenty-three words to test the calculation properly.",
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: "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.",
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("Word").join(" "), // Generates a text with 9999 words
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("Word").join(" "), // Generates a text with 230 words
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("Word").join(" "), // Generates a text with 460 words
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(" ").length} words`, () => {
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 {};