stringzy 4.0.0 → 4.2.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 (139) hide show
  1. package/.github/workflows/auto-assign.yml +26 -0
  2. package/CODE_OF_CONDUCT.MD +115 -0
  3. package/README.md +963 -40
  4. package/dist/analyzing/checkMultiplePatterns.d.ts +14 -0
  5. package/dist/analyzing/checkMultiplePatterns.js +75 -0
  6. package/dist/analyzing/checkSubsequence.d.ts +14 -0
  7. package/dist/analyzing/checkSubsequence.js +33 -0
  8. package/dist/analyzing/contentWordCount.d.ts +11 -0
  9. package/dist/analyzing/contentWordCount.js +23 -0
  10. package/dist/analyzing/functionWordCount.d.ts +11 -0
  11. package/dist/analyzing/functionWordCount.js +33 -0
  12. package/dist/analyzing/index.d.ts +14 -0
  13. package/dist/analyzing/index.js +22 -2
  14. package/dist/analyzing/lexicographicalRank.d.ts +26 -0
  15. package/dist/analyzing/lexicographicalRank.js +66 -0
  16. package/dist/analyzing/patternCount.d.ts +6 -5
  17. package/dist/analyzing/patternCount.js +19 -17
  18. package/dist/analyzing/stringRotation.d.ts +29 -0
  19. package/dist/analyzing/stringRotation.js +44 -0
  20. package/dist/formatting/binary.d.ts +24 -0
  21. package/dist/formatting/binary.js +49 -0
  22. package/dist/formatting/creditCard.d.ts +8 -0
  23. package/dist/formatting/creditCard.js +28 -0
  24. package/dist/formatting/decimal.d.ts +21 -0
  25. package/dist/formatting/decimal.js +73 -0
  26. package/dist/formatting/duration.d.ts +27 -0
  27. package/dist/formatting/duration.js +92 -0
  28. package/dist/formatting/fileSize.d.ts +18 -0
  29. package/dist/formatting/fileSize.js +39 -0
  30. package/dist/formatting/hexadecimal.d.ts +14 -0
  31. package/dist/formatting/hexadecimal.js +38 -0
  32. package/dist/formatting/index.d.ts +42 -0
  33. package/dist/formatting/index.js +57 -1
  34. package/dist/formatting/listToString.d.ts +17 -0
  35. package/dist/formatting/listToString.js +35 -0
  36. package/dist/formatting/octal.d.ts +19 -0
  37. package/dist/formatting/octal.js +31 -0
  38. package/dist/formatting/ordinal.d.ts +20 -0
  39. package/dist/formatting/ordinal.js +43 -0
  40. package/dist/formatting/percentage.d.ts +19 -0
  41. package/dist/formatting/percentage.js +31 -0
  42. package/dist/formatting/romanNumerals.d.ts +20 -0
  43. package/dist/formatting/romanNumerals.js +53 -0
  44. package/dist/formatting/scientific.d.ts +14 -0
  45. package/dist/formatting/scientific.js +24 -0
  46. package/dist/formatting/temperature.d.ts +6 -0
  47. package/dist/formatting/temperature.js +27 -0
  48. package/dist/formatting/trim.d.ts +10 -0
  49. package/dist/formatting/trim.js +20 -0
  50. package/dist/index.d.ts +30 -0
  51. package/dist/tests/analyzing/checkMultiplePatterns.test.d.ts +1 -0
  52. package/dist/tests/analyzing/checkMultiplePatterns.test.js +81 -0
  53. package/dist/tests/analyzing/checkSubsequence.test.d.ts +1 -0
  54. package/dist/tests/analyzing/checkSubsequence.test.js +34 -0
  55. package/dist/tests/analyzing/contentWordCount.test.d.ts +1 -0
  56. package/dist/tests/analyzing/contentWordCount.test.js +20 -0
  57. package/dist/tests/analyzing/functionWordCount.test.d.ts +1 -0
  58. package/dist/tests/analyzing/functionWordCount.test.js +20 -0
  59. package/dist/tests/analyzing/lexicographicalRank.test.d.ts +1 -0
  60. package/dist/tests/analyzing/lexicographicalRank.test.js +43 -0
  61. package/dist/tests/analyzing/stringRotation.test.d.ts +1 -0
  62. package/dist/tests/analyzing/stringRotation.test.js +42 -0
  63. package/dist/tests/formatting/binary.test.d.ts +1 -0
  64. package/dist/tests/formatting/binary.test.js +53 -0
  65. package/dist/tests/formatting/creditCard.test.d.ts +1 -0
  66. package/dist/tests/formatting/creditCard.test.js +31 -0
  67. package/dist/tests/formatting/decimal.test.d.ts +1 -0
  68. package/dist/tests/formatting/decimal.test.js +62 -0
  69. package/dist/tests/formatting/duration.test.d.ts +1 -0
  70. package/dist/tests/formatting/duration.test.js +61 -0
  71. package/dist/tests/formatting/fileSize.test.d.ts +1 -0
  72. package/dist/tests/formatting/fileSize.test.js +39 -0
  73. package/dist/tests/formatting/hexadecimal.test.d.ts +1 -0
  74. package/dist/tests/formatting/hexadecimal.test.js +38 -0
  75. package/dist/tests/formatting/listToString.test.d.ts +1 -0
  76. package/dist/tests/formatting/listToString.test.js +37 -0
  77. package/dist/tests/formatting/octal.test.d.ts +1 -0
  78. package/dist/tests/formatting/octal.test.js +36 -0
  79. package/dist/tests/formatting/ordinal.test.d.ts +1 -0
  80. package/dist/tests/formatting/ordinal.test.js +37 -0
  81. package/dist/tests/formatting/percentage.test.d.ts +1 -0
  82. package/dist/tests/formatting/percentage.test.js +38 -0
  83. package/dist/tests/formatting/romanNumerals.test.d.ts +1 -0
  84. package/dist/tests/formatting/romanNumerals.test.js +35 -0
  85. package/dist/tests/formatting/scientific.test.d.ts +1 -0
  86. package/dist/tests/formatting/scientific.test.js +35 -0
  87. package/dist/tests/formatting/temperature.test.d.ts +1 -0
  88. package/dist/tests/formatting/temperature.test.js +34 -0
  89. package/dist/tests/formatting/trim.test.d.ts +1 -0
  90. package/dist/tests/formatting/trim.test.js +42 -0
  91. package/dist/tests/transformations/reverseString.test.d.ts +1 -0
  92. package/dist/tests/transformations/reverseString.test.js +41 -0
  93. package/dist/tests/transformations/stringCombinations.test.d.ts +1 -0
  94. package/dist/tests/transformations/stringCombinations.test.js +41 -0
  95. package/dist/tests/transformations/stringPermutations.test.d.ts +1 -0
  96. package/dist/tests/transformations/stringPermutations.test.js +110 -0
  97. package/dist/tests/validations/isAlphaNumeric.test.d.ts +1 -0
  98. package/dist/tests/validations/isAlphaNumeric.test.js +30 -0
  99. package/dist/tests/validations/isAlphabetic.test.d.ts +1 -0
  100. package/dist/tests/validations/isAlphabetic.test.js +32 -0
  101. package/dist/tests/validations/isAnagram.test.d.ts +1 -0
  102. package/dist/tests/validations/isAnagram.test.js +44 -0
  103. package/dist/tests/validations/isIPv6.test.d.ts +1 -0
  104. package/dist/tests/validations/isIPv6.test.js +65 -0
  105. package/dist/tests/validations/isLowerCase.test.d.ts +1 -0
  106. package/dist/tests/validations/isLowerCase.test.js +50 -0
  107. package/dist/tests/validations/isMacAddress.test.d.ts +1 -0
  108. package/dist/tests/validations/isMacAddress.test.js +72 -0
  109. package/dist/tests/validations/isPanagram.test.d.ts +1 -0
  110. package/dist/tests/validations/isPanagram.test.js +39 -0
  111. package/dist/tests/validations/isUpperCase.test.d.ts +1 -0
  112. package/dist/tests/validations/isUpperCase.test.js +50 -0
  113. package/dist/transformations/index.d.ts +10 -0
  114. package/dist/transformations/index.js +16 -2
  115. package/dist/transformations/reverseWordsInString .d.ts +9 -0
  116. package/dist/transformations/reverseWordsInString .js +49 -0
  117. package/dist/transformations/stringCombinations.d.ts +28 -0
  118. package/dist/transformations/stringCombinations.js +44 -0
  119. package/dist/transformations/stringPermutations.d.ts +53 -0
  120. package/dist/transformations/stringPermutations.js +179 -0
  121. package/dist/validations/index.d.ts +24 -0
  122. package/dist/validations/index.js +34 -2
  123. package/dist/validations/isAlphaNumeric.d.ts +11 -0
  124. package/dist/validations/isAlphaNumeric.js +22 -0
  125. package/dist/validations/isAlphabetic.d.ts +9 -0
  126. package/dist/validations/isAlphabetic.js +21 -0
  127. package/dist/validations/isAnagram.d.ts +13 -0
  128. package/dist/validations/isAnagram.js +23 -0
  129. package/dist/validations/isIPv6.d.ts +24 -0
  130. package/dist/validations/isIPv6.js +45 -0
  131. package/dist/validations/isLowerCase.d.ts +12 -0
  132. package/dist/validations/isLowerCase.js +32 -0
  133. package/dist/validations/isMacAddress.d.ts +27 -0
  134. package/dist/validations/isMacAddress.js +43 -0
  135. package/dist/validations/isPanagram.d.ts +20 -0
  136. package/dist/validations/isPanagram.js +35 -0
  137. package/dist/validations/isUpperCase.d.ts +12 -0
  138. package/dist/validations/isUpperCase.js +32 -0
  139. package/package.json +3 -3
