stringzy 2.2.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (151) hide show
  1. package/.github/workflows/publish.yml +29 -0
  2. package/.github/workflows/test-on-pr.yml +23 -0
  3. package/CONTRIBUTING.md +87 -0
  4. package/LICENSE +21 -21
  5. package/README.md +952 -723
  6. package/changelog.txt +110 -102
  7. package/dist/analyzing/characterCount.d.ts +1 -0
  8. package/dist/analyzing/characterCount.js +9 -0
  9. package/dist/analyzing/characterFrequency.d.ts +1 -0
  10. package/dist/analyzing/characterFrequency.js +16 -0
  11. package/dist/analyzing/complexity.d.ts +6 -0
  12. package/dist/analyzing/complexity.js +30 -0
  13. package/dist/analyzing/index.d.ts +20 -0
  14. package/dist/analyzing/index.js +29 -0
  15. package/dist/analyzing/readingDuration.d.ts +10 -0
  16. package/dist/analyzing/readingDuration.js +17 -0
  17. package/dist/analyzing/stringSimilarity.d.ts +8 -0
  18. package/dist/analyzing/stringSimilarity.js +145 -0
  19. package/dist/analyzing/wordCount.d.ts +1 -0
  20. package/dist/analyzing/wordCount.js +11 -0
  21. package/dist/formatting/capitalize.d.ts +1 -0
  22. package/dist/formatting/capitalize.js +12 -0
  23. package/dist/formatting/index.d.ts +11 -0
  24. package/dist/formatting/index.js +17 -0
  25. package/dist/formatting/number.d.ts +1 -0
  26. package/dist/formatting/number.js +7 -0
  27. package/dist/formatting/phone.d.ts +2 -0
  28. package/dist/formatting/phone.js +25 -0
  29. package/dist/index.d.ts +47 -0
  30. package/dist/index.js +30 -0
  31. package/dist/tests/analyzing/characterCount.test.d.ts +1 -0
  32. package/dist/tests/analyzing/characterCount.test.js +19 -0
  33. package/dist/tests/analyzing/characterFrequency.test.d.ts +1 -0
  34. package/dist/tests/analyzing/characterFrequency.test.js +22 -0
  35. package/dist/tests/analyzing/complexity.test.d.ts +1 -0
  36. package/dist/tests/analyzing/complexity.test.js +28 -0
  37. package/dist/tests/analyzing/readingDuration.test.d.ts +1 -0
  38. package/dist/tests/analyzing/readingDuration.test.js +45 -0
  39. package/dist/tests/analyzing/stringSimilarity.test.d.ts +1 -0
  40. package/dist/tests/analyzing/stringSimilarity.test.js +61 -0
  41. package/dist/tests/analyzing/wordCount.test.d.ts +1 -0
  42. package/dist/tests/analyzing/wordCount.test.js +22 -0
  43. package/dist/tests/formatting/capitalize.test.d.ts +1 -0
  44. package/dist/tests/formatting/capitalize.test.js +22 -0
  45. package/dist/tests/formatting/number.test.d.ts +1 -0
  46. package/dist/tests/formatting/number.test.js +19 -0
  47. package/dist/tests/formatting/phone.test.d.ts +1 -0
  48. package/dist/tests/formatting/phone.test.js +25 -0
  49. package/dist/tests/transformations/camelCase.test.d.ts +1 -0
  50. package/dist/tests/transformations/camelCase.test.js +19 -0
  51. package/dist/tests/transformations/capitalizeWords.test.d.ts +1 -0
  52. package/dist/tests/transformations/capitalizeWords.test.js +19 -0
  53. package/dist/tests/transformations/constantCase.test.d.ts +1 -0
  54. package/dist/tests/transformations/constantCase.test.js +19 -0
  55. package/dist/tests/transformations/deburr.test.d.ts +1 -0
  56. package/dist/tests/transformations/deburr.test.js +27 -0
  57. package/dist/tests/transformations/escapeHTML.test.d.ts +1 -0
  58. package/dist/tests/transformations/escapeHTML.test.js +46 -0
  59. package/dist/tests/transformations/initials.test.d.ts +1 -0
  60. package/dist/tests/transformations/initials.test.js +25 -0
  61. package/dist/tests/transformations/kebabCase.test.d.ts +1 -0
  62. package/dist/tests/transformations/kebabCase.test.js +19 -0
  63. package/dist/tests/transformations/maskSegment.test.d.ts +1 -0
  64. package/dist/tests/transformations/maskSegment.test.js +30 -0
  65. package/dist/tests/transformations/pascalCase.test.d.ts +1 -0
  66. package/dist/tests/transformations/pascalCase.test.js +19 -0
  67. package/dist/tests/transformations/removeDuplicates.test.d.ts +1 -0
  68. package/dist/tests/transformations/removeDuplicates.test.js +19 -0
  69. package/dist/tests/transformations/removeSpecialChars.test.d.ts +1 -0
  70. package/dist/tests/transformations/removeSpecialChars.test.js +22 -0
  71. package/dist/tests/transformations/removeWords.test.d.ts +1 -0
  72. package/dist/tests/transformations/removeWords.test.js +25 -0
  73. package/dist/tests/transformations/snakeCase.test.d.ts +1 -0
  74. package/dist/tests/transformations/snakeCase.test.js +19 -0
  75. package/dist/tests/transformations/titleCase.test.d.ts +1 -0
  76. package/dist/tests/transformations/titleCase.test.js +19 -0
  77. package/dist/tests/transformations/toSlug.test.d.ts +1 -0
  78. package/dist/tests/transformations/toSlug.test.js +22 -0
  79. package/dist/tests/transformations/truncateText.test.d.ts +1 -0
  80. package/dist/tests/transformations/truncateText.test.js +31 -0
  81. package/dist/tests/validations/isDate.test.d.ts +1 -0
  82. package/dist/tests/validations/isDate.test.js +55 -0
  83. package/dist/tests/validations/isEmail.test.d.ts +1 -0
  84. package/dist/tests/validations/isEmail.test.js +17 -0
  85. package/dist/tests/validations/isEmpty.test.d.ts +1 -0
  86. package/dist/tests/validations/isEmpty.test.js +19 -0
  87. package/dist/tests/validations/isHexColor.test.d.ts +1 -0
  88. package/dist/tests/validations/isHexColor.test.js +32 -0
  89. package/dist/tests/validations/isIPv4.test.d.ts +1 -0
  90. package/dist/tests/validations/isIPv4.test.js +59 -0
  91. package/dist/tests/validations/isSlug.test.d.ts +1 -0
  92. package/dist/tests/validations/isSlug.test.js +22 -0
  93. package/dist/tests/validations/isURL.test.d.ts +1 -0
  94. package/dist/tests/validations/isURL.test.js +18 -0
  95. package/dist/transformations/camelCase.d.ts +1 -0
  96. package/dist/transformations/camelCase.js +15 -0
  97. package/dist/transformations/capitalizeWords.d.ts +1 -0
  98. package/dist/transformations/capitalizeWords.js +9 -0
  99. package/dist/transformations/constantCase.d.ts +1 -0
  100. package/dist/transformations/constantCase.js +15 -0
  101. package/dist/transformations/deburr.d.ts +7 -0
  102. package/dist/transformations/deburr.js +16 -0
  103. package/dist/transformations/escapeHTML.d.ts +1 -0
  104. package/dist/transformations/escapeHTML.js +14 -0
  105. package/dist/transformations/index.d.ts +49 -0
  106. package/dist/transformations/index.js +67 -0
  107. package/dist/transformations/initials.d.ts +1 -0
  108. package/dist/transformations/initials.js +19 -0
  109. package/dist/transformations/kebabCase.d.ts +1 -0
  110. package/dist/transformations/kebabCase.js +15 -0
  111. package/dist/transformations/maskSegment.d.ts +9 -0
  112. package/dist/transformations/maskSegment.js +25 -0
  113. package/dist/transformations/pascalCase.d.ts +1 -0
  114. package/dist/transformations/pascalCase.js +15 -0
  115. package/dist/transformations/removeDuplicates.d.ts +1 -0
  116. package/dist/transformations/removeDuplicates.js +13 -0
  117. package/dist/transformations/removeSpecialChars.d.ts +1 -0
  118. package/dist/transformations/removeSpecialChars.js +12 -0
  119. package/dist/transformations/removeWords.d.ts +1 -0
  120. package/dist/transformations/removeWords.js +23 -0
  121. package/dist/transformations/snakeCase.d.ts +1 -0
  122. package/dist/transformations/snakeCase.js +15 -0
  123. package/dist/transformations/titleCase.d.ts +1 -0
  124. package/dist/transformations/titleCase.js +14 -0
  125. package/dist/transformations/toSlug.d.ts +1 -0
  126. package/dist/transformations/toSlug.js +13 -0
  127. package/dist/transformations/truncateText.d.ts +1 -0
  128. package/dist/transformations/truncateText.js +19 -0
  129. package/dist/validations/index.d.ts +23 -0
  130. package/dist/validations/index.js +33 -0
  131. package/dist/validations/isDate.d.ts +18 -0
  132. package/dist/validations/isDate.js +63 -0
  133. package/dist/validations/isEmail.d.ts +1 -0
  134. package/dist/validations/isEmail.js +7 -0
  135. package/dist/validations/isEmpty.d.ts +1 -0
  136. package/dist/validations/isEmpty.js +6 -0
  137. package/dist/validations/isHexColor.d.ts +7 -0
  138. package/dist/validations/isHexColor.js +15 -0
  139. package/dist/validations/isIPv4.d.ts +1 -0
  140. package/dist/validations/isIPv4.js +13 -0
  141. package/dist/validations/isSlug.d.ts +1 -0
  142. package/dist/validations/isSlug.js +10 -0
  143. package/dist/validations/isURL.d.ts +1 -0
  144. package/dist/validations/isURL.js +12 -0
  145. package/package.json +10 -4
  146. package/analysis.js +0 -21
  147. package/assets/stringzy-banner2.jpg +0 -0
  148. package/formatting.js +0 -37
  149. package/index.js +0 -75
  150. package/transformations.js +0 -190
  151. package/validations.js +0 -80
