stringzy 2.2.1 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (190) hide show
  1. package/.github/workflows/publish.yml +29 -0
  2. package/.github/workflows/test-on-pr.yml +23 -0
  3. package/.prettierignore +4 -0
  4. package/.prettierrc +7 -0
  5. package/CONTRIBUTING.md +99 -0
  6. package/LICENSE +21 -21
  7. package/README.md +1189 -723
  8. package/changelog.txt +110 -110
  9. package/dist/analyzing/characterCount.d.ts +20 -0
  10. package/dist/analyzing/characterCount.js +28 -0
  11. package/dist/analyzing/characterFrequency.d.ts +20 -0
  12. package/dist/analyzing/characterFrequency.js +35 -0
  13. package/dist/analyzing/complexity.d.ts +39 -0
  14. package/dist/analyzing/complexity.js +63 -0
  15. package/dist/analyzing/index.d.ts +26 -0
  16. package/dist/analyzing/index.js +37 -0
  17. package/dist/analyzing/patternCount.d.ts +10 -0
  18. package/dist/analyzing/patternCount.js +52 -0
  19. package/dist/analyzing/readingDuration.d.ts +10 -0
  20. package/dist/analyzing/readingDuration.js +17 -0
  21. package/dist/analyzing/stringSimilarity.d.ts +8 -0
  22. package/dist/analyzing/stringSimilarity.js +145 -0
  23. package/dist/analyzing/vowelConsonantCount.d.ts +22 -0
  24. package/dist/analyzing/vowelConsonantCount.js +38 -0
  25. package/dist/analyzing/wordCount.d.ts +23 -0
  26. package/dist/analyzing/wordCount.js +33 -0
  27. package/dist/formatting/capitalize.d.ts +22 -0
  28. package/dist/formatting/capitalize.js +33 -0
  29. package/dist/formatting/index.d.ts +11 -0
  30. package/dist/formatting/index.js +17 -0
  31. package/dist/formatting/number.d.ts +24 -0
  32. package/dist/formatting/number.js +30 -0
  33. package/dist/formatting/phone.d.ts +25 -0
  34. package/dist/formatting/phone.js +48 -0
  35. package/dist/index.d.ts +52 -0
  36. package/dist/index.js +30 -0
  37. package/dist/tests/analyzing/characterCount.test.d.ts +1 -0
  38. package/dist/tests/analyzing/characterCount.test.js +19 -0
  39. package/dist/tests/analyzing/characterFrequency.test.d.ts +1 -0
  40. package/dist/tests/analyzing/characterFrequency.test.js +22 -0
  41. package/dist/tests/analyzing/complexity.test.d.ts +1 -0
  42. package/dist/tests/analyzing/complexity.test.js +28 -0
  43. package/dist/tests/analyzing/patternCount.test.d.ts +1 -0
  44. package/dist/tests/analyzing/patternCount.test.js +34 -0
  45. package/dist/tests/analyzing/readingDuration.test.d.ts +1 -0
  46. package/dist/tests/analyzing/readingDuration.test.js +45 -0
  47. package/dist/tests/analyzing/stringSimilarity.test.d.ts +1 -0
  48. package/dist/tests/analyzing/stringSimilarity.test.js +61 -0
  49. package/dist/tests/analyzing/vowelConsonantCount.test.d.ts +1 -0
  50. package/dist/tests/analyzing/vowelConsonantCount.test.js +25 -0
  51. package/dist/tests/analyzing/wordCount.test.d.ts +1 -0
  52. package/dist/tests/analyzing/wordCount.test.js +22 -0
  53. package/dist/tests/formatting/capitalize.test.d.ts +1 -0
  54. package/dist/tests/formatting/capitalize.test.js +22 -0
  55. package/dist/tests/formatting/number.test.d.ts +1 -0
  56. package/dist/tests/formatting/number.test.js +19 -0
  57. package/dist/tests/formatting/phone.test.d.ts +1 -0
  58. package/dist/tests/formatting/phone.test.js +25 -0
  59. package/dist/tests/transformations/camelCase.test.d.ts +1 -0
  60. package/dist/tests/transformations/camelCase.test.js +19 -0
  61. package/dist/tests/transformations/capitalizeWords.test.d.ts +1 -0
  62. package/dist/tests/transformations/capitalizeWords.test.js +19 -0
  63. package/dist/tests/transformations/constantCase.test.d.ts +1 -0
  64. package/dist/tests/transformations/constantCase.test.js +19 -0
  65. package/dist/tests/transformations/deburr.test.d.ts +1 -0
  66. package/dist/tests/transformations/deburr.test.js +27 -0
  67. package/dist/tests/transformations/escapeHTML.test.d.ts +1 -0
  68. package/dist/tests/transformations/escapeHTML.test.js +46 -0
  69. package/dist/tests/transformations/initials.test.d.ts +1 -0
  70. package/dist/tests/transformations/initials.test.js +25 -0
  71. package/dist/tests/transformations/kebabCase.test.d.ts +1 -0
  72. package/dist/tests/transformations/kebabCase.test.js +19 -0
  73. package/dist/tests/transformations/maskSegment.test.d.ts +1 -0
  74. package/dist/tests/transformations/maskSegment.test.js +30 -0
  75. package/dist/tests/transformations/numberToText.test.d.ts +1 -0
  76. package/dist/tests/transformations/numberToText.test.js +60 -0
  77. package/dist/tests/transformations/pascalCase.test.d.ts +1 -0
  78. package/dist/tests/transformations/pascalCase.test.js +19 -0
  79. package/dist/tests/transformations/removeDuplicates.test.d.ts +1 -0
  80. package/dist/tests/transformations/removeDuplicates.test.js +19 -0
  81. package/dist/tests/transformations/removeSpecialChars.test.d.ts +1 -0
  82. package/dist/tests/transformations/removeSpecialChars.test.js +22 -0
  83. package/dist/tests/transformations/removeWords.test.d.ts +1 -0
  84. package/dist/tests/transformations/removeWords.test.js +25 -0
  85. package/dist/tests/transformations/snakeCase.test.d.ts +1 -0
  86. package/dist/tests/transformations/snakeCase.test.js +19 -0
  87. package/dist/tests/transformations/splitChunks.test.d.ts +1 -0
  88. package/dist/tests/transformations/splitChunks.test.js +31 -0
  89. package/dist/tests/transformations/titleCase.test.d.ts +1 -0
  90. package/dist/tests/transformations/titleCase.test.js +19 -0
  91. package/dist/tests/transformations/toSlug.test.d.ts +1 -0
  92. package/dist/tests/transformations/toSlug.test.js +22 -0
  93. package/dist/tests/transformations/truncateText.test.d.ts +1 -0
  94. package/dist/tests/transformations/truncateText.test.js +31 -0
  95. package/dist/tests/validations/isCoordinates.test.d.ts +1 -0
  96. package/dist/tests/validations/isCoordinates.test.js +18 -0
  97. package/dist/tests/validations/isDate.test.d.ts +1 -0
  98. package/dist/tests/validations/isDate.test.js +55 -0
  99. package/dist/tests/validations/isEmail.smtpUTF8.test.d.ts +1 -0
  100. package/dist/tests/validations/isEmail.smtpUTF8.test.js +16 -0
  101. package/dist/tests/validations/isEmail.test.d.ts +1 -0
  102. package/dist/tests/validations/isEmail.test.js +67 -0
  103. package/dist/tests/validations/isEmpty.test.d.ts +1 -0
  104. package/dist/tests/validations/isEmpty.test.js +19 -0
  105. package/dist/tests/validations/isHexColor.test.d.ts +1 -0
  106. package/dist/tests/validations/isHexColor.test.js +32 -0
  107. package/dist/tests/validations/isIPv4.test.d.ts +1 -0
  108. package/dist/tests/validations/isIPv4.test.js +59 -0
  109. package/dist/tests/validations/isPalindrome.test.d.ts +1 -0
  110. package/dist/tests/validations/isPalindrome.test.js +39 -0
  111. package/dist/tests/validations/isSlug.test.d.ts +1 -0
  112. package/dist/tests/validations/isSlug.test.js +22 -0
  113. package/dist/tests/validations/isTypeOf.test.d.ts +1 -0
  114. package/dist/tests/validations/isTypeOf.test.js +28 -0
  115. package/dist/tests/validations/isURL.test.d.ts +1 -0
  116. package/dist/tests/validations/isURL.test.js +18 -0
  117. package/dist/transformations/camelCase.d.ts +25 -0
  118. package/dist/transformations/camelCase.js +39 -0
  119. package/dist/transformations/capitalizeWords.d.ts +22 -0
  120. package/dist/transformations/capitalizeWords.js +30 -0
  121. package/dist/transformations/constantCase.d.ts +27 -0
  122. package/dist/transformations/constantCase.js +41 -0
  123. package/dist/transformations/deburr.d.ts +7 -0
  124. package/dist/transformations/deburr.js +16 -0
  125. package/dist/transformations/escapeHTML.d.ts +24 -0
  126. package/dist/transformations/escapeHTML.js +36 -0
  127. package/dist/transformations/index.d.ts +52 -0
  128. package/dist/transformations/index.js +71 -0
  129. package/dist/transformations/initials.d.ts +28 -0
  130. package/dist/transformations/initials.js +49 -0
  131. package/dist/transformations/kebabCase.d.ts +27 -0
  132. package/dist/transformations/kebabCase.js +41 -0
  133. package/dist/transformations/maskSegment.d.ts +9 -0
  134. package/dist/transformations/maskSegment.js +23 -0
  135. package/dist/transformations/numberToText/helpers.d.ts +10 -0
  136. package/dist/transformations/numberToText/helpers.js +31 -0
  137. package/dist/transformations/numberToText/implementation_EN.d.ts +10 -0
  138. package/dist/transformations/numberToText/implementation_EN.js +45 -0
  139. package/dist/transformations/numberToText/implementation_PL.d.ts +10 -0
  140. package/dist/transformations/numberToText/implementation_PL.js +79 -0
  141. package/dist/transformations/numberToText/main.d.ts +19 -0
  142. package/dist/transformations/numberToText/main.js +67 -0
  143. package/dist/transformations/numberToText/types.d.ts +3 -0
  144. package/dist/transformations/numberToText/types.js +82 -0
  145. package/dist/transformations/pascalCase.d.ts +26 -0
  146. package/dist/transformations/pascalCase.js +40 -0
  147. package/dist/transformations/removeDuplicates.d.ts +22 -0
  148. package/dist/transformations/removeDuplicates.js +34 -0
  149. package/dist/transformations/removeSpecialChars.d.ts +23 -0
  150. package/dist/transformations/removeSpecialChars.js +34 -0
  151. package/dist/transformations/removeWords.d.ts +28 -0
  152. package/dist/transformations/removeWords.js +50 -0
  153. package/dist/transformations/snakeCase.d.ts +27 -0
  154. package/dist/transformations/snakeCase.js +41 -0
  155. package/dist/transformations/splitChunks.d.ts +8 -0
  156. package/dist/transformations/splitChunks.js +24 -0
  157. package/dist/transformations/titleCase.d.ts +26 -0
  158. package/dist/transformations/titleCase.js +39 -0
  159. package/dist/transformations/toSlug.d.ts +25 -0
  160. package/dist/transformations/toSlug.js +37 -0
  161. package/dist/transformations/truncateText.d.ts +26 -0
  162. package/dist/transformations/truncateText.js +44 -0
  163. package/dist/validations/index.d.ts +29 -0
  164. package/dist/validations/index.js +41 -0
  165. package/dist/validations/isCoordinates.d.ts +8 -0
  166. package/dist/validations/isCoordinates.js +19 -0
  167. package/dist/validations/isDate.d.ts +18 -0
  168. package/dist/validations/isDate.js +61 -0
  169. package/dist/validations/isEmail.d.ts +13 -0
  170. package/dist/validations/isEmail.js +180 -0
  171. package/dist/validations/isEmpty.d.ts +10 -0
  172. package/dist/validations/isEmpty.js +15 -0
  173. package/dist/validations/isHexColor.d.ts +7 -0
  174. package/dist/validations/isHexColor.js +15 -0
  175. package/dist/validations/isIPv4.d.ts +22 -0
  176. package/dist/validations/isIPv4.js +33 -0
  177. package/dist/validations/isPalindrome.d.ts +10 -0
  178. package/dist/validations/isPalindrome.js +21 -0
  179. package/dist/validations/isSlug.d.ts +28 -0
  180. package/dist/validations/isSlug.js +37 -0
  181. package/dist/validations/isTypeOf.d.ts +9 -0
  182. package/dist/validations/isTypeOf.js +30 -0
  183. package/dist/validations/isURL.d.ts +22 -0
  184. package/dist/validations/isURL.js +33 -0
  185. package/package.json +12 -4
  186. package/analysis.js +0 -21
  187. package/formatting.js +0 -37
  188. package/index.js +0 -75
  189. package/transformations.js +0 -190
  190. package/validations.js +0 -80
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.splitChunks = splitChunks;
4
+ /**
5
+ * Creates chunks of string based on a given chunk size
6
+ * @param text - Input string
7
+ * @param Number - Size of the chunk. Must be a positive integer. Defaults to 1.
8
+ * @returns An array of all the chunks created from the string based on the specified chunk size.
9
+ * @throws Error if input text is not a string or chunk size is not a positive integer.
10
+ */
11
+ function splitChunks(text, chunkSize = 1) {
12
+ if (typeof text !== 'string') {
13
+ throw new Error('Input text must be a string');
14
+ }
15
+ if (typeof chunkSize !== 'number' || !Number.isInteger(chunkSize) || chunkSize < 1) {
16
+ throw new Error('chunkSize must be a natural number (1, 2, 3, ...)');
17
+ }
18
+ const len = text.length;
19
+ const chunks = [];
20
+ for (let i = 0; i < len; i += chunkSize) {
21
+ chunks.push(text.slice(i, i + chunkSize));
22
+ }
23
+ return chunks;
24
+ }
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Converts a string to Title Case, capitalizing the first letter of each word.
3
+ *
4
+ * The conversion process includes:
5
+ * - Trimming whitespace from both ends.
6
+ * - Converting the entire string to lowercase.
7
+ * - Replacing non-word characters and underscores with spaces.
8
+ * - Collapsing multiple spaces into a single space.
9
+ * - Capitalizing the first character of each word.
10
+ * - Preserving spaces between words.
11
+ *
12
+ * If the input is `null` or `undefined`, it returns an empty string.
13
+ *
14
+ * @param {string} text - The input string to convert.
15
+ * @returns {string} The Title Case formatted string.
16
+ *
17
+ * @example
18
+ * titleCase("hello world"); // "Hello World"
19
+ *
20
+ * @example
21
+ * titleCase("convert_to-title.case!"); // "Convert To Title Case"
22
+ *
23
+ * @example
24
+ * titleCase(" multiple spaces here "); // "Multiple Spaces Here"
25
+ */
26
+ export declare function titleCase(text: string): string;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.titleCase = titleCase;
4
+ /**
5
+ * Converts a string to Title Case, capitalizing the first letter of each word.
6
+ *
7
+ * The conversion process includes:
8
+ * - Trimming whitespace from both ends.
9
+ * - Converting the entire string to lowercase.
10
+ * - Replacing non-word characters and underscores with spaces.
11
+ * - Collapsing multiple spaces into a single space.
12
+ * - Capitalizing the first character of each word.
13
+ * - Preserving spaces between words.
14
+ *
15
+ * If the input is `null` or `undefined`, it returns an empty string.
16
+ *
17
+ * @param {string} text - The input string to convert.
18
+ * @returns {string} The Title Case formatted string.
19
+ *
20
+ * @example
21
+ * titleCase("hello world"); // "Hello World"
22
+ *
23
+ * @example
24
+ * titleCase("convert_to-title.case!"); // "Convert To Title Case"
25
+ *
26
+ * @example
27
+ * titleCase(" multiple spaces here "); // "Multiple Spaces Here"
28
+ */
29
+ function titleCase(text) {
30
+ if (text == null)
31
+ return '';
32
+ return text
33
+ .trim()
34
+ .toLowerCase()
35
+ .replace(/([^\w\s]|_)/g, ' ')
36
+ .replace(/\s+/g, ' ')
37
+ .replace(/(^|\s)(.)/g, (_, prefix, character) => prefix + character.toUpperCase())
38
+ .replace(/\s/g, ' ');
39
+ }
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Converts a string into a URL-friendly slug.
3
+ *
4
+ * The conversion process includes:
5
+ * - Converting the string to lowercase.
6
+ * - Trimming whitespace from both ends.
7
+ * - Replacing one or more whitespace characters with a single hyphen (`-`).
8
+ * - Removing all characters except word characters (letters, digits, and underscores) and hyphens.
9
+ *
10
+ * Throws an error if the input is not a string.
11
+ *
12
+ * @param {string} text - The input string to convert into a slug.
13
+ * @returns {string} The URL-friendly slug string.
14
+ * @throws {Error} If the input is not a string.
15
+ *
16
+ * @example
17
+ * toSlug("Hello World!"); // "hello-world"
18
+ *
19
+ * @example
20
+ * toSlug(" This is a test --- "); // "this-is-a-test"
21
+ *
22
+ * @example
23
+ * toSlug("Clean_URL--Slug123"); // "clean_url--slug123"
24
+ */
25
+ export declare function toSlug(text: string): string;
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toSlug = toSlug;
4
+ /**
5
+ * Converts a string into a URL-friendly slug.
6
+ *
7
+ * The conversion process includes:
8
+ * - Converting the string to lowercase.
9
+ * - Trimming whitespace from both ends.
10
+ * - Replacing one or more whitespace characters with a single hyphen (`-`).
11
+ * - Removing all characters except word characters (letters, digits, and underscores) and hyphens.
12
+ *
13
+ * Throws an error if the input is not a string.
14
+ *
15
+ * @param {string} text - The input string to convert into a slug.
16
+ * @returns {string} The URL-friendly slug string.
17
+ * @throws {Error} If the input is not a string.
18
+ *
19
+ * @example
20
+ * toSlug("Hello World!"); // "hello-world"
21
+ *
22
+ * @example
23
+ * toSlug(" This is a test --- "); // "this-is-a-test"
24
+ *
25
+ * @example
26
+ * toSlug("Clean_URL--Slug123"); // "clean_url--slug123"
27
+ */
28
+ function toSlug(text) {
29
+ if (typeof text !== 'string') {
30
+ throw new Error('Invalid argument. Expected a string.');
31
+ }
32
+ return text
33
+ .toLowerCase()
34
+ .trim()
35
+ .replace(/[\s]+/g, '-')
36
+ .replace(/[^\w-]+/g, '');
37
+ }
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Truncates a string to a specified maximum length and appends a suffix if truncated.
3
+ *
4
+ * If the text length is less than or equal to `maxLength`, the original text is returned.
5
+ * Otherwise, the text is cut off so that the total length including the suffix does not exceed `maxLength`.
6
+ *
7
+ * Throws a `TypeError` if input types are invalid or if `maxLength` is negative.
8
+ *
9
+ * @param {string} text - The input string to truncate.
10
+ * @param {number} maxLength - The maximum allowed length of the returned string including suffix.
11
+ * @param {string} [suffix='...'] - The string to append if truncation occurs.
12
+ * @returns {string} The truncated string with suffix if applicable.
13
+ * @throws {TypeError} If `text` is not a string.
14
+ * @throws {Error} If `maxLength` is not a non-negative number.
15
+ * @throws {TypeError} If `suffix` is not a string.
16
+ *
17
+ * @example
18
+ * truncateText("Hello World", 8); // "Hello..."
19
+ *
20
+ * @example
21
+ * truncateText("Short text", 20); // "Short text"
22
+ *
23
+ * @example
24
+ * truncateText("Custom suffix example", 10, "---"); // "Custom---"
25
+ */
26
+ export declare function truncateText(text: string, maxLength: number, suffix?: string): string;
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.truncateText = truncateText;
4
+ /**
5
+ * Truncates a string to a specified maximum length and appends a suffix if truncated.
6
+ *
7
+ * If the text length is less than or equal to `maxLength`, the original text is returned.
8
+ * Otherwise, the text is cut off so that the total length including the suffix does not exceed `maxLength`.
9
+ *
10
+ * Throws a `TypeError` if input types are invalid or if `maxLength` is negative.
11
+ *
12
+ * @param {string} text - The input string to truncate.
13
+ * @param {number} maxLength - The maximum allowed length of the returned string including suffix.
14
+ * @param {string} [suffix='...'] - The string to append if truncation occurs.
15
+ * @returns {string} The truncated string with suffix if applicable.
16
+ * @throws {TypeError} If `text` is not a string.
17
+ * @throws {Error} If `maxLength` is not a non-negative number.
18
+ * @throws {TypeError} If `suffix` is not a string.
19
+ *
20
+ * @example
21
+ * truncateText("Hello World", 8); // "Hello..."
22
+ *
23
+ * @example
24
+ * truncateText("Short text", 20); // "Short text"
25
+ *
26
+ * @example
27
+ * truncateText("Custom suffix example", 10, "---"); // "Custom---"
28
+ */
29
+ function truncateText(text, maxLength, suffix = '...') {
30
+ if (typeof text !== 'string') {
31
+ throw new TypeError('Input text must be a string.');
32
+ }
33
+ if (typeof maxLength !== 'number' || maxLength < 0) {
34
+ throw new Error('maxLength must be a non-negative number.');
35
+ }
36
+ if (typeof suffix !== 'string') {
37
+ throw new TypeError('Suffix must be a string.');
38
+ }
39
+ if (text.length <= maxLength) {
40
+ return text;
41
+ }
42
+ const adjustedLength = maxLength - suffix.length;
43
+ return text.slice(0, adjustedLength > 0 ? adjustedLength : 0) + suffix;
44
+ }
@@ -0,0 +1,29 @@
1
+ export { isCoordinates } from './isCoordinates';
2
+ export { isDate } from './isDate';
3
+ export { isEmail } from './isEmail';
4
+ export { isEmpty } from './isEmpty';
5
+ export { isSlug } from './isSlug';
6
+ export { isURL } from './isURL';
7
+ export { isIPv4 } from './isIPv4';
8
+ export { isHexColor } from './isHexColor';
9
+ export { isPalindrome } from './isPalindrome';
10
+ import { isCoordinates } from './isCoordinates';
11
+ import { isDate } from './isDate';
12
+ import { isEmail } from './isEmail';
13
+ import { isEmpty } from './isEmpty';
14
+ import { isSlug } from './isSlug';
15
+ import { isURL } from './isURL';
16
+ import { isIPv4 } from './isIPv4';
17
+ import { isHexColor } from './isHexColor';
18
+ import { isPalindrome } from './isPalindrome';
19
+ export declare const validations: {
20
+ isCoordinates: typeof isCoordinates;
21
+ isDate: typeof isDate;
22
+ isEmail: typeof isEmail;
23
+ isEmpty: typeof isEmpty;
24
+ isSlug: typeof isSlug;
25
+ isURL: typeof isURL;
26
+ isIPv4: typeof isIPv4;
27
+ isHexColor: typeof isHexColor;
28
+ isPalindrome: typeof isPalindrome;
29
+ };
@@ -0,0 +1,41 @@
1
+ "use strict";
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;
4
+ var isCoordinates_1 = require("./isCoordinates");
5
+ Object.defineProperty(exports, "isCoordinates", { enumerable: true, get: function () { return isCoordinates_1.isCoordinates; } });
6
+ var isDate_1 = require("./isDate");
7
+ Object.defineProperty(exports, "isDate", { enumerable: true, get: function () { return isDate_1.isDate; } });
8
+ var isEmail_1 = require("./isEmail");
9
+ Object.defineProperty(exports, "isEmail", { enumerable: true, get: function () { return isEmail_1.isEmail; } });
10
+ var isEmpty_1 = require("./isEmpty");
11
+ Object.defineProperty(exports, "isEmpty", { enumerable: true, get: function () { return isEmpty_1.isEmpty; } });
12
+ var isSlug_1 = require("./isSlug");
13
+ Object.defineProperty(exports, "isSlug", { enumerable: true, get: function () { return isSlug_1.isSlug; } });
14
+ var isURL_1 = require("./isURL");
15
+ Object.defineProperty(exports, "isURL", { enumerable: true, get: function () { return isURL_1.isURL; } });
16
+ var isIPv4_1 = require("./isIPv4");
17
+ Object.defineProperty(exports, "isIPv4", { enumerable: true, get: function () { return isIPv4_1.isIPv4; } });
18
+ var isHexColor_1 = require("./isHexColor");
19
+ Object.defineProperty(exports, "isHexColor", { enumerable: true, get: function () { return isHexColor_1.isHexColor; } });
20
+ var isPalindrome_1 = require("./isPalindrome");
21
+ Object.defineProperty(exports, "isPalindrome", { enumerable: true, get: function () { return isPalindrome_1.isPalindrome; } });
22
+ const isCoordinates_2 = require("./isCoordinates");
23
+ const isDate_2 = require("./isDate");
24
+ const isEmail_2 = require("./isEmail");
25
+ const isEmpty_2 = require("./isEmpty");
26
+ const isSlug_2 = require("./isSlug");
27
+ const isURL_2 = require("./isURL");
28
+ const isIPv4_2 = require("./isIPv4");
29
+ const isHexColor_2 = require("./isHexColor");
30
+ const isPalindrome_2 = require("./isPalindrome");
31
+ exports.validations = {
32
+ isCoordinates: isCoordinates_2.isCoordinates,
33
+ isDate: isDate_2.isDate,
34
+ isEmail: isEmail_2.isEmail,
35
+ isEmpty: isEmpty_2.isEmpty,
36
+ isSlug: isSlug_2.isSlug,
37
+ isURL: isURL_2.isURL,
38
+ isIPv4: isIPv4_2.isIPv4,
39
+ isHexColor: isHexColor_2.isHexColor,
40
+ isPalindrome: isPalindrome_2.isPalindrome
41
+ };
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Checks if given latitude and longitude are valid coordinates.
3
+ *
4
+ * @param {number} lat - The latitude to check.
5
+ * @param {number} long - The longitude to check.
6
+ * @returns {boolean} True if both latitude and longitude are valid, false otherwise.
7
+ */
8
+ export declare function isCoordinates(lat: number, long: number): boolean;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ /**
3
+ * Checks if given latitude and longitude are valid coordinates.
4
+ *
5
+ * @param {number} lat - The latitude to check.
6
+ * @param {number} long - The longitude to check.
7
+ * @returns {boolean} True if both latitude and longitude are valid, false otherwise.
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.isCoordinates = isCoordinates;
11
+ function isCoordinates(lat, long) {
12
+ return isLatitude(lat) && isLongitude(long);
13
+ }
14
+ function isLatitude(num) {
15
+ return Number.isFinite(num) && Math.abs(num) <= 90;
16
+ }
17
+ function isLongitude(num) {
18
+ return Number.isFinite(num) && Math.abs(num) <= 180;
19
+ }
@@ -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,61 @@
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 && checkDate.getMonth() === M - 1 && checkDate.getDate() === D;
60
+ return isValid;
61
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Checks if a given string is a valid email address.
3
+ *
4
+ * Uses a regular expression to verify the format: it must contain
5
+ * one "@" symbol, no spaces, and at least one dot after the "@"
6
+ * (e.g., "example@domain.com").
7
+ *
8
+ * @param {string} str - The string to be checked.
9
+ * @returns {boolean} True if the string is a valid email address, false otherwise.
10
+ */
11
+ export declare function isEmail(str: string, opts?: {
12
+ smtpUTF8?: boolean;
13
+ }): boolean;
@@ -0,0 +1,180 @@
1
+ "use strict";
2
+ /**
3
+ * Checks if a given string is a valid email address.
4
+ *
5
+ * Uses a regular expression to verify the format: it must contain
6
+ * one "@" symbol, no spaces, and at least one dot after the "@"
7
+ * (e.g., "example@domain.com").
8
+ *
9
+ * @param {string} str - The string to be checked.
10
+ * @returns {boolean} True if the string is a valid email address, false otherwise.
11
+ */
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.isEmail = isEmail;
14
+ function isEmail(str, opts) {
15
+ if (typeof str !== 'string')
16
+ return false;
17
+ if (!str)
18
+ return false;
19
+ // Enable SMTPUTF8 by default; set opts.smtpUTF8=false to enforce ASCII-only
20
+ const smtpUTF8 = (opts === null || opts === void 0 ? void 0 : opts.smtpUTF8) !== false;
21
+ // Quick overall length guard
22
+ if (str.length > 254)
23
+ return false;
24
+ // Find the separator '@' by scanning from right to left and skipping those inside quotes
25
+ let inQuote = false;
26
+ let atIndex = -1;
27
+ for (let i = str.length - 1; i >= 0; i--) {
28
+ const ch = str[i];
29
+ if (ch === '"') {
30
+ // toggle quote state if this quote is not escaped by a backslash
31
+ const prev = str[i - 1];
32
+ if (prev !== '\\')
33
+ inQuote = !inQuote;
34
+ continue;
35
+ }
36
+ if (ch === '@' && !inQuote) {
37
+ atIndex = i;
38
+ break;
39
+ }
40
+ }
41
+ if (inQuote)
42
+ return false; // unbalanced quotes
43
+ if (atIndex <= 0 || atIndex === str.length - 1)
44
+ return false;
45
+ const local = str.slice(0, atIndex);
46
+ const domain = str.slice(atIndex + 1);
47
+ // Local-part length limit (64 octets)
48
+ if (local.length > 64)
49
+ return false;
50
+ // Validate local part as dot-separated of atoms or quoted-strings
51
+ // Validate local with a robust FSM that supports nested unescaped quotes inside quoted strings
52
+ const isAsciiAtext = (ch) => /[A-Za-z0-9!#$%&'*+\/=?^_`{|}~-]/.test(ch);
53
+ const isUnicodeAtext = (ch) => {
54
+ if (!smtpUTF8)
55
+ return false;
56
+ // Disallow obvious separators and specials used by the parser
57
+ if (ch === '.' || ch === ' ' || ch === '"' || ch === '\\' || ch === '@')
58
+ return false;
59
+ // Disallow whitespace/control
60
+ if (/\s/u.test(ch))
61
+ return false;
62
+ // Allow Unicode Letters, Marks, Numbers and Symbols (e.g., emoji)
63
+ return /[\p{L}\p{N}\p{M}\p{S}]/u.test(ch);
64
+ };
65
+ let lastWasDot = false; // disallow consecutive or leading/trailing dots anywhere
66
+ let inQ = false; // inside a quoted token
67
+ let qDepth = 0; // quote nesting depth (>=1 when inside outer quotes)
68
+ let escQ = false; // backslash escape inside quotes
69
+ let needDotAfterQuoted = false; // require a dot right after a quoted token if not at end
70
+ for (let i = 0; i < local.length; i++) {
71
+ const c = local[i];
72
+ // If we just closed a quoted token, the very next char must be a dot
73
+ if (!inQ && needDotAfterQuoted) {
74
+ if (c !== '.')
75
+ return false;
76
+ needDotAfterQuoted = false;
77
+ lastWasDot = true;
78
+ continue;
79
+ }
80
+ if (inQ) {
81
+ if (escQ) {
82
+ // After a backslash, allow any non-newline character (broader under SMTPUTF8)
83
+ if (/\r|\n/.test(c))
84
+ return false;
85
+ escQ = false;
86
+ continue;
87
+ }
88
+ if (c === '\\') {
89
+ escQ = true;
90
+ continue;
91
+ }
92
+ if (c === '"') {
93
+ // Support nested unescaped quotes within a quoted token.
94
+ // Only close the quoted token when depth returns to 0 and we're at end-of-local
95
+ // or the next character is a dot (separator between tokens).
96
+ if (qDepth > 1) {
97
+ qDepth -= 1;
98
+ lastWasDot = false;
99
+ continue;
100
+ }
101
+ // qDepth === 1: decide whether to close or to start nesting
102
+ if (i + 1 === local.length || local[i + 1] === '.') {
103
+ // this quote closes the quoted token
104
+ inQ = false;
105
+ qDepth = 0;
106
+ // require a dot if not at end
107
+ if (i + 1 < local.length)
108
+ needDotAfterQuoted = true;
109
+ lastWasDot = false;
110
+ continue;
111
+ }
112
+ else {
113
+ // start a nested quote level
114
+ qDepth += 1; // becomes 2
115
+ lastWasDot = false;
116
+ continue;
117
+ }
118
+ }
119
+ // Inside quotes: allow ASCII VCHAR and space by default; with SMTPUTF8 allow any char except control newlines
120
+ if (smtpUTF8) {
121
+ if (/\r|\n/.test(c))
122
+ return false;
123
+ }
124
+ else {
125
+ const code = c.charCodeAt(0);
126
+ if (code < 0x20 || code > 0x7E)
127
+ return false;
128
+ }
129
+ // Dots inside quoted string are allowed freely
130
+ continue;
131
+ }
132
+ // outside quotes
133
+ if (c === '"') {
134
+ // quotes can only start at token boundaries (start or right after a dot)
135
+ if (i > 0 && !lastWasDot)
136
+ return false;
137
+ inQ = true;
138
+ qDepth = 1;
139
+ escQ = false;
140
+ lastWasDot = false;
141
+ continue;
142
+ }
143
+ if (c === '.') {
144
+ if (i === 0 || lastWasDot)
145
+ return false; // leading or consecutive dot
146
+ lastWasDot = true;
147
+ continue;
148
+ }
149
+ if (c === ' ')
150
+ return false; // no spaces outside quotes
151
+ // must be atext outside quotes
152
+ if (!(isAsciiAtext(c) || isUnicodeAtext(c)))
153
+ return false;
154
+ lastWasDot = false;
155
+ }
156
+ if (inQ || qDepth !== 0 || escQ)
157
+ return false; // unbalanced quotes or dangling escape
158
+ if (lastWasDot)
159
+ return false; // trailing dot
160
+ // Validate domain
161
+ const labelRe = /^[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?$/;
162
+ const ipv4Re = /^(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}$/;
163
+ const ipv6Re = /^IPv6:(?:[A-Fa-f0-9:]+)$/; // coarse check; detailed covered by overall tests
164
+ if (domain.startsWith('[') && domain.endsWith(']')) {
165
+ const literal = domain.slice(1, -1);
166
+ if (ipv4Re.test(literal))
167
+ return true;
168
+ if (ipv6Re.test(literal))
169
+ return true; // accept canonical IPv6 forms used in tests
170
+ return false;
171
+ }
172
+ const parts = domain.split('.');
173
+ if (parts.some(p => p.length === 0))
174
+ return false;
175
+ for (const p of parts) {
176
+ if (!labelRe.test(p))
177
+ return false;
178
+ }
179
+ return true;
180
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Checks whether a given string is empty or consists only of whitespace.
3
+ *
4
+ * Trims the input string and returns true if the resulting length is 0,
5
+ * indicating that the string is either empty or contains only whitespace characters.
6
+ *
7
+ * @param {string} str - The string to check.
8
+ * @returns {boolean} True if the string is empty or whitespace only, false otherwise.
9
+ */
10
+ export declare function isEmpty(str: string): boolean;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ /**
3
+ * Checks whether a given string is empty or consists only of whitespace.
4
+ *
5
+ * Trims the input string and returns true if the resulting length is 0,
6
+ * indicating that the string is either empty or contains only whitespace characters.
7
+ *
8
+ * @param {string} str - The string to check.
9
+ * @returns {boolean} True if the string is empty or whitespace only, false otherwise.
10
+ */
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.isEmpty = isEmpty;
13
+ function isEmpty(str) {
14
+ return str.trim().length === 0;
15
+ }
@@ -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
+ }