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
package/changelog.txt CHANGED
@@ -1,111 +1,111 @@
1
- CHANGELOG
2
-
3
- All notable changes to the `stringzy` package will be documented in this file.
4
-
5
- =============================================================================
6
- Version 2.2.1 - 2025-06-04
7
- -----------------------------------------------------------------------------
8
-
9
- ADDED:
10
- - Added npmignore file to exclude unnecessary files from the package
11
-
12
-
13
- =============================================================================
14
- Version 2.2.0 - 2025-06-04
15
- -----------------------------------------------------------------------------
16
-
17
- ADDED:
18
- - Added new utility functions:
19
- - `removeDuplicates`: Removes duplicate words from a string
20
- - Added the stringzy banner to the README
21
-
22
- =============================================================================
23
- Version 2.1.0 - 2025-05-31
24
- -----------------------------------------------------------------------------
25
-
26
- ADDED:
27
- - Added new utility functions:
28
- - `removeWords`:
29
- - `isDate`: Validates if a string is a valid date
30
- - Added contributors section in README
31
- - Added new badges for open source and PRs
32
-
33
- =============================================================================
34
- Version 2.0.1 - 2025-05-23
35
- -----------------------------------------------------------------------------
36
-
37
- FIXED:
38
- - Fixed README.MD table of contents for transformations.
39
-
40
-
41
-
42
- =============================================================================
43
- Version 2.0.0 - 2025-05-22
44
- -----------------------------------------------------------------------------
45
-
46
- ADDED:
47
- - Added a dynamic list of APIs in README
48
- - Divided the package into 4 modules-transformations, validations, formatting and analysis
49
- - Added many new APIs
50
- - `camelCase`: Converts a string to camel case
51
- - `kebabCase`: Converts a string to kebab case
52
- - `snakeCase`: Converts a string to snake case
53
- - `titleCase`: Converts a string to title case
54
- - `constantCase`: Converts a string to constant case
55
- - `pascalCase`: Converts a string to pascal case
56
- - `isURL`: Validates if a string is a valid URL
57
- - `isEmail`: Validates if a string is a valid email address
58
- - `isEmpty`: Checks if a string is empty or contains only whitespace
59
- - `wordCount`: Counts the number of words in a string
60
- - `characterCount`: Counts the number of characters in a string
61
- - `characterFrequency`: Calculates the frequency of each character in a string
62
- - `capitalize`: Capitalizes the entire string
63
- - `formatNumber`: Formats a number with commas as thousands separators
64
- - `formatPhone`: Formats a phone number to a standard format
65
-
66
- =============================================================================
67
-
68
- Version 1.1.2 - 2025-05-15
69
- -----------------------------------------------------------------------------
70
-
71
- ADDED:
72
- - Improved documentation with comprehensive README
73
- - Enhanced examples for all utility functions
74
-
75
- FIXED:
76
- - Resolved documentation rendering issues on npm website
77
-
78
- =============================================================================
79
-
80
- Version 1.1.1 - 2025-05-15
81
- -----------------------------------------------------------------------------
82
-
83
- CHANGED:
84
- - Updated package metadata
85
-
86
- FIXED:
87
- - Minor bug fixes in string handling edge cases
88
-
89
- =============================================================================
90
-
91
- Version 1.1.0 - 2025-05-15
92
- -----------------------------------------------------------------------------
93
-
94
- ADDED:
95
- - Added extensive API documentation
96
-
97
- CHANGED:
98
- - Improved performance for `toSlug` function
99
- - Enhanced error handling across all utility functions
100
-
101
- =============================================================================
102
-
103
- Version 1.0.0 - 2025-05-14
104
- -----------------------------------------------------------------------------
105
-
106
- ADDED:
107
- - Initial release with four core utility functions:
108
- - `truncateText`: Truncates text to a specified length with optional suffix
109
- - `toSlug`: Converts text to URL-friendly slug format
110
- - `capitalizeWords`: Capitalizes the first letter of each word
1
+ CHANGELOG
2
+
3
+ All notable changes to the `stringzy` package will be documented in this file.
4
+
5
+ =============================================================================
6
+ Version 2.2.1 - 2025-06-04
7
+ -----------------------------------------------------------------------------
8
+
9
+ ADDED:
10
+ - Added npmignore file to exclude unnecessary files from the package
11
+
12
+
13
+ =============================================================================
14
+ Version 2.2.0 - 2025-06-04
15
+ -----------------------------------------------------------------------------
16
+
17
+ ADDED:
18
+ - Added new utility functions:
19
+ - `removeDuplicates`: Removes duplicate words from a string
20
+ - Added the stringzy banner to the README
21
+
22
+ =============================================================================
23
+ Version 2.1.0 - 2025-05-31
24
+ -----------------------------------------------------------------------------
25
+
26
+ ADDED:
27
+ - Added new utility functions:
28
+ - `removeWords`:
29
+ - `isDate`: Validates if a string is a valid date
30
+ - Added contributors section in README
31
+ - Added new badges for open source and PRs
32
+
33
+ =============================================================================
34
+ Version 2.0.1 - 2025-05-23
35
+ -----------------------------------------------------------------------------
36
+
37
+ FIXED:
38
+ - Fixed README.MD table of contents for transformations.
39
+
40
+
41
+
42
+ =============================================================================
43
+ Version 2.0.0 - 2025-05-22
44
+ -----------------------------------------------------------------------------
45
+
46
+ ADDED:
47
+ - Added a dynamic list of APIs in README
48
+ - Divided the package into 4 modules-transformations, validations, formatting and analysis
49
+ - Added many new APIs
50
+ - `camelCase`: Converts a string to camel case
51
+ - `kebabCase`: Converts a string to kebab case
52
+ - `snakeCase`: Converts a string to snake case
53
+ - `titleCase`: Converts a string to title case
54
+ - `constantCase`: Converts a string to constant case
55
+ - `pascalCase`: Converts a string to pascal case
56
+ - `isURL`: Validates if a string is a valid URL
57
+ - `isEmail`: Validates if a string is a valid email address
58
+ - `isEmpty`: Checks if a string is empty or contains only whitespace
59
+ - `wordCount`: Counts the number of words in a string
60
+ - `characterCount`: Counts the number of characters in a string
61
+ - `characterFrequency`: Calculates the frequency of each character in a string
62
+ - `capitalize`: Capitalizes the entire string
63
+ - `formatNumber`: Formats a number with commas as thousands separators
64
+ - `formatPhone`: Formats a phone number to a standard format
65
+
66
+ =============================================================================
67
+
68
+ Version 1.1.2 - 2025-05-15
69
+ -----------------------------------------------------------------------------
70
+
71
+ ADDED:
72
+ - Improved documentation with comprehensive README
73
+ - Enhanced examples for all utility functions
74
+
75
+ FIXED:
76
+ - Resolved documentation rendering issues on npm website
77
+
78
+ =============================================================================
79
+
80
+ Version 1.1.1 - 2025-05-15
81
+ -----------------------------------------------------------------------------
82
+
83
+ CHANGED:
84
+ - Updated package metadata
85
+
86
+ FIXED:
87
+ - Minor bug fixes in string handling edge cases
88
+
89
+ =============================================================================
90
+
91
+ Version 1.1.0 - 2025-05-15
92
+ -----------------------------------------------------------------------------
93
+
94
+ ADDED:
95
+ - Added extensive API documentation
96
+
97
+ CHANGED:
98
+ - Improved performance for `toSlug` function
99
+ - Enhanced error handling across all utility functions
100
+
101
+ =============================================================================
102
+
103
+ Version 1.0.0 - 2025-05-14
104
+ -----------------------------------------------------------------------------
105
+
106
+ ADDED:
107
+ - Initial release with four core utility functions:
108
+ - `truncateText`: Truncates text to a specified length with optional suffix
109
+ - `toSlug`: Converts text to URL-friendly slug format
110
+ - `capitalizeWords`: Capitalizes the first letter of each word
111
111
  - `removeSpecialChars`: Removes special characters from text with optional replacement
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Returns the number of characters in a given string.
3
+ *
4
+ * This function counts all characters in the string, including whitespace,
5
+ * punctuation, and special characters. It throws a `TypeError` if the input is not a string.
6
+ *
7
+ * @param {string} str - The string whose characters will be counted.
8
+ * @returns {number} The number of characters in the input string.
9
+ * @throws {TypeError} If the input is not of type string.
10
+ *
11
+ * @example
12
+ * characterCount("Hello, world!"); // 13
13
+ *
14
+ * @example
15
+ * characterCount(" "); // 2
16
+ *
17
+ * @example
18
+ * characterCount(""); // 0
19
+ */
20
+ export declare function characterCount(str: string): number;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.characterCount = characterCount;
4
+ /**
5
+ * Returns the number of characters in a given string.
6
+ *
7
+ * This function counts all characters in the string, including whitespace,
8
+ * punctuation, and special characters. It throws a `TypeError` if the input is not a string.
9
+ *
10
+ * @param {string} str - The string whose characters will be counted.
11
+ * @returns {number} The number of characters in the input string.
12
+ * @throws {TypeError} If the input is not of type string.
13
+ *
14
+ * @example
15
+ * characterCount("Hello, world!"); // 13
16
+ *
17
+ * @example
18
+ * characterCount(" "); // 2
19
+ *
20
+ * @example
21
+ * characterCount(""); // 0
22
+ */
23
+ function characterCount(str) {
24
+ if (typeof str !== 'string') {
25
+ throw new TypeError('Input must be a string');
26
+ }
27
+ return str.length;
28
+ }
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Calculates the frequency of each non-space character in a string.
3
+ *
4
+ * This function returns an object mapping each lowercase character (excluding spaces)
5
+ * to the number of times it appears in the input string. The input is case-insensitive,
6
+ * meaning 'A' and 'a' are treated the same. It throws a `TypeError` if the input is not a string.
7
+ *
8
+ * @param {string} str - The string to analyze.
9
+ * @returns {Record<string, number>} An object where keys are characters and values are their counts.
10
+ * @throws {TypeError} If the input is not a string.
11
+ *
12
+ * @example
13
+ * characterFrequency("Hello World");
14
+ * // Returns: { h: 1, e: 1, l: 3, o: 2, w: 1, r: 1, d: 1 }
15
+ *
16
+ * @example
17
+ * characterFrequency("AaBb");
18
+ * // Returns: { a: 2, b: 2 }
19
+ */
20
+ export declare function characterFrequency(str: string): Record<string, number>;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.characterFrequency = characterFrequency;
4
+ /**
5
+ * Calculates the frequency of each non-space character in a string.
6
+ *
7
+ * This function returns an object mapping each lowercase character (excluding spaces)
8
+ * to the number of times it appears in the input string. The input is case-insensitive,
9
+ * meaning 'A' and 'a' are treated the same. It throws a `TypeError` if the input is not a string.
10
+ *
11
+ * @param {string} str - The string to analyze.
12
+ * @returns {Record<string, number>} An object where keys are characters and values are their counts.
13
+ * @throws {TypeError} If the input is not a string.
14
+ *
15
+ * @example
16
+ * characterFrequency("Hello World");
17
+ * // Returns: { h: 1, e: 1, l: 3, o: 2, w: 1, r: 1, d: 1 }
18
+ *
19
+ * @example
20
+ * characterFrequency("AaBb");
21
+ * // Returns: { a: 2, b: 2 }
22
+ */
23
+ function characterFrequency(str) {
24
+ if (typeof str !== 'string') {
25
+ throw new TypeError('Input must be a string');
26
+ }
27
+ const frequency = {};
28
+ for (const char of str.toLowerCase()) {
29
+ if (char !== ' ') {
30
+ // Exclude spaces for cleaner analysis
31
+ frequency[char] = (frequency[char] || 0) + 1;
32
+ }
33
+ }
34
+ return frequency;
35
+ }
@@ -0,0 +1,39 @@
1
+ export type ComplexityResult = {
2
+ score: number;
3
+ uniqueness: number;
4
+ length: number;
5
+ };
6
+ /**
7
+ * Evaluates the complexity of a given string based on length, character uniqueness,
8
+ * and character type diversity (lowercase, uppercase, numbers, symbols).
9
+ *
10
+ * The returned score ranges from 0 to 1, where a higher score indicates greater complexity.
11
+ * It also returns the raw length of the string and its uniqueness ratio (unique chars / total length).
12
+ *
13
+ * - `uniqueness`: Measures how varied the characters are.
14
+ * - `score`: Combines uniqueness, type diversity, and length into a weighted value.
15
+ * - `length`: The total number of characters in the input.
16
+ *
17
+ * Throws a `TypeError` if the input is not a string.
18
+ *
19
+ * @param {string} str - The input string to evaluate.
20
+ * @returns {ComplexityResult} An object containing `score`, `uniqueness`, and `length`.
21
+ * @throws {TypeError} If the input is not a string.
22
+ *
23
+ * @example
24
+ * complexity("abcABC123!");
25
+ * // {
26
+ * // score: 0.93,
27
+ * // uniqueness: 1.00,
28
+ * // length: 10
29
+ * // }
30
+ *
31
+ * @example
32
+ * complexity("aaaa");
33
+ * // {
34
+ * // score: 0.25,
35
+ * // uniqueness: 0.25,
36
+ * // length: 4
37
+ * // }
38
+ */
39
+ export declare function complexity(str: string): ComplexityResult;
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.complexity = complexity;
4
+ /**
5
+ * Evaluates the complexity of a given string based on length, character uniqueness,
6
+ * and character type diversity (lowercase, uppercase, numbers, symbols).
7
+ *
8
+ * The returned score ranges from 0 to 1, where a higher score indicates greater complexity.
9
+ * It also returns the raw length of the string and its uniqueness ratio (unique chars / total length).
10
+ *
11
+ * - `uniqueness`: Measures how varied the characters are.
12
+ * - `score`: Combines uniqueness, type diversity, and length into a weighted value.
13
+ * - `length`: The total number of characters in the input.
14
+ *
15
+ * Throws a `TypeError` if the input is not a string.
16
+ *
17
+ * @param {string} str - The input string to evaluate.
18
+ * @returns {ComplexityResult} An object containing `score`, `uniqueness`, and `length`.
19
+ * @throws {TypeError} If the input is not a string.
20
+ *
21
+ * @example
22
+ * complexity("abcABC123!");
23
+ * // {
24
+ * // score: 0.93,
25
+ * // uniqueness: 1.00,
26
+ * // length: 10
27
+ * // }
28
+ *
29
+ * @example
30
+ * complexity("aaaa");
31
+ * // {
32
+ * // score: 0.25,
33
+ * // uniqueness: 0.25,
34
+ * // length: 4
35
+ * // }
36
+ */
37
+ function complexity(str) {
38
+ if (!str)
39
+ return { score: 0, uniqueness: 0, length: 0 };
40
+ if (typeof str !== 'string') {
41
+ throw new TypeError('Input must be a string');
42
+ }
43
+ const length = str.length;
44
+ const unique = new Set(str).size;
45
+ const uniqueness = unique / length;
46
+ let typeScore = 0;
47
+ if (/[a-z]/.test(str))
48
+ typeScore += 0.25;
49
+ if (/[A-Z]/.test(str))
50
+ typeScore += 0.25;
51
+ if (/[0-9]/.test(str))
52
+ typeScore += 0.25;
53
+ if (/[^a-zA-Z0-9]/.test(str))
54
+ typeScore += 0.25;
55
+ // Calculate score based on length and character diversity
56
+ const lengthScore = Math.min(1, length / 20); // Max score at 20 chars
57
+ const score = uniqueness * 0.4 + typeScore * 0.4 + lengthScore * 0.2;
58
+ return {
59
+ score: parseFloat(score.toFixed(2)),
60
+ uniqueness: parseFloat(uniqueness.toFixed(2)),
61
+ length,
62
+ };
63
+ }
@@ -0,0 +1,26 @@
1
+ export { characterCount } from './characterCount';
2
+ export { characterFrequency } from './characterFrequency';
3
+ export { complexity } from './complexity';
4
+ export { readingDuration } from './readingDuration';
5
+ export { wordCount } from './wordCount';
6
+ export { stringSimilarity } from './stringSimilarity';
7
+ export { patternCount } from './patternCount';
8
+ export { vowelConsonantCount } from './vowelConsonantCount';
9
+ import { characterCount } from './characterCount';
10
+ import { characterFrequency } from './characterFrequency';
11
+ import { complexity } from './complexity';
12
+ import { readingDuration } from './readingDuration';
13
+ import { wordCount } from './wordCount';
14
+ import { stringSimilarity } from './stringSimilarity';
15
+ import { patternCount } from './patternCount';
16
+ import { vowelConsonantCount } from './vowelConsonantCount';
17
+ export declare const analyzing: {
18
+ characterCount: typeof characterCount;
19
+ characterFrequency: typeof characterFrequency;
20
+ complexity: typeof complexity;
21
+ readingDuration: typeof readingDuration;
22
+ wordCount: typeof wordCount;
23
+ stringSimilarity: typeof stringSimilarity;
24
+ patternCount: typeof patternCount;
25
+ vowelConsonantCount: typeof vowelConsonantCount;
26
+ };
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.analyzing = exports.vowelConsonantCount = exports.patternCount = exports.stringSimilarity = exports.wordCount = exports.readingDuration = exports.complexity = exports.characterFrequency = exports.characterCount = void 0;
4
+ var characterCount_1 = require("./characterCount");
5
+ Object.defineProperty(exports, "characterCount", { enumerable: true, get: function () { return characterCount_1.characterCount; } });
6
+ var characterFrequency_1 = require("./characterFrequency");
7
+ Object.defineProperty(exports, "characterFrequency", { enumerable: true, get: function () { return characterFrequency_1.characterFrequency; } });
8
+ var complexity_1 = require("./complexity");
9
+ Object.defineProperty(exports, "complexity", { enumerable: true, get: function () { return complexity_1.complexity; } });
10
+ var readingDuration_1 = require("./readingDuration");
11
+ Object.defineProperty(exports, "readingDuration", { enumerable: true, get: function () { return readingDuration_1.readingDuration; } });
12
+ var wordCount_1 = require("./wordCount");
13
+ Object.defineProperty(exports, "wordCount", { enumerable: true, get: function () { return wordCount_1.wordCount; } });
14
+ var stringSimilarity_1 = require("./stringSimilarity");
15
+ Object.defineProperty(exports, "stringSimilarity", { enumerable: true, get: function () { return stringSimilarity_1.stringSimilarity; } });
16
+ var patternCount_1 = require("./patternCount");
17
+ Object.defineProperty(exports, "patternCount", { enumerable: true, get: function () { return patternCount_1.patternCount; } });
18
+ var vowelConsonantCount_1 = require("./vowelConsonantCount");
19
+ Object.defineProperty(exports, "vowelConsonantCount", { enumerable: true, get: function () { return vowelConsonantCount_1.vowelConsonantCount; } });
20
+ const characterCount_2 = require("./characterCount");
21
+ const characterFrequency_2 = require("./characterFrequency");
22
+ const complexity_2 = require("./complexity");
23
+ const readingDuration_2 = require("./readingDuration");
24
+ const wordCount_2 = require("./wordCount");
25
+ const stringSimilarity_2 = require("./stringSimilarity");
26
+ const patternCount_2 = require("./patternCount");
27
+ const vowelConsonantCount_2 = require("./vowelConsonantCount");
28
+ exports.analyzing = {
29
+ characterCount: characterCount_2.characterCount,
30
+ characterFrequency: characterFrequency_2.characterFrequency,
31
+ complexity: complexity_2.complexity,
32
+ readingDuration: readingDuration_2.readingDuration,
33
+ wordCount: wordCount_2.wordCount,
34
+ stringSimilarity: stringSimilarity_2.stringSimilarity,
35
+ patternCount: patternCount_2.patternCount,
36
+ vowelConsonantCount: vowelConsonantCount_2.vowelConsonantCount
37
+ };
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Calculates the number of times a specific pattern occurs in a given text, including overlapping occurrences
3
+ *
4
+ * The algorithm used here is based on the Knuth-Morris-Pratt (KMP) pattern matching algorithm for better performance
5
+ *
6
+ * @param {string} text - The text for which we want to count the occurrences of a specific pattern.
7
+ * @param {string} pattern - The pattern to search for within the text.
8
+ * @returns {number} - The number of times the pattern occurs in the text (overlapping).
9
+ */
10
+ export declare function patternCount(text: string, pattern: string): number;
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.patternCount = patternCount;
4
+ /**
5
+ * Calculates the number of times a specific pattern occurs in a given text, including overlapping occurrences
6
+ *
7
+ * The algorithm used here is based on the Knuth-Morris-Pratt (KMP) pattern matching algorithm for better performance
8
+ *
9
+ * @param {string} text - The text for which we want to count the occurrences of a specific pattern.
10
+ * @param {string} pattern - The pattern to search for within the text.
11
+ * @returns {number} - The number of times the pattern occurs in the text (overlapping).
12
+ */
13
+ function patternCount(text, pattern) {
14
+ if (pattern.length === 0) {
15
+ return 0; // No pattern to search for
16
+ }
17
+ const prefixFunction = computePrefixFunction(pattern);
18
+ let count = 0;
19
+ let j = 0; // Index for pattern
20
+ for (let i = 0; i < text.length; i++) {
21
+ while (j > 0 && text[i] !== pattern[j]) {
22
+ j = prefixFunction[j - 1];
23
+ }
24
+ if (text[i] === pattern[j]) {
25
+ j++;
26
+ }
27
+ if (j === pattern.length) {
28
+ count++;
29
+ j = prefixFunction[j - 1]; // Allow for overlapping matches
30
+ }
31
+ }
32
+ return count;
33
+ }
34
+ /**
35
+ * Computes the prefix function (partial match table) for KMP algorithm.
36
+ * @param {string} pattern - The pattern string.
37
+ * @returns {number[]} - The prefix function array.
38
+ */
39
+ function computePrefixFunction(pattern) {
40
+ const prefixFunction = new Array(pattern.length).fill(0);
41
+ let j = 0;
42
+ for (let i = 1; i < pattern.length; i++) {
43
+ while (j > 0 && pattern[i] !== pattern[j]) {
44
+ j = prefixFunction[j - 1];
45
+ }
46
+ if (pattern[i] === pattern[j]) {
47
+ j++;
48
+ }
49
+ prefixFunction[i] = j;
50
+ }
51
+ return prefixFunction;
52
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Calculates the estimated reading duration for a given text based on an average reading speed.
3
+ *
4
+ * The default reading speed is set to 230 words per minute, which is derived from various research studies.
5
+ *
6
+ * @param {string} text - The text for which the reading duration is to be calculated.
7
+ * @param {number} [readingSpeed=230] - The reading speed in words per minute. Defaults to 230.
8
+ * @returns {number} - The estimated reading duration in minutes.
9
+ */
10
+ export declare function readingDuration(text: string, readingSpeed?: number): number;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.readingDuration = readingDuration;
4
+ const wordCount_1 = require("./wordCount");
5
+ /**
6
+ * Calculates the estimated reading duration for a given text based on an average reading speed.
7
+ *
8
+ * The default reading speed is set to 230 words per minute, which is derived from various research studies.
9
+ *
10
+ * @param {string} text - The text for which the reading duration is to be calculated.
11
+ * @param {number} [readingSpeed=230] - The reading speed in words per minute. Defaults to 230.
12
+ * @returns {number} - The estimated reading duration in minutes.
13
+ */
14
+ function readingDuration(text, readingSpeed = 230) {
15
+ const amountOfWords = (0, wordCount_1.wordCount)(text);
16
+ return Math.round(amountOfWords / readingSpeed);
17
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Calculates the percentage similarity between two texts using the selected algorithm.
3
+ * @param textA The first text to compare.
4
+ * @param textB The second text to compare.
5
+ * @param algorithm The algorithm to use: 'Levenshtein' or 'Damerau-Levenshtein'. Default is 'Levenshtein'.
6
+ * @returns Similarity percentage (0-100).
7
+ */
8
+ export declare function stringSimilarity(textA: string, textB: string, algorithm?: 'Levenshtein' | 'Damerau-Levenshtein'): number;