package/changelog.txt CHANGED
@@ -1,103 +1,111 @@
1
- CHANGELOG
2
-
3
- All notable changes to the `stringzy` package will be documented in this file.
4
-
5
- =============================================================================
6
- Version 2.1.0 - 2025-05-31
7
- -----------------------------------------------------------------------------
8
-
9
- ADDED:
10
- - Added new utility functions:
11
- - `removeDuplicates`: Removes duplicate words from a string
12
- - Added the stringzy banner to the README
13
-
14
- =============================================================================
15
- Version 2.1.0 - 2025-05-31
16
- -----------------------------------------------------------------------------
17
-
18
- ADDED:
19
- - Added new utility functions:
20
- - `removeWords`:
21
- - `isDate`: Validates if a string is a valid date
22
- - Added contributors section in README
23
- - Added new badges for open source and PRs
24
-
25
- =============================================================================
26
- Version 2.0.1 - 2025-05-23
27
- -----------------------------------------------------------------------------
28
-
29
- FIXED:
30
- - Fixed README.MD table of contents for transformations.
31
-
32
-
33
-
34
- =============================================================================
35
- Version 2.0.0 - 2025-05-22
36
- -----------------------------------------------------------------------------
37
-
38
- ADDED:
39
- - Added a dynamic list of APIs in README
40
- - Divided the package into 4 modules-transformations, validations, formatting and analysis
41
- - Added many new APIs
42
- - `camelCase`: Converts a string to camel case
43
- - `kebabCase`: Converts a string to kebab case
44
- - `snakeCase`: Converts a string to snake case
45
- - `titleCase`: Converts a string to title case
46
- - `constantCase`: Converts a string to constant case
47
- - `pascalCase`: Converts a string to pascal case
48
- - `isURL`: Validates if a string is a valid URL
49
- - `isEmail`: Validates if a string is a valid email address
50
- - `isEmpty`: Checks if a string is empty or contains only whitespace
51
- - `wordCount`: Counts the number of words in a string
52
- - `characterCount`: Counts the number of characters in a string
53
- - `characterFrequency`: Calculates the frequency of each character in a string
54
- - `capitalize`: Capitalizes the entire string
55
- - `formatNumber`: Formats a number with commas as thousands separators
56
- - `formatPhone`: Formats a phone number to a standard format
57
-
58
- =============================================================================
59
-
60
- Version 1.1.2 - 2025-05-15
61
- -----------------------------------------------------------------------------
62
-
63
- ADDED:
64
- - Improved documentation with comprehensive README
65
- - Enhanced examples for all utility functions
66
-
67
- FIXED:
68
- - Resolved documentation rendering issues on npm website
69
-
70
- =============================================================================
71
-
72
- Version 1.1.1 - 2025-05-15
73
- -----------------------------------------------------------------------------
74
-
75
- CHANGED:
76
- - Updated package metadata
77
-
78
- FIXED:
79
- - Minor bug fixes in string handling edge cases
80
-
81
- =============================================================================
82
-
83
- Version 1.1.0 - 2025-05-15
84
- -----------------------------------------------------------------------------
85
-
86
- ADDED:
87
- - Added extensive API documentation
88
-
89
- CHANGED:
90
- - Improved performance for `toSlug` function
91
- - Enhanced error handling across all utility functions
92
-
93
- =============================================================================
94
-
95
- Version 1.0.0 - 2025-05-14
96
- -----------------------------------------------------------------------------
97
-
98
- ADDED:
99
- - Initial release with four core utility functions:
100
- - `truncateText`: Truncates text to a specified length with optional suffix
101
- - `toSlug`: Converts text to URL-friendly slug format
102
- - `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
103
111
  - `removeSpecialChars`: Removes special characters from text with optional replacement
@@ -0,0 +1 @@
1
+ export declare function characterCount(str: string): number;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.characterCount = characterCount;
4
+ function characterCount(str) {
5
+ if (typeof str !== "string") {
6
+ throw new TypeError("Input must be a string");
7
+ }
8
+ return str.length;
9
+ }
@@ -0,0 +1 @@
1
+ export declare function characterFrequency(str: string): Record<string, number>;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.characterFrequency = characterFrequency;
4
+ function characterFrequency(str) {
5
+ if (typeof str !== "string") {
6
+ throw new TypeError("Input must be a string");
7
+ }
8
+ const frequency = {};
9
+ for (const char of str.toLowerCase()) {
10
+ if (char !== " ") {
11
+ // Exclude spaces for cleaner analysis
12
+ frequency[char] = (frequency[char] || 0) + 1;
13
+ }
14
+ }
15
+ return frequency;
16
+ }
@@ -0,0 +1,6 @@
1
+ export type ComplexityResult = {
2
+ score: number;
3
+ uniqueness: number;
4
+ length: number;
5
+ };
6
+ export declare function complexity(str: string): ComplexityResult;
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.complexity = complexity;
4
+ function complexity(str) {
5
+ if (!str)
6
+ return { score: 0, uniqueness: 0, length: 0 };
7
+ if (typeof str !== "string") {
8
+ throw new TypeError("Input must be a string");
9
+ }
10
+ const length = str.length;
11
+ const unique = new Set(str).size;
12
+ const uniqueness = unique / length;
13
+ let typeScore = 0;
14
+ if (/[a-z]/.test(str))
15
+ typeScore += 0.25;
16
+ if (/[A-Z]/.test(str))
17
+ typeScore += 0.25;
18
+ if (/[0-9]/.test(str))
19
+ typeScore += 0.25;
20
+ if (/[^a-zA-Z0-9]/.test(str))
21
+ typeScore += 0.25;
22
+ // Calculate score based on length and character diversity
23
+ const lengthScore = Math.min(1, length / 20); // Max score at 20 chars
24
+ const score = uniqueness * 0.4 + typeScore * 0.4 + lengthScore * 0.2;
25
+ return {
26
+ score: parseFloat(score.toFixed(2)),
27
+ uniqueness: parseFloat(uniqueness.toFixed(2)),
28
+ length,
29
+ };
30
+ }
@@ -0,0 +1,20 @@
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
+ import { characterCount } from "./characterCount";
8
+ import { characterFrequency } from "./characterFrequency";
9
+ import { complexity } from "./complexity";
10
+ import { readingDuration } from "./readingDuration";
11
+ import { wordCount } from "./wordCount";
12
+ import { stringSimilarity } from "./stringSimilarity";
13
+ export declare const analyzing: {
14
+ characterCount: typeof characterCount;
15
+ characterFrequency: typeof characterFrequency;
16
+ complexity: typeof complexity;
17
+ readingDuration: typeof readingDuration;
18
+ wordCount: typeof wordCount;
19
+ stringSimilarity: typeof stringSimilarity;
20
+ };
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.analyzing = 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
+ const characterCount_2 = require("./characterCount");
17
+ const characterFrequency_2 = require("./characterFrequency");
18
+ const complexity_2 = require("./complexity");
19
+ const readingDuration_2 = require("./readingDuration");
20
+ const wordCount_2 = require("./wordCount");
21
+ const stringSimilarity_2 = require("./stringSimilarity");
22
+ exports.analyzing = {
23
+ characterCount: characterCount_2.characterCount,
24
+ characterFrequency: characterFrequency_2.characterFrequency,
25
+ complexity: complexity_2.complexity,
26
+ readingDuration: readingDuration_2.readingDuration,
27
+ wordCount: wordCount_2.wordCount,
28
+ stringSimilarity: stringSimilarity_2.stringSimilarity
29
+ };
@@ -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;
@@ -0,0 +1,145 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.stringSimilarity = stringSimilarity;
4
+ /**
5
+ * Calculates the percentage similarity between two texts using the selected algorithm.
6
+ * @param textA The first text to compare.
7
+ * @param textB The second text to compare.
8
+ * @param algorithm The algorithm to use: 'Levenshtein' or 'Damerau-Levenshtein'. Default is 'Levenshtein'.
9
+ * @returns Similarity percentage (0-100).
10
+ */
11
+ function stringSimilarity(textA, textB, algorithm = 'Levenshtein') {
12
+ validateParams(textA, textB, algorithm);
13
+ if (textA === textB) {
14
+ return 100.0;
15
+ }
16
+ if (textA.length === 0 && textB.length != 0) {
17
+ return 0.0;
18
+ }
19
+ let distance;
20
+ if (algorithm === 'Levenshtein') {
21
+ distance = calculateLevenshteinDistance(textA, textB);
22
+ }
23
+ else {
24
+ distance = calculateDamerauLevenshteinDistance(textA, textB);
25
+ }
26
+ return calculateSimilarityScore(distance, textA, textB);
27
+ }
28
+ /**
29
+ * Converts the edit distance to a percentage similarity score.
30
+ * @param distance The edit distance between the texts.
31
+ * @param textA The first text.
32
+ * @param textB The second text.
33
+ * @returns Similarity percentage (0-100).
34
+ */
35
+ function calculateSimilarityScore(distance, textA, textB) {
36
+ const similarityScore = 1 - (distance / Math.max(textA.length, textB.length));
37
+ return parseFloat((similarityScore * 100).toFixed(2));
38
+ }
39
+ /**
40
+ * Calculates the Levenshtein distance between two texts.
41
+ * @param textA The first text.
42
+ * @param textB The second text.
43
+ * @returns The Levenshtein distance.
44
+ */
45
+ function calculateLevenshteinDistance(textA, textB) {
46
+ const lenA = textA.length;
47
+ const lenB = textB.length;
48
+ if (lenA === 0) {
49
+ return lenB;
50
+ }
51
+ if (lenB === 0) {
52
+ return lenA;
53
+ }
54
+ const distancesMatrix = prepareDistanceMatrix(lenA, lenB);
55
+ for (let i = 1; i <= lenA; i++) {
56
+ for (let j = 1; j <= lenB; j++) {
57
+ distancesMatrix[i][j] = applyBasicEditOperations(i, j, textA, textB, distancesMatrix);
58
+ }
59
+ }
60
+ return distancesMatrix[lenA][lenB];
61
+ }
62
+ /**
63
+ * Calculates the Damerau-Levenshtein distance between two texts.
64
+ * @param textA The first text.
65
+ * @param textB The second text.
66
+ * @returns The Damerau-Levenshtein distance.
67
+ */
68
+ function calculateDamerauLevenshteinDistance(textA, textB) {
69
+ const lenA = textA.length;
70
+ const lenB = textB.length;
71
+ if (lenA === 0) {
72
+ return lenB;
73
+ }
74
+ if (lenB === 0) {
75
+ return lenA;
76
+ }
77
+ const distancesMatrix = prepareDistanceMatrix(lenA, lenB);
78
+ for (let i = 1; i <= lenA; i++) {
79
+ for (let j = 1; j <= lenB; j++) {
80
+ distancesMatrix[i][j] = applyBasicEditOperations(i, j, textA, textB, distancesMatrix);
81
+ if (i > 1 && j > 1 && textA[i - 1] === textB[j - 2] && textA[i - 2] === textB[j - 1]) {
82
+ distancesMatrix[i][j] = Math.min(distancesMatrix[i][j], distancesMatrix[i - 2][j - 2] + 1);
83
+ }
84
+ }
85
+ }
86
+ return distancesMatrix[lenA][lenB];
87
+ }
88
+ /**
89
+ * Prepares a distance matrix for edit distance calculations.
90
+ * @param lenA Length of the first text.
91
+ * @param lenB Length of the second text.
92
+ * @returns A 2D array representing the distance matrix.
93
+ */
94
+ function prepareDistanceMatrix(lenA, lenB) {
95
+ const distancesMatrix = Array.from({ length: lenA + 1 }, () => Array(lenB + 1).fill(0));
96
+ for (let i = 0; i <= lenA; i++) {
97
+ distancesMatrix[i][0] = i;
98
+ }
99
+ for (let j = 0; j <= lenB; j++) {
100
+ distancesMatrix[0][j] = j;
101
+ }
102
+ return distancesMatrix;
103
+ }
104
+ /**
105
+ * Applies basic edit operations (deletion, insertion, substitution) for edit distance algorithms.
106
+ * @param i Current row index in the matrix.
107
+ * @param j Current column index in the matrix.
108
+ * @param textA The first text.
109
+ * @param textB The second text.
110
+ * @param matrix The distance matrix.
111
+ * @returns The minimum cost for the current cell.
112
+ */
113
+ function applyBasicEditOperations(i, j, textA, textB, matrix) {
114
+ const cost = textA[i - 1] === textB[j - 1] ? 0 : 1;
115
+ return Math.min(matrix[i - 1][j] + 1, // Deletion
116
+ matrix[i][j - 1] + 1, // Insertion
117
+ matrix[i - 1][j - 1] + cost // Substitution
118
+ );
119
+ }
120
+ /////////////////////////////////////////
121
+ //// Validation Functions
122
+ /////////////////////////////////////////
123
+ /**
124
+ * Checks if a value is a string.
125
+ * @param value The value to check.
126
+ * @returns True if the value is a string, otherwise false.
127
+ */
128
+ function isString(value) {
129
+ return typeof value === 'string';
130
+ }
131
+ /**
132
+ * Validates the input parameters for the string similarity functions.
133
+ * @param textA The first text.
134
+ * @param textB The second text.
135
+ * @param algorithm The algorithm to use.
136
+ * @throws Error if parameters are invalid.
137
+ */
138
+ function validateParams(textA, textB, algorithm) {
139
+ if (!isString(textA) || !isString(textB)) {
140
+ throw new Error('Both text arguments must be strings');
141
+ }
142
+ if (algorithm !== 'Levenshtein' && algorithm !== 'Damerau-Levenshtein') {
143
+ throw new Error("Invalid optional algorithm param. Should be 'Levenshtein' or 'Damerau-Levenshtein'");
144
+ }
145
+ }
@@ -0,0 +1 @@
1
+ export declare function wordCount(str: string): number;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.wordCount = wordCount;
4
+ function wordCount(str) {
5
+ if (typeof str !== "string") {
6
+ throw new TypeError("Input must be a string");
7
+ }
8
+ if (!str.trim())
9
+ return 0;
10
+ return str.trim().split(/\s+/).length;
11
+ }
@@ -0,0 +1 @@
1
+ export declare function capitalize(str: string): string;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.capitalize = capitalize;
4
+ function capitalize(str) {
5
+ if (typeof str !== 'string') {
6
+ throw new TypeError('Input must be a string');
7
+ }
8
+ return str
9
+ .split(' ')
10
+ .map(word => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())
11
+ .join(' ');
12
+ }
@@ -0,0 +1,11 @@
1
+ export { capitalize } from "./capitalize";
2
+ export { formatNumber } from "./number";
3
+ export { formatPhone } from "./phone";
4
+ import { capitalize } from "./capitalize";
5
+ import { formatNumber } from "./number";
6
+ import { formatPhone } from "./phone";
7
+ export declare const formatting: {
8
+ capitalize: typeof capitalize;
9
+ formatNumber: typeof formatNumber;
10
+ formatPhone: typeof formatPhone;
11
+ };
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.formatting = exports.formatPhone = exports.formatNumber = exports.capitalize = void 0;
4
+ var capitalize_1 = require("./capitalize");
5
+ Object.defineProperty(exports, "capitalize", { enumerable: true, get: function () { return capitalize_1.capitalize; } });
6
+ var number_1 = require("./number");
7
+ Object.defineProperty(exports, "formatNumber", { enumerable: true, get: function () { return number_1.formatNumber; } });
8
+ var phone_1 = require("./phone");
9
+ Object.defineProperty(exports, "formatPhone", { enumerable: true, get: function () { return phone_1.formatPhone; } });
10
+ const capitalize_2 = require("./capitalize");
11
+ const number_2 = require("./number");
12
+ const phone_2 = require("./phone");
13
+ exports.formatting = {
14
+ capitalize: capitalize_2.capitalize,
15
+ formatNumber: number_2.formatNumber,
16
+ formatPhone: phone_2.formatPhone,
17
+ };
@@ -0,0 +1 @@
1
+ export declare function formatNumber(num: string | number, thousendsSeperator?: '.' | ','): string;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.formatNumber = formatNumber;
4
+ function formatNumber(num, thousendsSeperator = ",") {
5
+ const numStr = num.toString();
6
+ return numStr.replace(/\B(?=(\d{3})+(?!\d))/g, thousendsSeperator);
7
+ }
@@ -0,0 +1,2 @@
1
+ export type PhoneFormat = 'us' | 'in' | 'international';
2
+ export declare function formatPhone(phone: string, format?: PhoneFormat): string;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.formatPhone = formatPhone;
4
+ function formatPhone(phone, format = 'us') {
5
+ const digits = phone.replace(/\D/g, '');
6
+ if (format === 'us' && digits.length === 10) {
7
+ return `(${digits.slice(0, 3)}) ${digits.slice(3, 6)}-${digits.slice(6)}`;
8
+ }
9
+ else if (format === 'international' && digits.length >= 10) {
10
+ const countryCode = digits.slice(0, -10);
11
+ const areaCode = digits.slice(-10, -7);
12
+ const firstPart = digits.slice(-7, -4);
13
+ const lastPart = digits.slice(-4);
14
+ return `+${countryCode} (${areaCode}) ${firstPart}-${lastPart}`;
15
+ }
16
+ else if (format === 'in') {
17
+ if (digits.length === 10) {
18
+ return `+91-${digits.slice(0, 5)}-${digits.slice(5)}`;
19
+ }
20
+ else if (digits.length === 12 && digits.startsWith('91')) {
21
+ return `+91-${digits.slice(2, 7)}-${digits.slice(7)}`;
22
+ }
23
+ }
24
+ return phone;
25
+ }