stringzy 2.2.0 → 3.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 (151) hide show
  1. package/.github/workflows/publish.yml +29 -0
  2. package/.github/workflows/test-on-pr.yml +23 -0
  3. package/CONTRIBUTING.md +87 -0
  4. package/LICENSE +21 -21
  5. package/README.md +952 -723
  6. package/changelog.txt +110 -102
  7. package/dist/analyzing/characterCount.d.ts +1 -0
  8. package/dist/analyzing/characterCount.js +9 -0
  9. package/dist/analyzing/characterFrequency.d.ts +1 -0
  10. package/dist/analyzing/characterFrequency.js +16 -0
  11. package/dist/analyzing/complexity.d.ts +6 -0
  12. package/dist/analyzing/complexity.js +30 -0
  13. package/dist/analyzing/index.d.ts +20 -0
  14. package/dist/analyzing/index.js +29 -0
  15. package/dist/analyzing/readingDuration.d.ts +10 -0
  16. package/dist/analyzing/readingDuration.js +17 -0
  17. package/dist/analyzing/stringSimilarity.d.ts +8 -0
  18. package/dist/analyzing/stringSimilarity.js +145 -0
  19. package/dist/analyzing/wordCount.d.ts +1 -0
  20. package/dist/analyzing/wordCount.js +11 -0
  21. package/dist/formatting/capitalize.d.ts +1 -0
  22. package/dist/formatting/capitalize.js +12 -0
  23. package/dist/formatting/index.d.ts +11 -0
  24. package/dist/formatting/index.js +17 -0
  25. package/dist/formatting/number.d.ts +1 -0
  26. package/dist/formatting/number.js +7 -0
  27. package/dist/formatting/phone.d.ts +2 -0
  28. package/dist/formatting/phone.js +25 -0
  29. package/dist/index.d.ts +47 -0
  30. package/dist/index.js +30 -0
  31. package/dist/tests/analyzing/characterCount.test.d.ts +1 -0
  32. package/dist/tests/analyzing/characterCount.test.js +19 -0
  33. package/dist/tests/analyzing/characterFrequency.test.d.ts +1 -0
  34. package/dist/tests/analyzing/characterFrequency.test.js +22 -0
  35. package/dist/tests/analyzing/complexity.test.d.ts +1 -0
  36. package/dist/tests/analyzing/complexity.test.js +28 -0
  37. package/dist/tests/analyzing/readingDuration.test.d.ts +1 -0
  38. package/dist/tests/analyzing/readingDuration.test.js +45 -0
  39. package/dist/tests/analyzing/stringSimilarity.test.d.ts +1 -0
  40. package/dist/tests/analyzing/stringSimilarity.test.js +61 -0
  41. package/dist/tests/analyzing/wordCount.test.d.ts +1 -0
  42. package/dist/tests/analyzing/wordCount.test.js +22 -0
  43. package/dist/tests/formatting/capitalize.test.d.ts +1 -0
  44. package/dist/tests/formatting/capitalize.test.js +22 -0
  45. package/dist/tests/formatting/number.test.d.ts +1 -0
  46. package/dist/tests/formatting/number.test.js +19 -0
  47. package/dist/tests/formatting/phone.test.d.ts +1 -0
  48. package/dist/tests/formatting/phone.test.js +25 -0
  49. package/dist/tests/transformations/camelCase.test.d.ts +1 -0
  50. package/dist/tests/transformations/camelCase.test.js +19 -0
  51. package/dist/tests/transformations/capitalizeWords.test.d.ts +1 -0
  52. package/dist/tests/transformations/capitalizeWords.test.js +19 -0
  53. package/dist/tests/transformations/constantCase.test.d.ts +1 -0
  54. package/dist/tests/transformations/constantCase.test.js +19 -0
  55. package/dist/tests/transformations/deburr.test.d.ts +1 -0
  56. package/dist/tests/transformations/deburr.test.js +27 -0
  57. package/dist/tests/transformations/escapeHTML.test.d.ts +1 -0
  58. package/dist/tests/transformations/escapeHTML.test.js +46 -0
  59. package/dist/tests/transformations/initials.test.d.ts +1 -0
  60. package/dist/tests/transformations/initials.test.js +25 -0
  61. package/dist/tests/transformations/kebabCase.test.d.ts +1 -0
  62. package/dist/tests/transformations/kebabCase.test.js +19 -0
  63. package/dist/tests/transformations/maskSegment.test.d.ts +1 -0
  64. package/dist/tests/transformations/maskSegment.test.js +30 -0
  65. package/dist/tests/transformations/pascalCase.test.d.ts +1 -0
  66. package/dist/tests/transformations/pascalCase.test.js +19 -0
  67. package/dist/tests/transformations/removeDuplicates.test.d.ts +1 -0
  68. package/dist/tests/transformations/removeDuplicates.test.js +19 -0
  69. package/dist/tests/transformations/removeSpecialChars.test.d.ts +1 -0
  70. package/dist/tests/transformations/removeSpecialChars.test.js +22 -0
  71. package/dist/tests/transformations/removeWords.test.d.ts +1 -0
  72. package/dist/tests/transformations/removeWords.test.js +25 -0
  73. package/dist/tests/transformations/snakeCase.test.d.ts +1 -0
  74. package/dist/tests/transformations/snakeCase.test.js +19 -0
  75. package/dist/tests/transformations/titleCase.test.d.ts +1 -0
  76. package/dist/tests/transformations/titleCase.test.js +19 -0
  77. package/dist/tests/transformations/toSlug.test.d.ts +1 -0
  78. package/dist/tests/transformations/toSlug.test.js +22 -0
  79. package/dist/tests/transformations/truncateText.test.d.ts +1 -0
  80. package/dist/tests/transformations/truncateText.test.js +31 -0
  81. package/dist/tests/validations/isDate.test.d.ts +1 -0
  82. package/dist/tests/validations/isDate.test.js +55 -0
  83. package/dist/tests/validations/isEmail.test.d.ts +1 -0
  84. package/dist/tests/validations/isEmail.test.js +17 -0
  85. package/dist/tests/validations/isEmpty.test.d.ts +1 -0
  86. package/dist/tests/validations/isEmpty.test.js +19 -0
  87. package/dist/tests/validations/isHexColor.test.d.ts +1 -0
  88. package/dist/tests/validations/isHexColor.test.js +32 -0
  89. package/dist/tests/validations/isIPv4.test.d.ts +1 -0
  90. package/dist/tests/validations/isIPv4.test.js +59 -0
  91. package/dist/tests/validations/isSlug.test.d.ts +1 -0
  92. package/dist/tests/validations/isSlug.test.js +22 -0
  93. package/dist/tests/validations/isURL.test.d.ts +1 -0
  94. package/dist/tests/validations/isURL.test.js +18 -0
  95. package/dist/transformations/camelCase.d.ts +1 -0
  96. package/dist/transformations/camelCase.js +15 -0
  97. package/dist/transformations/capitalizeWords.d.ts +1 -0
  98. package/dist/transformations/capitalizeWords.js +9 -0
  99. package/dist/transformations/constantCase.d.ts +1 -0
  100. package/dist/transformations/constantCase.js +15 -0
  101. package/dist/transformations/deburr.d.ts +7 -0
  102. package/dist/transformations/deburr.js +16 -0
  103. package/dist/transformations/escapeHTML.d.ts +1 -0
  104. package/dist/transformations/escapeHTML.js +14 -0
  105. package/dist/transformations/index.d.ts +49 -0
  106. package/dist/transformations/index.js +67 -0
  107. package/dist/transformations/initials.d.ts +1 -0
  108. package/dist/transformations/initials.js +19 -0
  109. package/dist/transformations/kebabCase.d.ts +1 -0
  110. package/dist/transformations/kebabCase.js +15 -0
  111. package/dist/transformations/maskSegment.d.ts +9 -0
  112. package/dist/transformations/maskSegment.js +25 -0
  113. package/dist/transformations/pascalCase.d.ts +1 -0
  114. package/dist/transformations/pascalCase.js +15 -0
  115. package/dist/transformations/removeDuplicates.d.ts +1 -0
  116. package/dist/transformations/removeDuplicates.js +13 -0
  117. package/dist/transformations/removeSpecialChars.d.ts +1 -0
  118. package/dist/transformations/removeSpecialChars.js +12 -0
  119. package/dist/transformations/removeWords.d.ts +1 -0
  120. package/dist/transformations/removeWords.js +23 -0
  121. package/dist/transformations/snakeCase.d.ts +1 -0
  122. package/dist/transformations/snakeCase.js +15 -0
  123. package/dist/transformations/titleCase.d.ts +1 -0
  124. package/dist/transformations/titleCase.js +14 -0
  125. package/dist/transformations/toSlug.d.ts +1 -0
  126. package/dist/transformations/toSlug.js +13 -0
  127. package/dist/transformations/truncateText.d.ts +1 -0
  128. package/dist/transformations/truncateText.js +19 -0
  129. package/dist/validations/index.d.ts +23 -0
  130. package/dist/validations/index.js +33 -0
  131. package/dist/validations/isDate.d.ts +18 -0
  132. package/dist/validations/isDate.js +63 -0
  133. package/dist/validations/isEmail.d.ts +1 -0
  134. package/dist/validations/isEmail.js +7 -0
  135. package/dist/validations/isEmpty.d.ts +1 -0
  136. package/dist/validations/isEmpty.js +6 -0
  137. package/dist/validations/isHexColor.d.ts +7 -0
  138. package/dist/validations/isHexColor.js +15 -0
  139. package/dist/validations/isIPv4.d.ts +1 -0
  140. package/dist/validations/isIPv4.js +13 -0
  141. package/dist/validations/isSlug.d.ts +1 -0
  142. package/dist/validations/isSlug.js +10 -0
  143. package/dist/validations/isURL.d.ts +1 -0
  144. package/dist/validations/isURL.js +12 -0
  145. package/package.json +10 -4
  146. package/analysis.js +0 -21
  147. package/assets/stringzy-banner2.jpg +0 -0
  148. package/formatting.js +0 -37
  149. package/index.js +0 -75
  150. package/transformations.js +0 -190
  151. package/validations.js +0 -80
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.transformations = 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
+ var camelCase_1 = require("./camelCase");
5
+ Object.defineProperty(exports, "camelCase", { enumerable: true, get: function () { return camelCase_1.camelCase; } });
6
+ var capitalizeWords_1 = require("./capitalizeWords");
7
+ Object.defineProperty(exports, "capitalizeWords", { enumerable: true, get: function () { return capitalizeWords_1.capitalizeWords; } });
8
+ var constantCase_1 = require("./constantCase");
9
+ Object.defineProperty(exports, "constantCase", { enumerable: true, get: function () { return constantCase_1.constantCase; } });
10
+ var initials_1 = require("./initials");
11
+ Object.defineProperty(exports, "initials", { enumerable: true, get: function () { return initials_1.initials; } });
12
+ var kebabCase_1 = require("./kebabCase");
13
+ Object.defineProperty(exports, "kebabCase", { enumerable: true, get: function () { return kebabCase_1.kebabCase; } });
14
+ var pascalCase_1 = require("./pascalCase");
15
+ Object.defineProperty(exports, "pascalCase", { enumerable: true, get: function () { return pascalCase_1.pascalCase; } });
16
+ var removeDuplicates_1 = require("./removeDuplicates");
17
+ Object.defineProperty(exports, "removeDuplicates", { enumerable: true, get: function () { return removeDuplicates_1.removeDuplicates; } });
18
+ var removeSpecialChars_1 = require("./removeSpecialChars");
19
+ Object.defineProperty(exports, "removeSpecialChars", { enumerable: true, get: function () { return removeSpecialChars_1.removeSpecialChars; } });
20
+ var removeWords_1 = require("./removeWords");
21
+ Object.defineProperty(exports, "removeWords", { enumerable: true, get: function () { return removeWords_1.removeWords; } });
22
+ var snakeCase_1 = require("./snakeCase");
23
+ Object.defineProperty(exports, "snakeCase", { enumerable: true, get: function () { return snakeCase_1.snakeCase; } });
24
+ var titleCase_1 = require("./titleCase");
25
+ Object.defineProperty(exports, "titleCase", { enumerable: true, get: function () { return titleCase_1.titleCase; } });
26
+ var toSlug_1 = require("./toSlug");
27
+ Object.defineProperty(exports, "toSlug", { enumerable: true, get: function () { return toSlug_1.toSlug; } });
28
+ var truncateText_1 = require("./truncateText");
29
+ Object.defineProperty(exports, "truncateText", { enumerable: true, get: function () { return truncateText_1.truncateText; } });
30
+ var escapeHTML_1 = require("./escapeHTML");
31
+ Object.defineProperty(exports, "escapeHtml", { enumerable: true, get: function () { return escapeHTML_1.escapeHtml; } });
32
+ var maskSegment_1 = require("./maskSegment");
33
+ Object.defineProperty(exports, "maskSegment", { enumerable: true, get: function () { return maskSegment_1.maskSegment; } });
34
+ const camelCase_2 = require("./camelCase");
35
+ const capitalizeWords_2 = require("./capitalizeWords");
36
+ const constantCase_2 = require("./constantCase");
37
+ const initials_2 = require("./initials");
38
+ const kebabCase_2 = require("./kebabCase");
39
+ const pascalCase_2 = require("./pascalCase");
40
+ const removeDuplicates_2 = require("./removeDuplicates");
41
+ const removeSpecialChars_2 = require("./removeSpecialChars");
42
+ const removeWords_2 = require("./removeWords");
43
+ const snakeCase_2 = require("./snakeCase");
44
+ const titleCase_2 = require("./titleCase");
45
+ const toSlug_2 = require("./toSlug");
46
+ const truncateText_2 = require("./truncateText");
47
+ const escapeHTML_2 = require("./escapeHTML");
48
+ const maskSegment_2 = require("./maskSegment");
49
+ const deburr_1 = require("./deburr");
50
+ exports.transformations = {
51
+ camelCase: camelCase_2.camelCase,
52
+ capitalizeWords: capitalizeWords_2.capitalizeWords,
53
+ constantCase: constantCase_2.constantCase,
54
+ initials: initials_2.initials,
55
+ kebabCase: kebabCase_2.kebabCase,
56
+ pascalCase: pascalCase_2.pascalCase,
57
+ removeDuplicates: removeDuplicates_2.removeDuplicates,
58
+ removeSpecialChars: removeSpecialChars_2.removeSpecialChars,
59
+ removeWords: removeWords_2.removeWords,
60
+ snakeCase: snakeCase_2.snakeCase,
61
+ titleCase: titleCase_2.titleCase,
62
+ toSlug: toSlug_2.toSlug,
63
+ truncateText: truncateText_2.truncateText,
64
+ escapeHtml: escapeHTML_2.escapeHtml,
65
+ maskSegment: maskSegment_2.maskSegment,
66
+ deburr: deburr_1.deburr
67
+ };
@@ -0,0 +1 @@
1
+ export declare function initials(text: string, limit?: number): string;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.initials = initials;
4
+ function initials(text, limit) {
5
+ if (typeof text !== "string") {
6
+ throw new Error("Input must be a string");
7
+ }
8
+ if (limit !== undefined && (typeof limit !== "number" || isNaN(limit))) {
9
+ throw new Error("Limit must be a valid number");
10
+ }
11
+ if (limit !== undefined && limit < 0) {
12
+ throw new Error("Limit must be a non-negative number");
13
+ }
14
+ const words = text.trim().split(/\s+/).filter((word) => word.length > 0);
15
+ if (words.length === 0)
16
+ return "";
17
+ const initialsArray = words.map((word) => word.charAt(0)).slice(0, limit !== null && limit !== void 0 ? limit : words.length);
18
+ return initialsArray.join("");
19
+ }
@@ -0,0 +1 @@
1
+ export declare function kebabCase(text: string): string;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.kebabCase = kebabCase;
4
+ function kebabCase(text) {
5
+ if (text == null)
6
+ return '';
7
+ return text
8
+ .trim()
9
+ .replace(/[\s_]+/g, '-')
10
+ .replace(/([a-z])([A-Z])/g, '$1-$2')
11
+ .replace(/[^\w-]/g, '-')
12
+ .toLowerCase()
13
+ .replace(/-+/g, '-')
14
+ .replace(/^-+|-+$/g, '');
15
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Hides a segment of a string by replacing it with a specified character.
3
+ * @param text The input string.
4
+ * @param maskStart The start index of the segment to mask (inclusive). Defaults to 0.
5
+ * @param maskEnd The end index of the segment to mask (exclusive). Defaults to text.length.
6
+ * @param maskChar The character to use for masking. Defaults to '*'.
7
+ * @returns The string with the specified segment masked.
8
+ */
9
+ export declare function maskSegment(text: string, maskStart?: number, maskEnd?: number, maskChar?: string): string;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ /**
3
+ * Hides a segment of a string by replacing it with a specified character.
4
+ * @param text The input string.
5
+ * @param maskStart The start index of the segment to mask (inclusive). Defaults to 0.
6
+ * @param maskEnd The end index of the segment to mask (exclusive). Defaults to text.length.
7
+ * @param maskChar The character to use for masking. Defaults to '*'.
8
+ * @returns The string with the specified segment masked.
9
+ */
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.maskSegment = maskSegment;
12
+ function maskSegment(text, maskStart = 0, maskEnd = text.length, maskChar = "*") {
13
+ if (maskStart < 0 || maskEnd > text.length || maskStart >= maskEnd) {
14
+ throw new Error("Invalid mask segment range");
15
+ }
16
+ if (maskChar.length !== 1) {
17
+ throw new Error("Mask character must be a single character");
18
+ }
19
+ if (maskStart === 0 && maskEnd === text.length) {
20
+ return maskChar.repeat(text.length);
21
+ }
22
+ return (text.slice(0, maskStart) +
23
+ maskChar.repeat(maskEnd - maskStart) +
24
+ text.slice(maskEnd));
25
+ }
@@ -0,0 +1 @@
1
+ export declare function pascalCase(text: string): string;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.pascalCase = pascalCase;
4
+ function pascalCase(text) {
5
+ if (text == null)
6
+ return '';
7
+ return text
8
+ .trim()
9
+ .toLowerCase()
10
+ .replace(/[^\w\s]/g, ' ')
11
+ .replace(/_/g, ' ')
12
+ .replace(/\s+/g, ' ')
13
+ .replace(/(^|\s)(.)/g, (_, prefix, character) => character.toUpperCase())
14
+ .replace(/\s/g, '');
15
+ }
@@ -0,0 +1 @@
1
+ export declare function removeDuplicates(text: string): string;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.removeDuplicates = removeDuplicates;
4
+ function removeDuplicates(text) {
5
+ if (typeof text !== "string") {
6
+ throw new Error("Input must be a string");
7
+ }
8
+ const wordSet = new Set();
9
+ text.split(" ").forEach((word) => {
10
+ wordSet.add(word);
11
+ });
12
+ return Array.from(wordSet).join(" ");
13
+ }
@@ -0,0 +1 @@
1
+ export declare function removeSpecialChars(text: string, replacement?: string): string;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.removeSpecialChars = removeSpecialChars;
4
+ function removeSpecialChars(text, replacement = '') {
5
+ if (typeof text !== "string") {
6
+ throw new Error("Invalid argument. Expected a string.");
7
+ }
8
+ if (typeof replacement !== "string") {
9
+ throw new Error("Replacement must be a string.");
10
+ }
11
+ return text.replace(/[^\w\s]/gi, replacement);
12
+ }
@@ -0,0 +1 @@
1
+ export declare function removeWords(str: string, wordsToRemove: string | string[]): string;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.removeWords = removeWords;
4
+ function removeWords(str, wordsToRemove) {
5
+ if (str === null || str === undefined) {
6
+ throw new Error('Input string cannot be null or undefined');
7
+ }
8
+ if (typeof str !== 'string') {
9
+ throw new Error('First parameter must be a string');
10
+ }
11
+ if (wordsToRemove === null || wordsToRemove === undefined) {
12
+ throw new Error('Words to remove cannot be null or undefined');
13
+ }
14
+ if (typeof wordsToRemove !== 'string' && !Array.isArray(wordsToRemove)) {
15
+ throw new Error('Second parameter must be a string or an array of strings');
16
+ }
17
+ if (str === '') {
18
+ return '';
19
+ }
20
+ const wordsArray = Array.isArray(wordsToRemove) ? wordsToRemove : [wordsToRemove];
21
+ const regex = new RegExp(`\\b(${wordsArray.join('|')})\\b`, 'gi');
22
+ return str.replace(regex, '').replace(/\s+/g, ' ').trim();
23
+ }
@@ -0,0 +1 @@
1
+ export declare function snakeCase(text: string): string;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.snakeCase = snakeCase;
4
+ function snakeCase(text) {
5
+ if (text == null)
6
+ return '';
7
+ return text
8
+ .trim()
9
+ .replace(/[\s-]+/g, '_')
10
+ .replace(/([a-z])([A-Z])/g, '$1_$2')
11
+ .replace(/[^\w_]/g, '_')
12
+ .toLowerCase()
13
+ .replace(/_+/g, '_')
14
+ .replace(/^_+|_+$/g, '');
15
+ }
@@ -0,0 +1 @@
1
+ export declare function titleCase(text: string): string;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.titleCase = titleCase;
4
+ function titleCase(text) {
5
+ if (text == null)
6
+ return '';
7
+ return text
8
+ .trim()
9
+ .toLowerCase()
10
+ .replace(/([^\w\s]|_)/g, ' ')
11
+ .replace(/\s+/g, ' ')
12
+ .replace(/(^|\s)(.)/g, (_, prefix, character) => prefix + character.toUpperCase())
13
+ .replace(/\s/g, ' ');
14
+ }
@@ -0,0 +1 @@
1
+ export declare function toSlug(text: string): string;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toSlug = toSlug;
4
+ function toSlug(text) {
5
+ if (typeof text !== "string") {
6
+ throw new Error("Invalid argument. Expected a string.");
7
+ }
8
+ return text
9
+ .toLowerCase()
10
+ .trim()
11
+ .replace(/[\s]+/g, "-")
12
+ .replace(/[^\w-]+/g, "");
13
+ }
@@ -0,0 +1 @@
1
+ export declare function truncateText(text: string, maxLength: number, suffix?: string): string;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.truncateText = truncateText;
4
+ function truncateText(text, maxLength, suffix = '...') {
5
+ if (typeof text !== 'string') {
6
+ throw new Error("Input text must be a string.");
7
+ }
8
+ if (typeof maxLength !== 'number' || maxLength < 0) {
9
+ throw new Error("maxLength must be a non-negative number.");
10
+ }
11
+ if (typeof suffix !== 'string') {
12
+ throw new Error("Suffix must be a string.");
13
+ }
14
+ if (text.length <= maxLength) {
15
+ return text;
16
+ }
17
+ const adjustedLength = maxLength - suffix.length;
18
+ return text.slice(0, adjustedLength > 0 ? adjustedLength : 0) + suffix;
19
+ }
@@ -0,0 +1,23 @@
1
+ export { isDate } from './isDate';
2
+ export { isEmail } from './isEmail';
3
+ export { isEmpty } from './isEmpty';
4
+ export { isSlug } from './isSlug';
5
+ export { isURL } from './isURL';
6
+ export { isIPv4 } from './isIPv4';
7
+ export { isHexColor } from './isHexColor';
8
+ import { isDate } from './isDate';
9
+ import { isEmail } from './isEmail';
10
+ import { isEmpty } from './isEmpty';
11
+ import { isSlug } from './isSlug';
12
+ import { isURL } from './isURL';
13
+ import { isIPv4 } from './isIPv4';
14
+ import { isHexColor } from './isHexColor';
15
+ export declare const validations: {
16
+ isDate: typeof isDate;
17
+ isEmail: typeof isEmail;
18
+ isEmpty: typeof isEmpty;
19
+ isSlug: typeof isSlug;
20
+ isURL: typeof isURL;
21
+ isIPv4: typeof isIPv4;
22
+ isHexColor: typeof isHexColor;
23
+ };
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validations = exports.isHexColor = exports.isIPv4 = exports.isURL = exports.isSlug = exports.isEmpty = exports.isEmail = exports.isDate = void 0;
4
+ var isDate_1 = require("./isDate");
5
+ Object.defineProperty(exports, "isDate", { enumerable: true, get: function () { return isDate_1.isDate; } });
6
+ var isEmail_1 = require("./isEmail");
7
+ Object.defineProperty(exports, "isEmail", { enumerable: true, get: function () { return isEmail_1.isEmail; } });
8
+ var isEmpty_1 = require("./isEmpty");
9
+ Object.defineProperty(exports, "isEmpty", { enumerable: true, get: function () { return isEmpty_1.isEmpty; } });
10
+ var isSlug_1 = require("./isSlug");
11
+ Object.defineProperty(exports, "isSlug", { enumerable: true, get: function () { return isSlug_1.isSlug; } });
12
+ var isURL_1 = require("./isURL");
13
+ Object.defineProperty(exports, "isURL", { enumerable: true, get: function () { return isURL_1.isURL; } });
14
+ var isIPv4_1 = require("./isIPv4");
15
+ Object.defineProperty(exports, "isIPv4", { enumerable: true, get: function () { return isIPv4_1.isIPv4; } });
16
+ var isHexColor_1 = require("./isHexColor");
17
+ Object.defineProperty(exports, "isHexColor", { enumerable: true, get: function () { return isHexColor_1.isHexColor; } });
18
+ const isDate_2 = require("./isDate");
19
+ const isEmail_2 = require("./isEmail");
20
+ const isEmpty_2 = require("./isEmpty");
21
+ const isSlug_2 = require("./isSlug");
22
+ const isURL_2 = require("./isURL");
23
+ const isIPv4_2 = require("./isIPv4");
24
+ const isHexColor_2 = require("./isHexColor");
25
+ exports.validations = {
26
+ isDate: isDate_2.isDate,
27
+ isEmail: isEmail_2.isEmail,
28
+ isEmpty: isEmpty_2.isEmpty,
29
+ isSlug: isSlug_2.isSlug,
30
+ isURL: isURL_2.isURL,
31
+ isIPv4: isIPv4_2.isIPv4,
32
+ isHexColor: isHexColor_2.isHexColor
33
+ };
@@ -0,0 +1,18 @@
1
+ export declare enum DateFormats {
2
+ YYYYMMDD = "YYYYMMDD",
3
+ MMDDYYYY = "MMDDYYYY",
4
+ DDMMYYYY = "DDMMYYYY"
5
+ }
6
+ declare const VALID_SEPARATORS: readonly [".", "-", "/"];
7
+ type ValidSeparators = typeof VALID_SEPARATORS[number];
8
+ /**
9
+ * Takes a date and a format and returns whether or not the date matches the specified format.
10
+ * Optionally takes a separator that can be used instead of the default hyphen.
11
+ *
12
+ * Only accepts 2 digit month/day and 4 digit year
13
+ * @example 01-01-2000 -> True
14
+ * @example 01-1-2000 -> False
15
+ * @example 01-01-00 -> False
16
+ */
17
+ export declare function isDate(input: string, format: DateFormats, separator?: ValidSeparators): boolean;
18
+ export {};
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DateFormats = void 0;
4
+ exports.isDate = isDate;
5
+ var DateFormats;
6
+ (function (DateFormats) {
7
+ DateFormats["YYYYMMDD"] = "YYYYMMDD";
8
+ DateFormats["MMDDYYYY"] = "MMDDYYYY";
9
+ DateFormats["DDMMYYYY"] = "DDMMYYYY";
10
+ })(DateFormats || (exports.DateFormats = DateFormats = {}));
11
+ const VALID_SEPARATORS = ['.', '-', '/'];
12
+ /**
13
+ * Takes a date and a format and returns whether or not the date matches the specified format.
14
+ * Optionally takes a separator that can be used instead of the default hyphen.
15
+ *
16
+ * Only accepts 2 digit month/day and 4 digit year
17
+ * @example 01-01-2000 -> True
18
+ * @example 01-1-2000 -> False
19
+ * @example 01-01-00 -> False
20
+ */
21
+ function isDate(input, format, separator = '-') {
22
+ if (typeof input !== "string")
23
+ return false;
24
+ if (input.length !== 10)
25
+ return false;
26
+ // Ensure separator is supported
27
+ if (![...VALID_SEPARATORS].includes(separator))
28
+ return false;
29
+ const formats = [
30
+ {
31
+ // Format: YYYY-MM-DD
32
+ format: DateFormats.YYYYMMDD,
33
+ regex: new RegExp(`^\\d{4}${separator}\\d{2}${separator}\\d{2}$`),
34
+ order: ["Y", "M", "D"],
35
+ },
36
+ {
37
+ // Format: MM-DD-YYYY
38
+ format: DateFormats.MMDDYYYY,
39
+ regex: new RegExp(`^\d{2}${separator}\d{2}${separator}\d{4}$/`),
40
+ order: ["M", "D", "Y"],
41
+ },
42
+ {
43
+ // Format: DD-MM-YYYY
44
+ format: DateFormats.DDMMYYYY,
45
+ regex: new RegExp(`^\d{2}${separator}\d{2}${separator}\d{4}$`),
46
+ order: ["D", "M", "Y"],
47
+ },
48
+ ];
49
+ const targetFormat = formats.find(f => f.format === format);
50
+ const parts = input.split(separator).map(Number);
51
+ const dateParts = {};
52
+ targetFormat === null || targetFormat === void 0 ? void 0 : targetFormat.order.forEach((k, i) => {
53
+ dateParts[k] = parts[i];
54
+ });
55
+ const { Y, M, D } = dateParts;
56
+ const checkDate = new Date(Y, M - 1, D); // Months are 0 indexed
57
+ if (checkDate.toString() === 'Invalid Date')
58
+ return false;
59
+ const isValid = checkDate.getFullYear() === Y &&
60
+ checkDate.getMonth() === M - 1 &&
61
+ checkDate.getDate() === D;
62
+ return isValid;
63
+ }
@@ -0,0 +1 @@
1
+ export declare function isEmail(str: string): boolean;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isEmail = isEmail;
4
+ function isEmail(str) {
5
+ const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
6
+ return emailRegex.test(str);
7
+ }
@@ -0,0 +1 @@
1
+ export declare function isEmpty(str: string): boolean;
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isEmpty = isEmpty;
4
+ function isEmpty(str) {
5
+ return str.trim().length === 0;
6
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Checks if the input string is a valid hex color (e.g., "#fff", "#ffffff", "fff", "ffffff").
3
+ *
4
+ * @param color - The string to validate.
5
+ * @returns True if the string is a valid hex color, false otherwise.
6
+ */
7
+ export declare function isHexColor(text: string): boolean;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isHexColor = isHexColor;
4
+ /**
5
+ * Checks if the input string is a valid hex color (e.g., "#fff", "#ffffff", "fff", "ffffff").
6
+ *
7
+ * @param color - The string to validate.
8
+ * @returns True if the string is a valid hex color, false otherwise.
9
+ */
10
+ function isHexColor(text) {
11
+ if (typeof text !== "string" || text.length === 0) {
12
+ return false;
13
+ }
14
+ return /^#?([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6})$/.test(text.trim());
15
+ }
@@ -0,0 +1 @@
1
+ export declare function isIPv4(str: string): boolean;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isIPv4 = isIPv4;
4
+ function isIPv4(str) {
5
+ const parts = str.split('.');
6
+ if (parts.length !== 4)
7
+ return false;
8
+ return parts.every(part => {
9
+ const num = parseInt(part, 10);
10
+ return !isNaN(num) && num >= 0 && num <= 255 && part === num.toString();
11
+ });
12
+ }
13
+ ;
@@ -0,0 +1 @@
1
+ export declare function isSlug(str: string): boolean;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isSlug = isSlug;
4
+ function isSlug(str) {
5
+ if (typeof str !== 'string' || str.length === 0) {
6
+ return false;
7
+ }
8
+ const slugRegex = /^[a-z0-9]+(-[a-z0-9]+)*$/;
9
+ return slugRegex.test(str);
10
+ }
@@ -0,0 +1 @@
1
+ export declare function isURL(str: string): boolean;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isURL = isURL;
4
+ function isURL(str) {
5
+ try {
6
+ new URL(str);
7
+ return true;
8
+ }
9
+ catch (_a) {
10
+ return false;
11
+ }
12
+ }
package/package.json CHANGED
@@ -1,10 +1,12 @@
1
1
  {
2
2
  "name": "stringzy",
3
- "version": "2.2.0",
4
- "main": "index.js",
5
- "type": "module",
3
+ "version": "3.0.0",
4
+ "main": "dist/index.js",
5
+ "types": "dist/index.d.ts",
6
6
  "scripts": {
7
- "test": "echo \"Error: no test specified\" && exit 1"
7
+ "build": "tsc",
8
+ "test": "npm run build && node --test",
9
+ "prepublishOnly": "npm run build"
8
10
  },
9
11
  "author": "Samarth Ruia",
10
12
  "readmeFilename": "README.md",
@@ -40,5 +42,9 @@
40
42
  "repository": {
41
43
  "type": "git",
42
44
  "url": "git+https://github.com/Samarth2190/stringzy.git"
45
+ },
46
+ "devDependencies": {
47
+ "@types/node": "^24.0.0",
48
+ "typescript": "^5.8.3"
43
49
  }
44
50
  }
package/analysis.js DELETED
@@ -1,21 +0,0 @@
1
-
2
- export function wordCount(str) {
3
- if (!str.trim()) return 0;
4
- return str.trim().split(/\s+/).length;
5
- }
6
-
7
-
8
- export function characterCount(str) {
9
-
10
- return str.length;
11
- }
12
-
13
- export function characterFrequency(str) {
14
- const frequency = {};
15
- for (const char of str.toLowerCase()) {
16
- if (char !== ' ') { // Exclude spaces for cleaner analysis
17
- frequency[char] = (frequency[char] || 0) + 1;
18
- }
19
- }
20
- return frequency;
21
- }
Binary file
package/formatting.js DELETED
@@ -1,37 +0,0 @@
1
-
2
- export function capitalize(str) {
3
- return str
4
- .split(' ')
5
- .map(word => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())
6
- .join(' ');
7
- }
8
-
9
-
10
- export function formatNumber(num, separator = ',') {
11
- const numStr = num.toString();
12
- return numStr.replace(/\B(?=(\d{3})+(?!\d))/g, separator);
13
- }
14
-
15
-
16
- export function formatPhone(phone, format = 'us') {
17
- const digits = phone.replace(/\D/g, '');
18
-
19
- if (format === 'us' && digits.length === 10) {
20
- return `(${digits.slice(0, 3)}) ${digits.slice(3, 6)}-${digits.slice(6)}`;
21
- } else if (format === 'international' && digits.length >= 10) {
22
- const countryCode = digits.slice(0, -10);
23
- const areaCode = digits.slice(-10, -7);
24
- const firstPart = digits.slice(-7, -4);
25
- const lastPart = digits.slice(-4);
26
- return `+${countryCode} (${areaCode}) ${firstPart}-${lastPart}`;
27
- }
28
- else if (format === 'indian') {
29
- if (digits.length === 10) {
30
- return `+91-${digits.slice(0, 5)}-${digits.slice(5)}`;
31
- } else if (digits.length === 12 && digits.startsWith('91')) {
32
- return `+91-${digits.slice(2, 7)}-${digits.slice(7)}`;
33
- }
34
- }
35
-
36
- return phone;
37
- }