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.
- package/.github/workflows/publish.yml +29 -0
- package/.github/workflows/test-on-pr.yml +23 -0
- package/.prettierignore +4 -0
- package/.prettierrc +7 -0
- package/CONTRIBUTING.md +99 -0
- package/LICENSE +21 -21
- package/README.md +1189 -723
- package/changelog.txt +110 -110
- package/dist/analyzing/characterCount.d.ts +20 -0
- package/dist/analyzing/characterCount.js +28 -0
- package/dist/analyzing/characterFrequency.d.ts +20 -0
- package/dist/analyzing/characterFrequency.js +35 -0
- package/dist/analyzing/complexity.d.ts +39 -0
- package/dist/analyzing/complexity.js +63 -0
- package/dist/analyzing/index.d.ts +26 -0
- package/dist/analyzing/index.js +37 -0
- package/dist/analyzing/patternCount.d.ts +10 -0
- package/dist/analyzing/patternCount.js +52 -0
- package/dist/analyzing/readingDuration.d.ts +10 -0
- package/dist/analyzing/readingDuration.js +17 -0
- package/dist/analyzing/stringSimilarity.d.ts +8 -0
- package/dist/analyzing/stringSimilarity.js +145 -0
- package/dist/analyzing/vowelConsonantCount.d.ts +22 -0
- package/dist/analyzing/vowelConsonantCount.js +38 -0
- package/dist/analyzing/wordCount.d.ts +23 -0
- package/dist/analyzing/wordCount.js +33 -0
- package/dist/formatting/capitalize.d.ts +22 -0
- package/dist/formatting/capitalize.js +33 -0
- package/dist/formatting/index.d.ts +11 -0
- package/dist/formatting/index.js +17 -0
- package/dist/formatting/number.d.ts +24 -0
- package/dist/formatting/number.js +30 -0
- package/dist/formatting/phone.d.ts +25 -0
- package/dist/formatting/phone.js +48 -0
- package/dist/index.d.ts +52 -0
- package/dist/index.js +30 -0
- package/dist/tests/analyzing/characterCount.test.d.ts +1 -0
- package/dist/tests/analyzing/characterCount.test.js +19 -0
- package/dist/tests/analyzing/characterFrequency.test.d.ts +1 -0
- package/dist/tests/analyzing/characterFrequency.test.js +22 -0
- package/dist/tests/analyzing/complexity.test.d.ts +1 -0
- package/dist/tests/analyzing/complexity.test.js +28 -0
- package/dist/tests/analyzing/patternCount.test.d.ts +1 -0
- package/dist/tests/analyzing/patternCount.test.js +34 -0
- package/dist/tests/analyzing/readingDuration.test.d.ts +1 -0
- package/dist/tests/analyzing/readingDuration.test.js +45 -0
- package/dist/tests/analyzing/stringSimilarity.test.d.ts +1 -0
- package/dist/tests/analyzing/stringSimilarity.test.js +61 -0
- package/dist/tests/analyzing/vowelConsonantCount.test.d.ts +1 -0
- package/dist/tests/analyzing/vowelConsonantCount.test.js +25 -0
- package/dist/tests/analyzing/wordCount.test.d.ts +1 -0
- package/dist/tests/analyzing/wordCount.test.js +22 -0
- package/dist/tests/formatting/capitalize.test.d.ts +1 -0
- package/dist/tests/formatting/capitalize.test.js +22 -0
- package/dist/tests/formatting/number.test.d.ts +1 -0
- package/dist/tests/formatting/number.test.js +19 -0
- package/dist/tests/formatting/phone.test.d.ts +1 -0
- package/dist/tests/formatting/phone.test.js +25 -0
- package/dist/tests/transformations/camelCase.test.d.ts +1 -0
- package/dist/tests/transformations/camelCase.test.js +19 -0
- package/dist/tests/transformations/capitalizeWords.test.d.ts +1 -0
- package/dist/tests/transformations/capitalizeWords.test.js +19 -0
- package/dist/tests/transformations/constantCase.test.d.ts +1 -0
- package/dist/tests/transformations/constantCase.test.js +19 -0
- package/dist/tests/transformations/deburr.test.d.ts +1 -0
- package/dist/tests/transformations/deburr.test.js +27 -0
- package/dist/tests/transformations/escapeHTML.test.d.ts +1 -0
- package/dist/tests/transformations/escapeHTML.test.js +46 -0
- package/dist/tests/transformations/initials.test.d.ts +1 -0
- package/dist/tests/transformations/initials.test.js +25 -0
- package/dist/tests/transformations/kebabCase.test.d.ts +1 -0
- package/dist/tests/transformations/kebabCase.test.js +19 -0
- package/dist/tests/transformations/maskSegment.test.d.ts +1 -0
- package/dist/tests/transformations/maskSegment.test.js +30 -0
- package/dist/tests/transformations/numberToText.test.d.ts +1 -0
- package/dist/tests/transformations/numberToText.test.js +60 -0
- package/dist/tests/transformations/pascalCase.test.d.ts +1 -0
- package/dist/tests/transformations/pascalCase.test.js +19 -0
- package/dist/tests/transformations/removeDuplicates.test.d.ts +1 -0
- package/dist/tests/transformations/removeDuplicates.test.js +19 -0
- package/dist/tests/transformations/removeSpecialChars.test.d.ts +1 -0
- package/dist/tests/transformations/removeSpecialChars.test.js +22 -0
- package/dist/tests/transformations/removeWords.test.d.ts +1 -0
- package/dist/tests/transformations/removeWords.test.js +25 -0
- package/dist/tests/transformations/snakeCase.test.d.ts +1 -0
- package/dist/tests/transformations/snakeCase.test.js +19 -0
- package/dist/tests/transformations/splitChunks.test.d.ts +1 -0
- package/dist/tests/transformations/splitChunks.test.js +31 -0
- package/dist/tests/transformations/titleCase.test.d.ts +1 -0
- package/dist/tests/transformations/titleCase.test.js +19 -0
- package/dist/tests/transformations/toSlug.test.d.ts +1 -0
- package/dist/tests/transformations/toSlug.test.js +22 -0
- package/dist/tests/transformations/truncateText.test.d.ts +1 -0
- package/dist/tests/transformations/truncateText.test.js +31 -0
- package/dist/tests/validations/isCoordinates.test.d.ts +1 -0
- package/dist/tests/validations/isCoordinates.test.js +18 -0
- package/dist/tests/validations/isDate.test.d.ts +1 -0
- package/dist/tests/validations/isDate.test.js +55 -0
- package/dist/tests/validations/isEmail.smtpUTF8.test.d.ts +1 -0
- package/dist/tests/validations/isEmail.smtpUTF8.test.js +16 -0
- package/dist/tests/validations/isEmail.test.d.ts +1 -0
- package/dist/tests/validations/isEmail.test.js +67 -0
- package/dist/tests/validations/isEmpty.test.d.ts +1 -0
- package/dist/tests/validations/isEmpty.test.js +19 -0
- package/dist/tests/validations/isHexColor.test.d.ts +1 -0
- package/dist/tests/validations/isHexColor.test.js +32 -0
- package/dist/tests/validations/isIPv4.test.d.ts +1 -0
- package/dist/tests/validations/isIPv4.test.js +59 -0
- package/dist/tests/validations/isPalindrome.test.d.ts +1 -0
- package/dist/tests/validations/isPalindrome.test.js +39 -0
- package/dist/tests/validations/isSlug.test.d.ts +1 -0
- package/dist/tests/validations/isSlug.test.js +22 -0
- package/dist/tests/validations/isTypeOf.test.d.ts +1 -0
- package/dist/tests/validations/isTypeOf.test.js +28 -0
- package/dist/tests/validations/isURL.test.d.ts +1 -0
- package/dist/tests/validations/isURL.test.js +18 -0
- package/dist/transformations/camelCase.d.ts +25 -0
- package/dist/transformations/camelCase.js +39 -0
- package/dist/transformations/capitalizeWords.d.ts +22 -0
- package/dist/transformations/capitalizeWords.js +30 -0
- package/dist/transformations/constantCase.d.ts +27 -0
- package/dist/transformations/constantCase.js +41 -0
- package/dist/transformations/deburr.d.ts +7 -0
- package/dist/transformations/deburr.js +16 -0
- package/dist/transformations/escapeHTML.d.ts +24 -0
- package/dist/transformations/escapeHTML.js +36 -0
- package/dist/transformations/index.d.ts +52 -0
- package/dist/transformations/index.js +71 -0
- package/dist/transformations/initials.d.ts +28 -0
- package/dist/transformations/initials.js +49 -0
- package/dist/transformations/kebabCase.d.ts +27 -0
- package/dist/transformations/kebabCase.js +41 -0
- package/dist/transformations/maskSegment.d.ts +9 -0
- package/dist/transformations/maskSegment.js +23 -0
- package/dist/transformations/numberToText/helpers.d.ts +10 -0
- package/dist/transformations/numberToText/helpers.js +31 -0
- package/dist/transformations/numberToText/implementation_EN.d.ts +10 -0
- package/dist/transformations/numberToText/implementation_EN.js +45 -0
- package/dist/transformations/numberToText/implementation_PL.d.ts +10 -0
- package/dist/transformations/numberToText/implementation_PL.js +79 -0
- package/dist/transformations/numberToText/main.d.ts +19 -0
- package/dist/transformations/numberToText/main.js +67 -0
- package/dist/transformations/numberToText/types.d.ts +3 -0
- package/dist/transformations/numberToText/types.js +82 -0
- package/dist/transformations/pascalCase.d.ts +26 -0
- package/dist/transformations/pascalCase.js +40 -0
- package/dist/transformations/removeDuplicates.d.ts +22 -0
- package/dist/transformations/removeDuplicates.js +34 -0
- package/dist/transformations/removeSpecialChars.d.ts +23 -0
- package/dist/transformations/removeSpecialChars.js +34 -0
- package/dist/transformations/removeWords.d.ts +28 -0
- package/dist/transformations/removeWords.js +50 -0
- package/dist/transformations/snakeCase.d.ts +27 -0
- package/dist/transformations/snakeCase.js +41 -0
- package/dist/transformations/splitChunks.d.ts +8 -0
- package/dist/transformations/splitChunks.js +24 -0
- package/dist/transformations/titleCase.d.ts +26 -0
- package/dist/transformations/titleCase.js +39 -0
- package/dist/transformations/toSlug.d.ts +25 -0
- package/dist/transformations/toSlug.js +37 -0
- package/dist/transformations/truncateText.d.ts +26 -0
- package/dist/transformations/truncateText.js +44 -0
- package/dist/validations/index.d.ts +29 -0
- package/dist/validations/index.js +41 -0
- package/dist/validations/isCoordinates.d.ts +8 -0
- package/dist/validations/isCoordinates.js +19 -0
- package/dist/validations/isDate.d.ts +18 -0
- package/dist/validations/isDate.js +61 -0
- package/dist/validations/isEmail.d.ts +13 -0
- package/dist/validations/isEmail.js +180 -0
- package/dist/validations/isEmpty.d.ts +10 -0
- package/dist/validations/isEmpty.js +15 -0
- package/dist/validations/isHexColor.d.ts +7 -0
- package/dist/validations/isHexColor.js +15 -0
- package/dist/validations/isIPv4.d.ts +22 -0
- package/dist/validations/isIPv4.js +33 -0
- package/dist/validations/isPalindrome.d.ts +10 -0
- package/dist/validations/isPalindrome.js +21 -0
- package/dist/validations/isSlug.d.ts +28 -0
- package/dist/validations/isSlug.js +37 -0
- package/dist/validations/isTypeOf.d.ts +9 -0
- package/dist/validations/isTypeOf.js +30 -0
- package/dist/validations/isURL.d.ts +22 -0
- package/dist/validations/isURL.js +33 -0
- package/package.json +12 -4
- package/analysis.js +0 -21
- package/formatting.js +0 -37
- package/index.js +0 -75
- package/transformations.js +0 -190
- package/validations.js +0 -80
|
@@ -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,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns the number of vowels and consonants in a given string.
|
|
3
|
+
*
|
|
4
|
+
* This function counts the number of vowels and consonants in the string, ignoring 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 vowels and consonants will be counted.
|
|
8
|
+
* @returns {{ vowels: number, consonants: number }} An object containing the counts of vowels and consonants.
|
|
9
|
+
* @throws {TypeError} If the input is not of type string
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* vowelConsonantCount("hello");
|
|
13
|
+
* // { vowels: 2, consonants: 3 }
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* vowelConsonantCount("stringzy");
|
|
17
|
+
* // { vowels: 1, consonants: 7 }
|
|
18
|
+
*/
|
|
19
|
+
export declare function vowelConsonantCount(str: string): {
|
|
20
|
+
vowels: number;
|
|
21
|
+
consonants: number;
|
|
22
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.vowelConsonantCount = vowelConsonantCount;
|
|
4
|
+
/**
|
|
5
|
+
* Returns the number of vowels and consonants in a given string.
|
|
6
|
+
*
|
|
7
|
+
* This function counts the number of vowels and consonants in the string, ignoring 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 vowels and consonants will be counted.
|
|
11
|
+
* @returns {{ vowels: number, consonants: number }} An object containing the counts of vowels and consonants.
|
|
12
|
+
* @throws {TypeError} If the input is not of type string
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* vowelConsonantCount("hello");
|
|
16
|
+
* // { vowels: 2, consonants: 3 }
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* vowelConsonantCount("stringzy");
|
|
20
|
+
* // { vowels: 1, consonants: 7 }
|
|
21
|
+
*/
|
|
22
|
+
function vowelConsonantCount(str) {
|
|
23
|
+
if (typeof str !== 'string') {
|
|
24
|
+
throw new TypeError('Input must be a string');
|
|
25
|
+
}
|
|
26
|
+
const vowels = 'aeiouAEIOU';
|
|
27
|
+
let vowelCount = 0;
|
|
28
|
+
let consonantCount = 0;
|
|
29
|
+
for (const char of str) {
|
|
30
|
+
if (vowels.includes(char)) {
|
|
31
|
+
vowelCount++;
|
|
32
|
+
}
|
|
33
|
+
else if (char.toLowerCase() >= 'a' && char.toLowerCase() <= 'z') {
|
|
34
|
+
consonantCount++;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return { vowels: vowelCount, consonants: consonantCount };
|
|
38
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Counts the number of words in a given string.
|
|
3
|
+
*
|
|
4
|
+
* Words are defined as sequences of non-whitespace characters separated by one or more
|
|
5
|
+
* whitespace characters (spaces, tabs, newlines, etc.). Leading and trailing whitespace
|
|
6
|
+
* is trimmed before counting.
|
|
7
|
+
*
|
|
8
|
+
* Throws a `TypeError` if the input is not a string.
|
|
9
|
+
*
|
|
10
|
+
* @param {string} str - The string to analyze.
|
|
11
|
+
* @returns {number} The number of words in the input string.
|
|
12
|
+
* @throws {TypeError} If the input is not a string.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* wordCount("Hello world"); // 2
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* wordCount(" This is a test\nwith multiple lines "); // 7
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* wordCount(" "); // 0
|
|
22
|
+
*/
|
|
23
|
+
export declare function wordCount(str: string): number;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.wordCount = wordCount;
|
|
4
|
+
/**
|
|
5
|
+
* Counts the number of words in a given string.
|
|
6
|
+
*
|
|
7
|
+
* Words are defined as sequences of non-whitespace characters separated by one or more
|
|
8
|
+
* whitespace characters (spaces, tabs, newlines, etc.). Leading and trailing whitespace
|
|
9
|
+
* is trimmed before counting.
|
|
10
|
+
*
|
|
11
|
+
* Throws a `TypeError` if the input is not a string.
|
|
12
|
+
*
|
|
13
|
+
* @param {string} str - The string to analyze.
|
|
14
|
+
* @returns {number} The number of words in the input string.
|
|
15
|
+
* @throws {TypeError} If the input is not a string.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* wordCount("Hello world"); // 2
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* wordCount(" This is a test\nwith multiple lines "); // 7
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* wordCount(" "); // 0
|
|
25
|
+
*/
|
|
26
|
+
function wordCount(str) {
|
|
27
|
+
if (typeof str !== 'string') {
|
|
28
|
+
throw new TypeError('Input must be a string');
|
|
29
|
+
}
|
|
30
|
+
if (!str.trim())
|
|
31
|
+
return 0;
|
|
32
|
+
return str.trim().split(/\s+/).length;
|
|
33
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Capitalizes the first letter of each word in a string.
|
|
3
|
+
*
|
|
4
|
+
* Converts the first character of each word to uppercase and the remaining characters to lowercase.
|
|
5
|
+
* Words are assumed to be separated by spaces. Handles multiple words and mixed casing.
|
|
6
|
+
*
|
|
7
|
+
* Throws a `TypeError` if the input is not a string.
|
|
8
|
+
*
|
|
9
|
+
* @param {string} str - The input string to capitalize.
|
|
10
|
+
* @returns {string} A new string with each word capitalized.
|
|
11
|
+
* @throws {TypeError} If the input is not a string.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* capitalize("hello world"); // "Hello World"
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* capitalize("mIxEd CaSe tExT"); // "Mixed Case Text"
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* capitalize(" multiple spaces "); // "Multiple Spaces"
|
|
21
|
+
*/
|
|
22
|
+
export declare function capitalize(str: string): string;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.capitalize = capitalize;
|
|
4
|
+
/**
|
|
5
|
+
* Capitalizes the first letter of each word in a string.
|
|
6
|
+
*
|
|
7
|
+
* Converts the first character of each word to uppercase and the remaining characters to lowercase.
|
|
8
|
+
* Words are assumed to be separated by spaces. Handles multiple words and mixed casing.
|
|
9
|
+
*
|
|
10
|
+
* Throws a `TypeError` if the input is not a string.
|
|
11
|
+
*
|
|
12
|
+
* @param {string} str - The input string to capitalize.
|
|
13
|
+
* @returns {string} A new string with each word capitalized.
|
|
14
|
+
* @throws {TypeError} If the input is not a string.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* capitalize("hello world"); // "Hello World"
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* capitalize("mIxEd CaSe tExT"); // "Mixed Case Text"
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* capitalize(" multiple spaces "); // "Multiple Spaces"
|
|
24
|
+
*/
|
|
25
|
+
function capitalize(str) {
|
|
26
|
+
if (typeof str !== 'string') {
|
|
27
|
+
throw new TypeError('Input must be a string');
|
|
28
|
+
}
|
|
29
|
+
return str
|
|
30
|
+
.split(' ')
|
|
31
|
+
.map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())
|
|
32
|
+
.join(' ');
|
|
33
|
+
}
|
|
@@ -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,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Formats a number with a thousands separator.
|
|
3
|
+
*
|
|
4
|
+
* Converts a number or numeric string into a more readable format by inserting the specified
|
|
5
|
+
* thousands separator (either `','` or `'.'`). This function does not round or localize
|
|
6
|
+
* decimals — it only adds the separator between every three digits from the right.
|
|
7
|
+
*
|
|
8
|
+
* The input is first converted to a string before formatting. If the input is not a valid
|
|
9
|
+
* number or numeric string, the output may be incorrect.
|
|
10
|
+
*
|
|
11
|
+
* @param {string | number} num - The number or numeric string to format.
|
|
12
|
+
* @param {'.' | ','} [thousendsSeperator=','] - The character to use as the thousands separator.
|
|
13
|
+
* @returns {string} The formatted string with the separator added.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* formatNumber(1234567); // "1,234,567"
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* formatNumber("987654321", '.'); // "987.654.321"
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* formatNumber(12345.67); // "12,345.67" (decimals preserved as-is)
|
|
23
|
+
*/
|
|
24
|
+
export declare function formatNumber(num: string | number, thousendsSeperator?: '.' | ','): string;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.formatNumber = formatNumber;
|
|
4
|
+
/**
|
|
5
|
+
* Formats a number with a thousands separator.
|
|
6
|
+
*
|
|
7
|
+
* Converts a number or numeric string into a more readable format by inserting the specified
|
|
8
|
+
* thousands separator (either `','` or `'.'`). This function does not round or localize
|
|
9
|
+
* decimals — it only adds the separator between every three digits from the right.
|
|
10
|
+
*
|
|
11
|
+
* The input is first converted to a string before formatting. If the input is not a valid
|
|
12
|
+
* number or numeric string, the output may be incorrect.
|
|
13
|
+
*
|
|
14
|
+
* @param {string | number} num - The number or numeric string to format.
|
|
15
|
+
* @param {'.' | ','} [thousendsSeperator=','] - The character to use as the thousands separator.
|
|
16
|
+
* @returns {string} The formatted string with the separator added.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* formatNumber(1234567); // "1,234,567"
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* formatNumber("987654321", '.'); // "987.654.321"
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* formatNumber(12345.67); // "12,345.67" (decimals preserved as-is)
|
|
26
|
+
*/
|
|
27
|
+
function formatNumber(num, thousendsSeperator = ',') {
|
|
28
|
+
const numStr = num.toString();
|
|
29
|
+
return numStr.replace(/\B(?=(\d{3})+(?!\d))/g, thousendsSeperator);
|
|
30
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export type PhoneFormat = 'us' | 'in' | 'international';
|
|
2
|
+
/**
|
|
3
|
+
* Formats a phone number string into a readable format based on the given region.
|
|
4
|
+
*
|
|
5
|
+
* Strips all non-digit characters before formatting. Supports formatting for:
|
|
6
|
+
* - `'us'`: U.S. numbers with 10 digits → `(123) 456-7890`
|
|
7
|
+
* - `'in'`: Indian numbers with 10 digits or 12 digits starting with '91' → `+91-12345-67890`
|
|
8
|
+
* - `'international'`: Generic international format assuming last 10 digits are the local number.
|
|
9
|
+
*
|
|
10
|
+
* If the number does not match expected formats, it returns the original input.
|
|
11
|
+
*
|
|
12
|
+
* @param {string} phone - The phone number string to format.
|
|
13
|
+
* @param {PhoneFormat} [format='us'] - The desired formatting style: `'us'`, `'in'`, or `'international'`.
|
|
14
|
+
* @returns {string} The formatted phone number, or the original input if formatting fails.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* formatPhone("1234567890"); // "(123) 456-7890"
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* formatPhone("+91 9876543210", "in"); // "+91-98765-43210"
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* formatPhone("009199876543210", "international"); // "+0091 (998) 765-43210"
|
|
24
|
+
*/
|
|
25
|
+
export declare function formatPhone(phone: string, format?: PhoneFormat): string;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.formatPhone = formatPhone;
|
|
4
|
+
/**
|
|
5
|
+
* Formats a phone number string into a readable format based on the given region.
|
|
6
|
+
*
|
|
7
|
+
* Strips all non-digit characters before formatting. Supports formatting for:
|
|
8
|
+
* - `'us'`: U.S. numbers with 10 digits → `(123) 456-7890`
|
|
9
|
+
* - `'in'`: Indian numbers with 10 digits or 12 digits starting with '91' → `+91-12345-67890`
|
|
10
|
+
* - `'international'`: Generic international format assuming last 10 digits are the local number.
|
|
11
|
+
*
|
|
12
|
+
* If the number does not match expected formats, it returns the original input.
|
|
13
|
+
*
|
|
14
|
+
* @param {string} phone - The phone number string to format.
|
|
15
|
+
* @param {PhoneFormat} [format='us'] - The desired formatting style: `'us'`, `'in'`, or `'international'`.
|
|
16
|
+
* @returns {string} The formatted phone number, or the original input if formatting fails.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* formatPhone("1234567890"); // "(123) 456-7890"
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* formatPhone("+91 9876543210", "in"); // "+91-98765-43210"
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* formatPhone("009199876543210", "international"); // "+0091 (998) 765-43210"
|
|
26
|
+
*/
|
|
27
|
+
function formatPhone(phone, format = 'us') {
|
|
28
|
+
const digits = phone.replace(/\D/g, '');
|
|
29
|
+
if (format === 'us' && digits.length === 10) {
|
|
30
|
+
return `(${digits.slice(0, 3)}) ${digits.slice(3, 6)}-${digits.slice(6)}`;
|
|
31
|
+
}
|
|
32
|
+
else if (format === 'international' && digits.length >= 10) {
|
|
33
|
+
const countryCode = digits.slice(0, -10);
|
|
34
|
+
const areaCode = digits.slice(-10, -7);
|
|
35
|
+
const firstPart = digits.slice(-7, -4);
|
|
36
|
+
const lastPart = digits.slice(-4);
|
|
37
|
+
return `+${countryCode} (${areaCode}) ${firstPart}-${lastPart}`;
|
|
38
|
+
}
|
|
39
|
+
else if (format === 'in') {
|
|
40
|
+
if (digits.length === 10) {
|
|
41
|
+
return `+91-${digits.slice(0, 5)}-${digits.slice(5)}`;
|
|
42
|
+
}
|
|
43
|
+
else if (digits.length === 12 && digits.startsWith('91')) {
|
|
44
|
+
return `+91-${digits.slice(2, 7)}-${digits.slice(7)}`;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return phone;
|
|
48
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
export * from './analyzing';
|
|
2
|
+
export * from './formatting';
|
|
3
|
+
export * from './transformations';
|
|
4
|
+
export * from './validations';
|
|
5
|
+
declare const _default: {
|
|
6
|
+
analyzing: {
|
|
7
|
+
characterCount: typeof import("./analyzing").characterCount;
|
|
8
|
+
characterFrequency: typeof import("./analyzing").characterFrequency;
|
|
9
|
+
complexity: typeof import("./analyzing").complexity;
|
|
10
|
+
readingDuration: typeof import("./analyzing").readingDuration;
|
|
11
|
+
wordCount: typeof import("./analyzing").wordCount;
|
|
12
|
+
stringSimilarity: typeof import("./analyzing").stringSimilarity;
|
|
13
|
+
patternCount: typeof import("./analyzing").patternCount;
|
|
14
|
+
vowelConsonantCount: typeof import("./analyzing").vowelConsonantCount;
|
|
15
|
+
};
|
|
16
|
+
formatting: {
|
|
17
|
+
capitalize: typeof import("./formatting").capitalize;
|
|
18
|
+
formatNumber: typeof import("./formatting").formatNumber;
|
|
19
|
+
formatPhone: typeof import("./formatting").formatPhone;
|
|
20
|
+
};
|
|
21
|
+
transformations: {
|
|
22
|
+
camelCase: typeof import("./transformations").camelCase;
|
|
23
|
+
capitalizeWords: typeof import("./transformations").capitalizeWords;
|
|
24
|
+
constantCase: typeof import("./transformations").constantCase;
|
|
25
|
+
initials: typeof import("./transformations").initials;
|
|
26
|
+
kebabCase: typeof import("./transformations").kebabCase;
|
|
27
|
+
pascalCase: typeof import("./transformations").pascalCase;
|
|
28
|
+
removeDuplicates: typeof import("./transformations").removeDuplicates;
|
|
29
|
+
removeSpecialChars: typeof import("./transformations").removeSpecialChars;
|
|
30
|
+
removeWords: typeof import("./transformations").removeWords;
|
|
31
|
+
snakeCase: typeof import("./transformations").snakeCase;
|
|
32
|
+
titleCase: typeof import("./transformations").titleCase;
|
|
33
|
+
toSlug: typeof import("./transformations").toSlug;
|
|
34
|
+
truncateText: typeof import("./transformations").truncateText;
|
|
35
|
+
escapeHtml: typeof import("./transformations").escapeHtml;
|
|
36
|
+
maskSegment: typeof import("./transformations").maskSegment;
|
|
37
|
+
deburr: typeof import("./transformations/deburr").deburr;
|
|
38
|
+
numberToText: typeof import("./transformations").numberToText;
|
|
39
|
+
};
|
|
40
|
+
validations: {
|
|
41
|
+
isCoordinates: typeof import("./validations").isCoordinates;
|
|
42
|
+
isDate: typeof import("./validations").isDate;
|
|
43
|
+
isEmail: typeof import("./validations").isEmail;
|
|
44
|
+
isEmpty: typeof import("./validations").isEmpty;
|
|
45
|
+
isSlug: typeof import("./validations").isSlug;
|
|
46
|
+
isURL: typeof import("./validations").isURL;
|
|
47
|
+
isIPv4: typeof import("./validations").isIPv4;
|
|
48
|
+
isHexColor: typeof import("./validations").isHexColor;
|
|
49
|
+
isPalindrome: typeof import("./validations").isPalindrome;
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
export default _default;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./analyzing"), exports);
|
|
18
|
+
__exportStar(require("./formatting"), exports);
|
|
19
|
+
__exportStar(require("./transformations"), exports);
|
|
20
|
+
__exportStar(require("./validations"), exports);
|
|
21
|
+
const analyzing_1 = require("./analyzing");
|
|
22
|
+
const formatting_1 = require("./formatting");
|
|
23
|
+
const transformations_1 = require("./transformations");
|
|
24
|
+
const validations_1 = require("./validations");
|
|
25
|
+
exports.default = {
|
|
26
|
+
analyzing: analyzing_1.analyzing,
|
|
27
|
+
formatting: formatting_1.formatting,
|
|
28
|
+
transformations: transformations_1.transformations,
|
|
29
|
+
validations: validations_1.validations,
|
|
30
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
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 characterCount_1 = require("../../analyzing/characterCount");
|
|
9
|
+
(0, node_test_1.describe)('characterCount', () => {
|
|
10
|
+
(0, node_test_1.it)('returns length of string', () => {
|
|
11
|
+
node_assert_1.default.strictEqual((0, characterCount_1.characterCount)('hello'), 5);
|
|
12
|
+
});
|
|
13
|
+
(0, node_test_1.it)('returns 0 for empty string', () => {
|
|
14
|
+
node_assert_1.default.strictEqual((0, characterCount_1.characterCount)(''), 0);
|
|
15
|
+
});
|
|
16
|
+
(0, node_test_1.it)('throws if input is not a string', () => {
|
|
17
|
+
node_assert_1.default.throws(() => (0, characterCount_1.characterCount)(123), /Input must be a string/);
|
|
18
|
+
});
|
|
19
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
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 characterFrequency_1 = require("../../analyzing/characterFrequency");
|
|
9
|
+
(0, node_test_1.describe)('characterFrequency', () => {
|
|
10
|
+
(0, node_test_1.it)('returns frequency of each character', () => {
|
|
11
|
+
node_assert_1.default.deepStrictEqual((0, characterFrequency_1.characterFrequency)('aab'), { a: 2, b: 1 });
|
|
12
|
+
});
|
|
13
|
+
(0, node_test_1.it)('ignores spaces', () => {
|
|
14
|
+
node_assert_1.default.deepStrictEqual((0, characterFrequency_1.characterFrequency)('a a b'), { a: 2, b: 1 });
|
|
15
|
+
});
|
|
16
|
+
(0, node_test_1.it)('returns empty object for empty string', () => {
|
|
17
|
+
node_assert_1.default.deepStrictEqual((0, characterFrequency_1.characterFrequency)(''), {});
|
|
18
|
+
});
|
|
19
|
+
(0, node_test_1.it)('throws if input is not a string', () => {
|
|
20
|
+
node_assert_1.default.throws(() => (0, characterFrequency_1.characterFrequency)(123), /Input must be a string/);
|
|
21
|
+
});
|
|
22
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
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 complexity_1 = require("../../analyzing/complexity");
|
|
9
|
+
(0, node_test_1.describe)('complexity', () => {
|
|
10
|
+
(0, node_test_1.it)('returns 0s for empty string', () => {
|
|
11
|
+
node_assert_1.default.deepStrictEqual((0, complexity_1.complexity)(''), { score: 0, uniqueness: 0, length: 0 });
|
|
12
|
+
});
|
|
13
|
+
(0, node_test_1.it)('returns correct result for simple string', () => {
|
|
14
|
+
const result = (0, complexity_1.complexity)('abc');
|
|
15
|
+
node_assert_1.default.strictEqual(typeof result.score, 'number');
|
|
16
|
+
node_assert_1.default.strictEqual(typeof result.uniqueness, 'number');
|
|
17
|
+
node_assert_1.default.strictEqual(result.length, 3);
|
|
18
|
+
});
|
|
19
|
+
(0, node_test_1.it)('returns correct result for complex string', () => {
|
|
20
|
+
const result = (0, complexity_1.complexity)('aA1!aA1!');
|
|
21
|
+
node_assert_1.default.ok(result.score > 0);
|
|
22
|
+
node_assert_1.default.ok(result.uniqueness > 0);
|
|
23
|
+
node_assert_1.default.strictEqual(result.length, 8);
|
|
24
|
+
});
|
|
25
|
+
(0, node_test_1.it)('throws if input is not a string', () => {
|
|
26
|
+
node_assert_1.default.throws(() => (0, complexity_1.complexity)(123), /Input must be a string/);
|
|
27
|
+
});
|
|
28
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|