@@ -14,6 +14,9 @@ export { truncateText } from './truncateText';
14
14
  export { escapeHtml } from './escapeHTML';
15
15
  export { maskSegment } from './maskSegment';
16
16
  export { numberToText } from './numberToText/main';
17
+ export { reverseWordsInString } from './reverseWordsInString ';
18
+ export { stringPermutations, stringPermutationsGenerator } from './stringPermutations';
19
+ export { stringCombinations } from './stringCombinations';
17
20
  import { camelCase } from './camelCase';
18
21
  import { capitalizeWords } from './capitalizeWords';
19
22
  import { constantCase } from './constantCase';
@@ -31,6 +34,9 @@ import { escapeHtml } from './escapeHTML';
31
34
  import { maskSegment } from './maskSegment';
32
35
  import { deburr } from './deburr';
33
36
  import { numberToText } from './numberToText/main';
37
+ import { reverseWordsInString } from './reverseWordsInString ';
38
+ import { stringPermutations, stringPermutationsGenerator } from './stringPermutations';
39
+ import { stringCombinations } from './stringCombinations';
34
40
  export declare const transformations: {
35
41
  camelCase: typeof camelCase;
36
42
  capitalizeWords: typeof capitalizeWords;
@@ -49,4 +55,8 @@ export declare const transformations: {
49
55
  maskSegment: typeof maskSegment;
50
56
  deburr: typeof deburr;
51
57
  numberToText: typeof numberToText;
58
+ reverseWordsInString: typeof reverseWordsInString;
59
+ stringPermutations: typeof stringPermutations;
60
+ stringPermutationsGenerator: typeof stringPermutationsGenerator;
61
+ stringCombinations: typeof stringCombinations;
52
62
  };
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.transformations = exports.numberToText = exports.maskSegment = exports.escapeHtml = exports.truncateText = exports.toSlug = exports.titleCase = exports.snakeCase = exports.removeWords = exports.removeSpecialChars = exports.removeDuplicates = exports.pascalCase = exports.kebabCase = exports.initials = exports.constantCase = exports.capitalizeWords = exports.camelCase = void 0;
3
+ exports.transformations = exports.stringCombinations = exports.stringPermutationsGenerator = exports.stringPermutations = exports.reverseWordsInString = exports.numberToText = exports.maskSegment = exports.escapeHtml = exports.truncateText = exports.toSlug = exports.titleCase = exports.snakeCase = exports.removeWords = exports.removeSpecialChars = exports.removeDuplicates = exports.pascalCase = exports.kebabCase = exports.initials = exports.constantCase = exports.capitalizeWords = exports.camelCase = void 0;
4
4
  var camelCase_1 = require("./camelCase");
5
5
  Object.defineProperty(exports, "camelCase", { enumerable: true, get: function () { return camelCase_1.camelCase; } });
6
6
  var capitalizeWords_1 = require("./capitalizeWords");
@@ -33,6 +33,13 @@ var maskSegment_1 = require("./maskSegment");
33
33
  Object.defineProperty(exports, "maskSegment", { enumerable: true, get: function () { return maskSegment_1.maskSegment; } });
34
34
  var main_1 = require("./numberToText/main");
35
35
  Object.defineProperty(exports, "numberToText", { enumerable: true, get: function () { return main_1.numberToText; } });
36
+ var reverseWordsInString_1 = require("./reverseWordsInString ");
37
+ Object.defineProperty(exports, "reverseWordsInString", { enumerable: true, get: function () { return reverseWordsInString_1.reverseWordsInString; } });
38
+ var stringPermutations_1 = require("./stringPermutations");
39
+ Object.defineProperty(exports, "stringPermutations", { enumerable: true, get: function () { return stringPermutations_1.stringPermutations; } });
40
+ Object.defineProperty(exports, "stringPermutationsGenerator", { enumerable: true, get: function () { return stringPermutations_1.stringPermutationsGenerator; } });
41
+ var stringCombinations_1 = require("./stringCombinations");
42
+ Object.defineProperty(exports, "stringCombinations", { enumerable: true, get: function () { return stringCombinations_1.stringCombinations; } });
36
43
  const camelCase_2 = require("./camelCase");
37
44
  const capitalizeWords_2 = require("./capitalizeWords");
38
45
  const constantCase_2 = require("./constantCase");
@@ -50,6 +57,9 @@ const escapeHTML_2 = require("./escapeHTML");
50
57
  const maskSegment_2 = require("./maskSegment");
51
58
  const deburr_1 = require("./deburr");
52
59
  const main_2 = require("./numberToText/main");
60
+ const reverseWordsInString_2 = require("./reverseWordsInString ");
61
+ const stringPermutations_2 = require("./stringPermutations");
62
+ const stringCombinations_2 = require("./stringCombinations");
53
63
  exports.transformations = {
54
64
  camelCase: camelCase_2.camelCase,
55
65
  capitalizeWords: capitalizeWords_2.capitalizeWords,
@@ -67,5 +77,9 @@ exports.transformations = {
67
77
  escapeHtml: escapeHTML_2.escapeHtml,
68
78
  maskSegment: maskSegment_2.maskSegment,
69
79
  deburr: deburr_1.deburr,
70
- numberToText: main_2.numberToText
80
+ numberToText: main_2.numberToText,
81
+ reverseWordsInString: reverseWordsInString_2.reverseWordsInString,
82
+ stringPermutations: stringPermutations_2.stringPermutations,
83
+ stringPermutationsGenerator: stringPermutations_2.stringPermutationsGenerator,
84
+ stringCombinations: stringCombinations_2.stringCombinations
71
85
  };
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Reverses the order of words in a given string while preserving the
3
+ * exact spacing (including multiple spaces) between them.
4
+ *
5
+ * @param {string} str - The input string whose words are to be reversed.
6
+ * @returns {string} The string with the order of words reversed and all original spacing intact.
7
+ * @throws {TypeError} If the input is not a string.
8
+ */
9
+ export declare function reverseWordsInString(str: string): string;
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.reverseWordsInString = reverseWordsInString;
4
+ /**
5
+ * Reverses the order of words in a given string while preserving the
6
+ * exact spacing (including multiple spaces) between them.
7
+ *
8
+ * @param {string} str - The input string whose words are to be reversed.
9
+ * @returns {string} The string with the order of words reversed and all original spacing intact.
10
+ * @throws {TypeError} If the input is not a string.
11
+ */
12
+ function reverseWordsInString(str) {
13
+ if (typeof str !== 'string') {
14
+ throw new TypeError('Input must be a string');
15
+ }
16
+ // 1. Extract all blocks of non-whitespace characters (the words).
17
+ const words = str.match(/\S+/g) || [];
18
+ // 2. If there are no words (e.g., empty or whitespace-only string), return the original string.
19
+ if (words.length === 0) {
20
+ return str;
21
+ }
22
+ // 3. Extract all blocks of whitespace.
23
+ const spaces = str.match(/\s+/g) || [];
24
+ // 4. Reverse ONLY the array of words.
25
+ const reversedWords = words.reverse();
26
+ // 5. Stitch the reversed words and original spaces back together.
27
+ let result = '';
28
+ const startsWithSpace = /^\s/.test(str);
29
+ if (startsWithSpace) {
30
+ // If the string starts with a space, the pattern is: space, word, space, word...
31
+ for (let i = 0; i < reversedWords.length; i++) {
32
+ result += spaces[i] + reversedWords[i];
33
+ }
34
+ // Append any final trailing space block.
35
+ if (spaces.length > reversedWords.length) {
36
+ result += spaces[spaces.length - 1];
37
+ }
38
+ }
39
+ else {
40
+ // If the string starts with a word, the pattern is: word, space, word, space...
41
+ for (let i = 0; i < reversedWords.length; i++) {
42
+ result += reversedWords[i];
43
+ if (spaces[i]) {
44
+ result += spaces[i];
45
+ }
46
+ }
47
+ }
48
+ return result;
49
+ }
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Generates all unique combinations (subsequences) of a given string,
3
+ * including the empty string.
4
+ *
5
+ * Handles duplicate characters by ensuring only unique combinations are returned.
6
+ * The order of combinations in the output array is not guaranteed.
7
+ *
8
+ * @param {string} str - The input string to generate combinations from.
9
+ * @returns {string[]} An array containing all unique combinations of the string.
10
+ * @throws {TypeError} If the input is not a string.
11
+ *
12
+ * @example
13
+ * stringCombinations("ab");
14
+ * // ["", "a", "b", "ab"]
15
+ *
16
+ * @example
17
+ * stringCombinations("abc");
18
+ * // ["", "a", "b", "c", "ab", "ac", "bc", "abc"]
19
+ *
20
+ * @example
21
+ * stringCombinations("aab");
22
+ * // ["", "a", "b", "aa", "ab", "aab"]
23
+ *
24
+ * @example
25
+ * stringCombinations("");
26
+ * // [""]
27
+ */
28
+ export declare function stringCombinations(str: string): string[];
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.stringCombinations = stringCombinations;
4
+ /**
5
+ * Generates all unique combinations (subsequences) of a given string,
6
+ * including the empty string.
7
+ *
8
+ * Handles duplicate characters by ensuring only unique combinations are returned.
9
+ * The order of combinations in the output array is not guaranteed.
10
+ *
11
+ * @param {string} str - The input string to generate combinations from.
12
+ * @returns {string[]} An array containing all unique combinations of the string.
13
+ * @throws {TypeError} If the input is not a string.
14
+ *
15
+ * @example
16
+ * stringCombinations("ab");
17
+ * // ["", "a", "b", "ab"]
18
+ *
19
+ * @example
20
+ * stringCombinations("abc");
21
+ * // ["", "a", "b", "c", "ab", "ac", "bc", "abc"]
22
+ *
23
+ * @example
24
+ * stringCombinations("aab");
25
+ * // ["", "a", "b", "aa", "ab", "aab"]
26
+ *
27
+ * @example
28
+ * stringCombinations("");
29
+ * // [""]
30
+ */
31
+ function stringCombinations(str) {
32
+ if (typeof str !== 'string') {
33
+ throw new TypeError('Input must be a string');
34
+ }
35
+ const results = new Set();
36
+ function backtrack(start, path) {
37
+ results.add(path);
38
+ for (let i = start; i < str.length; i++) {
39
+ backtrack(i + 1, path + str[i]);
40
+ }
41
+ }
42
+ backtrack(0, '');
43
+ return Array.from(results);
44
+ }
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Generates all unique permutations of a given string.
3
+ *
4
+ * Handles repeated characters by ensuring only unique permutations
5
+ * are included in the result. The order of permutations is not guaranteed.
6
+ *
7
+ * Performance optimized version using iterative approach and efficient
8
+ * character frequency tracking to avoid duplicate permutations.
9
+ *
10
+ * @param {string} str - The input string to generate permutations for.
11
+ * @param {number} [limit] - Optional limit on number of permutations to generate.
12
+ * @returns {string[]} An array of unique permutations of the input string.
13
+ * @throws {TypeError} If the input is not a string.
14
+ * @throws {RangeError} If limit is negative.
15
+ *
16
+ * @example
17
+ * stringPermutations("ab");
18
+ * // ["ab", "ba"]
19
+ *
20
+ * @example
21
+ * stringPermutations("abc");
22
+ * // ["abc", "acb", "bac", "bca", "cab", "cba"]
23
+ *
24
+ * @example
25
+ * stringPermutations("aab");
26
+ * // ["aab", "aba", "baa"]
27
+ *
28
+ * @example
29
+ * stringPermutations("abcdef", 10);
30
+ * // Returns first 10 permutations
31
+ *
32
+ * @example
33
+ * stringPermutations("");
34
+ * // [""]
35
+ *
36
+ * @example
37
+ * stringPermutations("a");
38
+ * // ["a"]
39
+ */
40
+ export declare function stringPermutations(str: string, limit?: number): string[];
41
+ /**
42
+ * Generator function for permutations - yields permutations one at a time.
43
+ * This is the most memory-efficient approach for very large strings.
44
+ *
45
+ * @param {string} str - The input string to generate permutations for.
46
+ * @yields {string} Each unique permutation.
47
+ *
48
+ * @example
49
+ * for (const perm of stringPermutationsGenerator("abc")) {
50
+ * console.log(perm);
51
+ * }
52
+ */
53
+ export declare function stringPermutationsGenerator(str: string): Generator<string, void, unknown>;
@@ -0,0 +1,179 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.stringPermutations = stringPermutations;
4
+ exports.stringPermutationsGenerator = stringPermutationsGenerator;
5
+ /**
6
+ * Generates all unique permutations of a given string.
7
+ *
8
+ * Handles repeated characters by ensuring only unique permutations
9
+ * are included in the result. The order of permutations is not guaranteed.
10
+ *
11
+ * Performance optimized version using iterative approach and efficient
12
+ * character frequency tracking to avoid duplicate permutations.
13
+ *
14
+ * @param {string} str - The input string to generate permutations for.
15
+ * @param {number} [limit] - Optional limit on number of permutations to generate.
16
+ * @returns {string[]} An array of unique permutations of the input string.
17
+ * @throws {TypeError} If the input is not a string.
18
+ * @throws {RangeError} If limit is negative.
19
+ *
20
+ * @example
21
+ * stringPermutations("ab");
22
+ * // ["ab", "ba"]
23
+ *
24
+ * @example
25
+ * stringPermutations("abc");
26
+ * // ["abc", "acb", "bac", "bca", "cab", "cba"]
27
+ *
28
+ * @example
29
+ * stringPermutations("aab");
30
+ * // ["aab", "aba", "baa"]
31
+ *
32
+ * @example
33
+ * stringPermutations("abcdef", 10);
34
+ * // Returns first 10 permutations
35
+ *
36
+ * @example
37
+ * stringPermutations("");
38
+ * // [""]
39
+ *
40
+ * @example
41
+ * stringPermutations("a");
42
+ * // ["a"]
43
+ */
44
+ function stringPermutations(str, limit) {
45
+ if (typeof str !== 'string') {
46
+ throw new TypeError('Input must be a string');
47
+ }
48
+ if (limit !== undefined && limit < 0) {
49
+ throw new RangeError('Limit must be non-negative');
50
+ }
51
+ if (str.length === 0)
52
+ return [''];
53
+ // For small strings, use the original approach for simplicity
54
+ if (str.length <= 6) {
55
+ return generatePermutationsSmall(str, limit);
56
+ }
57
+ // For larger strings, use optimized approach
58
+ return generatePermutationsOptimized(str, limit);
59
+ }
60
+ /**
61
+ * Generates permutations for small strings (≤6 characters) using recursive approach.
62
+ * This is more memory efficient for small inputs.
63
+ */
64
+ function generatePermutationsSmall(str, limit) {
65
+ const results = new Set();
66
+ let count = 0;
67
+ const permute = (prefix, remaining) => {
68
+ if (limit !== undefined && count >= limit)
69
+ return;
70
+ if (remaining.length === 0) {
71
+ results.add(prefix);
72
+ count++;
73
+ }
74
+ else {
75
+ for (let i = 0; i < remaining.length; i++) {
76
+ if (limit !== undefined && count >= limit)
77
+ break;
78
+ permute(prefix + remaining[i], remaining.slice(0, i) + remaining.slice(i + 1));
79
+ }
80
+ }
81
+ };
82
+ permute('', str);
83
+ return Array.from(results);
84
+ }
85
+ /**
86
+ * Generates permutations for larger strings using optimized iterative approach.
87
+ * Uses character frequency tracking to avoid duplicate permutations efficiently.
88
+ */
89
+ function generatePermutationsOptimized(str, limit) {
90
+ // Count character frequencies
91
+ const charCount = new Map();
92
+ for (const char of str) {
93
+ charCount.set(char, (charCount.get(char) || 0) + 1);
94
+ }
95
+ const results = [];
96
+ const chars = Array.from(charCount.keys());
97
+ const counts = chars.map(char => charCount.get(char));
98
+ // Use iterative approach with stack to avoid recursion
99
+ const stack = [{
100
+ permutation: '',
101
+ remainingCounts: [...counts],
102
+ depth: 0
103
+ }];
104
+ while (stack.length > 0) {
105
+ if (limit !== undefined && results.length >= limit)
106
+ break;
107
+ const current = stack.pop();
108
+ if (current.depth === str.length) {
109
+ results.push(current.permutation);
110
+ continue;
111
+ }
112
+ // Generate next level permutations
113
+ for (let i = 0; i < chars.length; i++) {
114
+ if (current.remainingCounts[i] > 0) {
115
+ const newCounts = [...current.remainingCounts];
116
+ newCounts[i]--;
117
+ stack.push({
118
+ permutation: current.permutation + chars[i],
119
+ remainingCounts: newCounts,
120
+ depth: current.depth + 1
121
+ });
122
+ }
123
+ }
124
+ }
125
+ return results;
126
+ }
127
+ /**
128
+ * Generator function for permutations - yields permutations one at a time.
129
+ * This is the most memory-efficient approach for very large strings.
130
+ *
131
+ * @param {string} str - The input string to generate permutations for.
132
+ * @yields {string} Each unique permutation.
133
+ *
134
+ * @example
135
+ * for (const perm of stringPermutationsGenerator("abc")) {
136
+ * console.log(perm);
137
+ * }
138
+ */
139
+ function* stringPermutationsGenerator(str) {
140
+ if (typeof str !== 'string') {
141
+ throw new TypeError('Input must be a string');
142
+ }
143
+ if (str.length === 0) {
144
+ yield '';
145
+ return;
146
+ }
147
+ // Count character frequencies
148
+ const charCount = new Map();
149
+ for (const char of str) {
150
+ charCount.set(char, (charCount.get(char) || 0) + 1);
151
+ }
152
+ const chars = Array.from(charCount.keys());
153
+ const counts = chars.map(char => charCount.get(char));
154
+ // Use iterative approach with stack
155
+ const stack = [{
156
+ permutation: '',
157
+ remainingCounts: [...counts],
158
+ depth: 0
159
+ }];
160
+ while (stack.length > 0) {
161
+ const current = stack.pop();
162
+ if (current.depth === str.length) {
163
+ yield current.permutation;
164
+ continue;
165
+ }
166
+ // Generate next level permutations
167
+ for (let i = 0; i < chars.length; i++) {
168
+ if (current.remainingCounts[i] > 0) {
169
+ const newCounts = [...current.remainingCounts];
170
+ newCounts[i]--;
171
+ stack.push({
172
+ permutation: current.permutation + chars[i],
173
+ remainingCounts: newCounts,
174
+ depth: current.depth + 1
175
+ });
176
+ }
177
+ }
178
+ }
179
+ }
@@ -5,8 +5,16 @@ export { isEmpty } from './isEmpty';
5
5
  export { isSlug } from './isSlug';
6
6
  export { isURL } from './isURL';
7
7
  export { isIPv4 } from './isIPv4';
8
+ export { isIPv6 } from './isIPv6';
8
9
  export { isHexColor } from './isHexColor';
9
10
  export { isPalindrome } from './isPalindrome';
11
+ export { isLowerCase } from './isLowerCase';
12
+ export { isUpperCase } from './isUpperCase';
13
+ export { isAlphabetic } from './isAlphabetic';
14
+ export { isAlphaNumeric } from './isAlphaNumeric';
15
+ export { isAnagram } from './isAnagram';
16
+ export { isPanagram } from './isPanagram';
17
+ export { isMacAddress } from './isMacAddress';
10
18
  import { isCoordinates } from './isCoordinates';
11
19
  import { isDate } from './isDate';
12
20
  import { isEmail } from './isEmail';
@@ -14,8 +22,16 @@ import { isEmpty } from './isEmpty';
14
22
  import { isSlug } from './isSlug';
15
23
  import { isURL } from './isURL';
16
24
  import { isIPv4 } from './isIPv4';
25
+ import { isIPv6 } from './isIPv6';
17
26
  import { isHexColor } from './isHexColor';
18
27
  import { isPalindrome } from './isPalindrome';
28
+ import { isLowerCase } from './isLowerCase';
29
+ import { isUpperCase } from './isUpperCase';
30
+ import { isAlphabetic } from './isAlphabetic';
31
+ import { isAlphaNumeric } from './isAlphaNumeric';
32
+ import { isAnagram } from './isAnagram';
33
+ import { isPanagram } from './isPanagram';
34
+ import { isMacAddress } from './isMacAddress';
19
35
  export declare const validations: {
20
36
  isCoordinates: typeof isCoordinates;
21
37
  isDate: typeof isDate;
@@ -24,6 +40,14 @@ export declare const validations: {
24
40
  isSlug: typeof isSlug;
25
41
  isURL: typeof isURL;
26
42
  isIPv4: typeof isIPv4;
43
+ isIPv6: typeof isIPv6;
27
44
  isHexColor: typeof isHexColor;
28
45
  isPalindrome: typeof isPalindrome;
46
+ isLowerCase: typeof isLowerCase;
47
+ isUpperCase: typeof isUpperCase;
48
+ isAlphabetic: typeof isAlphabetic;
49
+ isAlphaNumeric: typeof isAlphaNumeric;
50
+ isAnagram: typeof isAnagram;
51
+ isPanagram: typeof isPanagram;
52
+ isMacAddress: typeof isMacAddress;
29
53
  };
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validations = exports.isPalindrome = exports.isHexColor = exports.isIPv4 = exports.isURL = exports.isSlug = exports.isEmpty = exports.isEmail = exports.isDate = exports.isCoordinates = void 0;
3
+ exports.validations = exports.isMacAddress = exports.isPanagram = exports.isAnagram = exports.isAlphaNumeric = exports.isAlphabetic = exports.isUpperCase = exports.isLowerCase = exports.isPalindrome = exports.isHexColor = exports.isIPv6 = exports.isIPv4 = exports.isURL = exports.isSlug = exports.isEmpty = exports.isEmail = exports.isDate = exports.isCoordinates = void 0;
4
4
  var isCoordinates_1 = require("./isCoordinates");
5
5
  Object.defineProperty(exports, "isCoordinates", { enumerable: true, get: function () { return isCoordinates_1.isCoordinates; } });
6
6
  var isDate_1 = require("./isDate");
@@ -15,10 +15,26 @@ var isURL_1 = require("./isURL");
15
15
  Object.defineProperty(exports, "isURL", { enumerable: true, get: function () { return isURL_1.isURL; } });
16
16
  var isIPv4_1 = require("./isIPv4");
17
17
  Object.defineProperty(exports, "isIPv4", { enumerable: true, get: function () { return isIPv4_1.isIPv4; } });
18
+ var isIPv6_1 = require("./isIPv6");
19
+ Object.defineProperty(exports, "isIPv6", { enumerable: true, get: function () { return isIPv6_1.isIPv6; } });
18
20
  var isHexColor_1 = require("./isHexColor");
19
21
  Object.defineProperty(exports, "isHexColor", { enumerable: true, get: function () { return isHexColor_1.isHexColor; } });
20
22
  var isPalindrome_1 = require("./isPalindrome");
21
23
  Object.defineProperty(exports, "isPalindrome", { enumerable: true, get: function () { return isPalindrome_1.isPalindrome; } });
24
+ var isLowerCase_1 = require("./isLowerCase");
25
+ Object.defineProperty(exports, "isLowerCase", { enumerable: true, get: function () { return isLowerCase_1.isLowerCase; } });
26
+ var isUpperCase_1 = require("./isUpperCase");
27
+ Object.defineProperty(exports, "isUpperCase", { enumerable: true, get: function () { return isUpperCase_1.isUpperCase; } });
28
+ var isAlphabetic_1 = require("./isAlphabetic");
29
+ Object.defineProperty(exports, "isAlphabetic", { enumerable: true, get: function () { return isAlphabetic_1.isAlphabetic; } });
30
+ var isAlphaNumeric_1 = require("./isAlphaNumeric");
31
+ Object.defineProperty(exports, "isAlphaNumeric", { enumerable: true, get: function () { return isAlphaNumeric_1.isAlphaNumeric; } });
32
+ var isAnagram_1 = require("./isAnagram");
33
+ Object.defineProperty(exports, "isAnagram", { enumerable: true, get: function () { return isAnagram_1.isAnagram; } });
34
+ var isPanagram_1 = require("./isPanagram");
35
+ Object.defineProperty(exports, "isPanagram", { enumerable: true, get: function () { return isPanagram_1.isPanagram; } });
36
+ var isMacAddress_1 = require("./isMacAddress");
37
+ Object.defineProperty(exports, "isMacAddress", { enumerable: true, get: function () { return isMacAddress_1.isMacAddress; } });
22
38
  const isCoordinates_2 = require("./isCoordinates");
23
39
  const isDate_2 = require("./isDate");
24
40
  const isEmail_2 = require("./isEmail");
@@ -26,8 +42,16 @@ const isEmpty_2 = require("./isEmpty");
26
42
  const isSlug_2 = require("./isSlug");
27
43
  const isURL_2 = require("./isURL");
28
44
  const isIPv4_2 = require("./isIPv4");
45
+ const isIPv6_2 = require("./isIPv6");
29
46
  const isHexColor_2 = require("./isHexColor");
30
47
  const isPalindrome_2 = require("./isPalindrome");
48
+ const isLowerCase_2 = require("./isLowerCase");
49
+ const isUpperCase_2 = require("./isUpperCase");
50
+ const isAlphabetic_2 = require("./isAlphabetic");
51
+ const isAlphaNumeric_2 = require("./isAlphaNumeric");
52
+ const isAnagram_2 = require("./isAnagram");
53
+ const isPanagram_2 = require("./isPanagram");
54
+ const isMacAddress_2 = require("./isMacAddress");
31
55
  exports.validations = {
32
56
  isCoordinates: isCoordinates_2.isCoordinates,
33
57
  isDate: isDate_2.isDate,
@@ -36,6 +60,14 @@ exports.validations = {
36
60
  isSlug: isSlug_2.isSlug,
37
61
  isURL: isURL_2.isURL,
38
62
  isIPv4: isIPv4_2.isIPv4,
63
+ isIPv6: isIPv6_2.isIPv6,
39
64
  isHexColor: isHexColor_2.isHexColor,
40
- isPalindrome: isPalindrome_2.isPalindrome
65
+ isPalindrome: isPalindrome_2.isPalindrome,
66
+ isLowerCase: isLowerCase_2.isLowerCase,
67
+ isUpperCase: isUpperCase_2.isUpperCase,
68
+ isAlphabetic: isAlphabetic_2.isAlphabetic,
69
+ isAlphaNumeric: isAlphaNumeric_2.isAlphaNumeric,
70
+ isAnagram: isAnagram_2.isAnagram,
71
+ isPanagram: isPanagram_2.isPanagram,
72
+ isMacAddress: isMacAddress_2.isMacAddress
41
73
  };
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Checks whether the given string is alphanumeric.
3
+ *
4
+ * The check ensures that the string contains only
5
+ * letters (a-z, A-Z) and digits (0-9).
6
+ *
7
+ * @param {string} str - The input string to check.
8
+ * @returns {boolean} True if the input is alphanumeric, false otherwise.
9
+ * @throws {TypeError} If the input is not a string.
10
+ */
11
+ export declare function isAlphaNumeric(str: string): boolean;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isAlphaNumeric = isAlphaNumeric;
4
+ /**
5
+ * Checks whether the given string is alphanumeric.
6
+ *
7
+ * The check ensures that the string contains only
8
+ * letters (a-z, A-Z) and digits (0-9).
9
+ *
10
+ * @param {string} str - The input string to check.
11
+ * @returns {boolean} True if the input is alphanumeric, false otherwise.
12
+ * @throws {TypeError} If the input is not a string.
13
+ */
14
+ function isAlphaNumeric(str) {
15
+ if (typeof str !== 'string') {
16
+ throw new TypeError('Input must be a string');
17
+ }
18
+ if (str.length === 0) {
19
+ return false;
20
+ }
21
+ return /^[a-z0-9]+$/i.test(str);
22
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Checks whether a given string contains only alphabetic characters (A-Z, a-z).
3
+ *
4
+ *
5
+ * @param {string} str - The input string to check.
6
+ * @returns {boolean} True if the input contains only alphabetic characters, otherwise false.
7
+ * @throws {TypeError} If the input is not a string.
8
+ */
9
+ export declare function isAlphabetic(str: string): boolean;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isAlphabetic = isAlphabetic;
4
+ /**
5
+ * Checks whether a given string contains only alphabetic characters (A-Z, a-z).
6
+ *
7
+ *
8
+ * @param {string} str - The input string to check.
9
+ * @returns {boolean} True if the input contains only alphabetic characters, otherwise false.
10
+ * @throws {TypeError} If the input is not a string.
11
+ */
12
+ function isAlphabetic(str) {
13
+ if (typeof str !== 'string') {
14
+ throw new TypeError('Input must be a string');
15
+ }
16
+ // empty string is not considered alphabetic
17
+ if (str === '')
18
+ return false;
19
+ // Regular expression to match only alphabetic characters
20
+ return /^[A-Za-z]+$/.test(str);
21
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Checks whether two strings are anagrams of each other.
3
+ *
4
+ * Rules:
5
+ * - Comparison is case-insensitive.
6
+ * - Spaces and punctuation are ignored.
7
+ *
8
+ * @param {string} str1 - The first input string.
9
+ * @param {string} str2 - The second input string.
10
+ * @returns {boolean} True if the inputs are anagrams, otherwise false.
11
+ * @throws {TypeError} If either input is not a string.
12
+ */
13
+ export declare function isAnagram(str1: string, str2: string): boolean;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isAnagram = isAnagram;
4
+ /**
5
+ * Checks whether two strings are anagrams of each other.
6
+ *
7
+ * Rules:
8
+ * - Comparison is case-insensitive.
9
+ * - Spaces and punctuation are ignored.
10
+ *
11
+ * @param {string} str1 - The first input string.
12
+ * @param {string} str2 - The second input string.
13
+ * @returns {boolean} True if the inputs are anagrams, otherwise false.
14
+ * @throws {TypeError} If either input is not a string.
15
+ */
16
+ function isAnagram(str1, str2) {
17
+ if (typeof str1 !== 'string' || typeof str2 !== 'string') {
18
+ throw new TypeError('Both inputs must be strings');
19
+ }
20
+ // Normalize: lowercase, remove spaces & punctuation
21
+ const normalize = (str) => str.toLowerCase().replace(/[^a-z0-9]/g, '').split('').sort().join('');
22
+ return normalize(str1) === normalize(str2);
23
+ }