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,18 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const node_test_1 = require("node:test");
7
+ const node_assert_1 = __importDefault(require("node:assert"));
8
+ const isURL_1 = require("../../validations/isURL");
9
+ (0, node_test_1.describe)('isURL', () => {
10
+ (0, node_test_1.it)('returns true for valid URLs', () => {
11
+ node_assert_1.default.strictEqual((0, isURL_1.isURL)('https://example.com'), true);
12
+ node_assert_1.default.strictEqual((0, isURL_1.isURL)('http://localhost:3000'), true);
13
+ });
14
+ (0, node_test_1.it)('returns false for invalid URLs', () => {
15
+ node_assert_1.default.strictEqual((0, isURL_1.isURL)('not a url'), false);
16
+ node_assert_1.default.strictEqual((0, isURL_1.isURL)(''), false);
17
+ });
18
+ });
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Converts a given string into camelCase format.
3
+ *
4
+ * This function normalizes the input by:
5
+ * - Converting it to lowercase
6
+ * - Removing special characters (except alphanumeric and underscores)
7
+ * - Replacing underscores and multiple spaces with single spaces
8
+ * - Capitalizing each word except the first
9
+ * - Removing all spaces to form a camelCased result
10
+ *
11
+ * If the input is `null` or `undefined`, an empty string is returned.
12
+ *
13
+ * @param {string} text - The input string to convert.
14
+ * @returns {string} The camelCased version of the input string.
15
+ *
16
+ * @example
17
+ * camelCase("Hello world"); // "helloWorld"
18
+ *
19
+ * @example
20
+ * camelCase(" convert_to-camel case!! "); // "convertToCamelCase"
21
+ *
22
+ * @example
23
+ * camelCase(""); // ""
24
+ */
25
+ export declare function camelCase(text: string): string;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.camelCase = camelCase;
4
+ /**
5
+ * Converts a given string into camelCase format.
6
+ *
7
+ * This function normalizes the input by:
8
+ * - Converting it to lowercase
9
+ * - Removing special characters (except alphanumeric and underscores)
10
+ * - Replacing underscores and multiple spaces with single spaces
11
+ * - Capitalizing each word except the first
12
+ * - Removing all spaces to form a camelCased result
13
+ *
14
+ * If the input is `null` or `undefined`, an empty string is returned.
15
+ *
16
+ * @param {string} text - The input string to convert.
17
+ * @returns {string} The camelCased version of the input string.
18
+ *
19
+ * @example
20
+ * camelCase("Hello world"); // "helloWorld"
21
+ *
22
+ * @example
23
+ * camelCase(" convert_to-camel case!! "); // "convertToCamelCase"
24
+ *
25
+ * @example
26
+ * camelCase(""); // ""
27
+ */
28
+ function camelCase(text) {
29
+ if (text == null)
30
+ return '';
31
+ return text
32
+ .trim()
33
+ .toLowerCase()
34
+ .replace(/[^\w\s]/g, ' ')
35
+ .replace(/_/g, ' ')
36
+ .replace(/\s+/g, ' ')
37
+ .replace(/\s(.)/g, (_, character) => character.toUpperCase())
38
+ .replace(/^(.)/, (_, character) => character.toLowerCase());
39
+ }
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Capitalizes the first letter of every word in a given string.
3
+ *
4
+ * A word is identified by word boundaries (`\b`), and only the first character
5
+ * of each word is converted to uppercase. The rest of the characters remain unchanged.
6
+ *
7
+ * Throws an error if the input is not a string.
8
+ *
9
+ * @param {string} text - The input string whose words will be capitalized.
10
+ * @returns {string} A new string with each word's first character in uppercase.
11
+ * @throws {Error} If the input is not a string.
12
+ *
13
+ * @example
14
+ * capitalizeWords("hello world"); // "Hello World"
15
+ *
16
+ * @example
17
+ * capitalizeWords("javaScript is fun!"); // "JavaScript Is Fun!"
18
+ *
19
+ * @example
20
+ * capitalizeWords(""); // ""
21
+ */
22
+ export declare function capitalizeWords(text: string): string;
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.capitalizeWords = capitalizeWords;
4
+ /**
5
+ * Capitalizes the first letter of every word in a given string.
6
+ *
7
+ * A word is identified by word boundaries (`\b`), and only the first character
8
+ * of each word is converted to uppercase. The rest of the characters remain unchanged.
9
+ *
10
+ * Throws an error if the input is not a string.
11
+ *
12
+ * @param {string} text - The input string whose words will be capitalized.
13
+ * @returns {string} A new string with each word's first character in uppercase.
14
+ * @throws {Error} If the input is not a string.
15
+ *
16
+ * @example
17
+ * capitalizeWords("hello world"); // "Hello World"
18
+ *
19
+ * @example
20
+ * capitalizeWords("javaScript is fun!"); // "JavaScript Is Fun!"
21
+ *
22
+ * @example
23
+ * capitalizeWords(""); // ""
24
+ */
25
+ function capitalizeWords(text) {
26
+ if (typeof text !== 'string') {
27
+ throw new Error('Invalid argument. Expected a string.');
28
+ }
29
+ return text.replace(/\b\w/g, (char) => char.toUpperCase());
30
+ }
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Converts a given string to CONSTANT_CASE format.
3
+ *
4
+ * The transformation includes:
5
+ * - Trimming whitespace from both ends
6
+ * - Replacing spaces and hyphens with underscores
7
+ * - Inserting underscores between lowercase and uppercase letter boundaries (e.g., `fooBar` → `FOO_BAR`)
8
+ * - Replacing all non-word characters with underscores
9
+ * - Converting the entire string to uppercase
10
+ * - Collapsing multiple underscores into one
11
+ * - Removing leading and trailing underscores
12
+ *
13
+ * If the input is `null` or `undefined`, it returns an empty string.
14
+ *
15
+ * @param {string} text - The input string to convert.
16
+ * @returns {string} The transformed CONSTANT_CASE string.
17
+ *
18
+ * @example
19
+ * constantCase("hello world"); // "HELLO_WORLD"
20
+ *
21
+ * @example
22
+ * constantCase("camelCaseText"); // "CAMEL_CASE_TEXT"
23
+ *
24
+ * @example
25
+ * constantCase(" convert-to_CONSTANT.case! "); // "CONVERT_TO_CONSTANT_CASE"
26
+ */
27
+ export declare function constantCase(text: string): string;
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.constantCase = constantCase;
4
+ /**
5
+ * Converts a given string to CONSTANT_CASE format.
6
+ *
7
+ * The transformation includes:
8
+ * - Trimming whitespace from both ends
9
+ * - Replacing spaces and hyphens with underscores
10
+ * - Inserting underscores between lowercase and uppercase letter boundaries (e.g., `fooBar` → `FOO_BAR`)
11
+ * - Replacing all non-word characters with underscores
12
+ * - Converting the entire string to uppercase
13
+ * - Collapsing multiple underscores into one
14
+ * - Removing leading and trailing underscores
15
+ *
16
+ * If the input is `null` or `undefined`, it returns an empty string.
17
+ *
18
+ * @param {string} text - The input string to convert.
19
+ * @returns {string} The transformed CONSTANT_CASE string.
20
+ *
21
+ * @example
22
+ * constantCase("hello world"); // "HELLO_WORLD"
23
+ *
24
+ * @example
25
+ * constantCase("camelCaseText"); // "CAMEL_CASE_TEXT"
26
+ *
27
+ * @example
28
+ * constantCase(" convert-to_CONSTANT.case! "); // "CONVERT_TO_CONSTANT_CASE"
29
+ */
30
+ function constantCase(text) {
31
+ if (text == null)
32
+ return '';
33
+ return text
34
+ .trim()
35
+ .replace(/[\s-]+/g, '_')
36
+ .replace(/([a-z])([A-Z])/g, '$1_$2')
37
+ .replace(/[^\w_]/g, '_')
38
+ .toUpperCase()
39
+ .replace(/_+/g, '_')
40
+ .replace(/^_+|_+$/g, '');
41
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Removes accents and diacritics from letters in a string.
3
+ * @param str - Input string
4
+ * @returns A deburred string without accented characters.
5
+ * @throws Error if input is not a string
6
+ */
7
+ export declare function deburr(str: string): string;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.deburr = deburr;
4
+ /**
5
+ * Removes accents and diacritics from letters in a string.
6
+ * @param str - Input string
7
+ * @returns A deburred string without accented characters.
8
+ * @throws Error if input is not a string
9
+ */
10
+ function deburr(str) {
11
+ if (typeof str !== 'string') {
12
+ throw new Error('Input must be a string');
13
+ }
14
+ // Normalize and strip combining marks (diacritics)
15
+ return str.normalize('NFD').replace(/[\u0300-\u036f]/g, '');
16
+ }
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Escapes special HTML characters in a string to their corresponding HTML entities.
3
+ *
4
+ * This function replaces the following characters:
5
+ * - `&` with `&`
6
+ * - `<` with `&lt;`
7
+ * - `>` with `&gt;`
8
+ * - `"` with `&quot;`
9
+ * - `'` with `&#39;`
10
+ *
11
+ * This is useful to prevent HTML injection or XSS attacks when inserting user input into HTML.
12
+ *
13
+ * @param {string} str - The string to escape.
14
+ * @returns {string} The escaped string with HTML entities.
15
+ *
16
+ * @example
17
+ * escapeHtml('<div class="test">Hello & Welcome</div>');
18
+ * // "&lt;div class=&quot;test&quot;&gt;Hello &amp; Welcome&lt;/div&gt;"
19
+ *
20
+ * @example
21
+ * escapeHtml("It's a test!");
22
+ * // "It&#39;s a test!"
23
+ */
24
+ export declare function escapeHtml(str: string): string;
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.escapeHtml = escapeHtml;
4
+ /**
5
+ * Escapes special HTML characters in a string to their corresponding HTML entities.
6
+ *
7
+ * This function replaces the following characters:
8
+ * - `&` with `&amp;`
9
+ * - `<` with `&lt;`
10
+ * - `>` with `&gt;`
11
+ * - `"` with `&quot;`
12
+ * - `'` with `&#39;`
13
+ *
14
+ * This is useful to prevent HTML injection or XSS attacks when inserting user input into HTML.
15
+ *
16
+ * @param {string} str - The string to escape.
17
+ * @returns {string} The escaped string with HTML entities.
18
+ *
19
+ * @example
20
+ * escapeHtml('<div class="test">Hello & Welcome</div>');
21
+ * // "&lt;div class=&quot;test&quot;&gt;Hello &amp; Welcome&lt;/div&gt;"
22
+ *
23
+ * @example
24
+ * escapeHtml("It's a test!");
25
+ * // "It&#39;s a test!"
26
+ */
27
+ function escapeHtml(str) {
28
+ const htmlEscapes = {
29
+ '&': '&amp;',
30
+ '<': '&lt;',
31
+ '>': '&gt;',
32
+ '"': '&quot;',
33
+ "'": '&#39;',
34
+ };
35
+ return str.replace(/[&<>"']/g, (match) => htmlEscapes[match]);
36
+ }
@@ -0,0 +1,52 @@
1
+ export { camelCase } from './camelCase';
2
+ export { capitalizeWords } from './capitalizeWords';
3
+ export { constantCase } from './constantCase';
4
+ export { initials } from './initials';
5
+ export { kebabCase } from './kebabCase';
6
+ export { pascalCase } from './pascalCase';
7
+ export { removeDuplicates } from './removeDuplicates';
8
+ export { removeSpecialChars } from './removeSpecialChars';
9
+ export { removeWords } from './removeWords';
10
+ export { snakeCase } from './snakeCase';
11
+ export { titleCase } from './titleCase';
12
+ export { toSlug } from './toSlug';
13
+ export { truncateText } from './truncateText';
14
+ export { escapeHtml } from './escapeHTML';
15
+ export { maskSegment } from './maskSegment';
16
+ export { numberToText } from './numberToText/main';
17
+ import { camelCase } from './camelCase';
18
+ import { capitalizeWords } from './capitalizeWords';
19
+ import { constantCase } from './constantCase';
20
+ import { initials } from './initials';
21
+ import { kebabCase } from './kebabCase';
22
+ import { pascalCase } from './pascalCase';
23
+ import { removeDuplicates } from './removeDuplicates';
24
+ import { removeSpecialChars } from './removeSpecialChars';
25
+ import { removeWords } from './removeWords';
26
+ import { snakeCase } from './snakeCase';
27
+ import { titleCase } from './titleCase';
28
+ import { toSlug } from './toSlug';
29
+ import { truncateText } from './truncateText';
30
+ import { escapeHtml } from './escapeHTML';
31
+ import { maskSegment } from './maskSegment';
32
+ import { deburr } from './deburr';
33
+ import { numberToText } from './numberToText/main';
34
+ export declare const transformations: {
35
+ camelCase: typeof camelCase;
36
+ capitalizeWords: typeof capitalizeWords;
37
+ constantCase: typeof constantCase;
38
+ initials: typeof initials;
39
+ kebabCase: typeof kebabCase;
40
+ pascalCase: typeof pascalCase;
41
+ removeDuplicates: typeof removeDuplicates;
42
+ removeSpecialChars: typeof removeSpecialChars;
43
+ removeWords: typeof removeWords;
44
+ snakeCase: typeof snakeCase;
45
+ titleCase: typeof titleCase;
46
+ toSlug: typeof toSlug;
47
+ truncateText: typeof truncateText;
48
+ escapeHtml: typeof escapeHtml;
49
+ maskSegment: typeof maskSegment;
50
+ deburr: typeof deburr;
51
+ numberToText: typeof numberToText;
52
+ };
@@ -0,0 +1,71 @@
1
+ "use strict";
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;
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
+ var main_1 = require("./numberToText/main");
35
+ Object.defineProperty(exports, "numberToText", { enumerable: true, get: function () { return main_1.numberToText; } });
36
+ const camelCase_2 = require("./camelCase");
37
+ const capitalizeWords_2 = require("./capitalizeWords");
38
+ const constantCase_2 = require("./constantCase");
39
+ const initials_2 = require("./initials");
40
+ const kebabCase_2 = require("./kebabCase");
41
+ const pascalCase_2 = require("./pascalCase");
42
+ const removeDuplicates_2 = require("./removeDuplicates");
43
+ const removeSpecialChars_2 = require("./removeSpecialChars");
44
+ const removeWords_2 = require("./removeWords");
45
+ const snakeCase_2 = require("./snakeCase");
46
+ const titleCase_2 = require("./titleCase");
47
+ const toSlug_2 = require("./toSlug");
48
+ const truncateText_2 = require("./truncateText");
49
+ const escapeHTML_2 = require("./escapeHTML");
50
+ const maskSegment_2 = require("./maskSegment");
51
+ const deburr_1 = require("./deburr");
52
+ const main_2 = require("./numberToText/main");
53
+ exports.transformations = {
54
+ camelCase: camelCase_2.camelCase,
55
+ capitalizeWords: capitalizeWords_2.capitalizeWords,
56
+ constantCase: constantCase_2.constantCase,
57
+ initials: initials_2.initials,
58
+ kebabCase: kebabCase_2.kebabCase,
59
+ pascalCase: pascalCase_2.pascalCase,
60
+ removeDuplicates: removeDuplicates_2.removeDuplicates,
61
+ removeSpecialChars: removeSpecialChars_2.removeSpecialChars,
62
+ removeWords: removeWords_2.removeWords,
63
+ snakeCase: snakeCase_2.snakeCase,
64
+ titleCase: titleCase_2.titleCase,
65
+ toSlug: toSlug_2.toSlug,
66
+ truncateText: truncateText_2.truncateText,
67
+ escapeHtml: escapeHTML_2.escapeHtml,
68
+ maskSegment: maskSegment_2.maskSegment,
69
+ deburr: deburr_1.deburr,
70
+ numberToText: main_2.numberToText
71
+ };
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Extracts the initials from a given string.
3
+ *
4
+ * Splits the input text by whitespace, takes the first character of each word,
5
+ * and joins them together. Optionally limits the number of initials returned.
6
+ *
7
+ * Throws an error if the input is not a string or if the `limit` parameter
8
+ * is provided but not a non-negative number.
9
+ *
10
+ * @param {string} text - The input string from which to extract initials.
11
+ * @param {number} [limit] - Optional maximum number of initials to return.
12
+ * @returns {string} A string containing the initials.
13
+ * @throws {TypeError} If `text` is not a string.
14
+ * @throws {Error} If `limit` is provided and is not a non-negative number.
15
+ *
16
+ * @example
17
+ * initials("John Doe"); // "JD"
18
+ *
19
+ * @example
20
+ * initials("John Ronald Reuel Tolkien", 2); // "JR"
21
+ *
22
+ * @example
23
+ * initials(" singleWord "); // "s"
24
+ *
25
+ * @example
26
+ * initials(""); // ""
27
+ */
28
+ export declare function initials(text: string, limit?: number): string;
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.initials = initials;
4
+ /**
5
+ * Extracts the initials from a given string.
6
+ *
7
+ * Splits the input text by whitespace, takes the first character of each word,
8
+ * and joins them together. Optionally limits the number of initials returned.
9
+ *
10
+ * Throws an error if the input is not a string or if the `limit` parameter
11
+ * is provided but not a non-negative number.
12
+ *
13
+ * @param {string} text - The input string from which to extract initials.
14
+ * @param {number} [limit] - Optional maximum number of initials to return.
15
+ * @returns {string} A string containing the initials.
16
+ * @throws {TypeError} If `text` is not a string.
17
+ * @throws {Error} If `limit` is provided and is not a non-negative number.
18
+ *
19
+ * @example
20
+ * initials("John Doe"); // "JD"
21
+ *
22
+ * @example
23
+ * initials("John Ronald Reuel Tolkien", 2); // "JR"
24
+ *
25
+ * @example
26
+ * initials(" singleWord "); // "s"
27
+ *
28
+ * @example
29
+ * initials(""); // ""
30
+ */
31
+ function initials(text, limit) {
32
+ if (typeof text !== 'string') {
33
+ throw new TypeError('Input must be a string');
34
+ }
35
+ if (limit !== undefined && (typeof limit !== 'number' || isNaN(limit))) {
36
+ throw new Error('Limit must be a valid number');
37
+ }
38
+ if (limit !== undefined && limit < 0) {
39
+ throw new Error('Limit must be a non-negative number');
40
+ }
41
+ const words = text
42
+ .trim()
43
+ .split(/\s+/)
44
+ .filter((word) => word.length > 0);
45
+ if (words.length === 0)
46
+ return '';
47
+ const initialsArray = words.map((word) => word.charAt(0)).slice(0, limit !== null && limit !== void 0 ? limit : words.length);
48
+ return initialsArray.join('');
49
+ }
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Converts a given string to kebab-case format.
3
+ *
4
+ * The conversion process includes:
5
+ * - Trimming whitespace from both ends.
6
+ * - Replacing spaces and underscores with hyphens.
7
+ * - Inserting hyphens between lowercase and uppercase letter boundaries (e.g., `fooBar` → `foo-bar`).
8
+ * - Replacing all non-word characters (except hyphens) with hyphens.
9
+ * - Converting the entire string to lowercase.
10
+ * - Collapsing multiple consecutive hyphens into a single one.
11
+ * - Removing leading and trailing hyphens.
12
+ *
13
+ * If the input is `null` or `undefined`, an empty string is returned.
14
+ *
15
+ * @param {string} text - The input string to convert.
16
+ * @returns {string} The kebab-case formatted string.
17
+ *
18
+ * @example
19
+ * kebabCase("Hello World"); // "hello-world"
20
+ *
21
+ * @example
22
+ * kebabCase("camelCaseText"); // "camel-case-text"
23
+ *
24
+ * @example
25
+ * kebabCase(" convert_to--kebab.case! "); // "convert-to-kebab-case"
26
+ */
27
+ export declare function kebabCase(text: string): string;
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.kebabCase = kebabCase;
4
+ /**
5
+ * Converts a given string to kebab-case format.
6
+ *
7
+ * The conversion process includes:
8
+ * - Trimming whitespace from both ends.
9
+ * - Replacing spaces and underscores with hyphens.
10
+ * - Inserting hyphens between lowercase and uppercase letter boundaries (e.g., `fooBar` → `foo-bar`).
11
+ * - Replacing all non-word characters (except hyphens) with hyphens.
12
+ * - Converting the entire string to lowercase.
13
+ * - Collapsing multiple consecutive hyphens into a single one.
14
+ * - Removing leading and trailing hyphens.
15
+ *
16
+ * If the input is `null` or `undefined`, an empty string is returned.
17
+ *
18
+ * @param {string} text - The input string to convert.
19
+ * @returns {string} The kebab-case formatted string.
20
+ *
21
+ * @example
22
+ * kebabCase("Hello World"); // "hello-world"
23
+ *
24
+ * @example
25
+ * kebabCase("camelCaseText"); // "camel-case-text"
26
+ *
27
+ * @example
28
+ * kebabCase(" convert_to--kebab.case! "); // "convert-to-kebab-case"
29
+ */
30
+ function kebabCase(text) {
31
+ if (text == null)
32
+ return '';
33
+ return text
34
+ .trim()
35
+ .replace(/[\s_]+/g, '-')
36
+ .replace(/([a-z])([A-Z])/g, '$1-$2')
37
+ .replace(/[^\w-]/g, '-')
38
+ .toLowerCase()
39
+ .replace(/-+/g, '-')
40
+ .replace(/^-+|-+$/g, '');
41
+ }
@@ -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,23 @@
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) + maskChar.repeat(maskEnd - maskStart) + text.slice(maskEnd);
23
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Checks if a number is negative
3
+ */
4
+ export declare function isNegative(num: number): boolean;
5
+ /**
6
+ * Gets the highest order of magnitude for a number
7
+ * @example getOrderOfMagnitude(1234) returns 1000
8
+ * @example getOrderOfMagnitude(567) returns 100
9
+ */
10
+ export declare function getOrderOfMagnitude(num: number): number;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isNegative = isNegative;
4
+ exports.getOrderOfMagnitude = getOrderOfMagnitude;
5
+ /**
6
+ * Checks if a number is negative
7
+ */
8
+ function isNegative(num) {
9
+ return num < 0;
10
+ }
11
+ /**
12
+ * Gets the highest order of magnitude for a number
13
+ * @example getOrderOfMagnitude(1234) returns 1000
14
+ * @example getOrderOfMagnitude(567) returns 100
15
+ */
16
+ function getOrderOfMagnitude(num) {
17
+ const absNum = Math.abs(num);
18
+ if (absNum >= 1000000000000)
19
+ return 1000000000000;
20
+ if (absNum >= 1000000000)
21
+ return 1000000000;
22
+ if (absNum >= 1000000)
23
+ return 1000000;
24
+ if (absNum >= 1000)
25
+ return 1000;
26
+ if (absNum >= 100)
27
+ return 100;
28
+ if (absNum >= 10)
29
+ return 10;
30
+ return 1;
31
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Converts a number to its English textual representation.
3
+ *
4
+ * Handles negative numbers, numbers from 0 to 20, tens, hundreds, thousands, and larger magnitudes.
5
+ *
6
+ * @param num The number to convert.
7
+ * @returns The textual representation of the number in English.
8
+ */
9
+ declare function numberToTextEn(num: number): string;
10
+ export default numberToTextEn;