stringzy 4.0.0 → 4.2.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/auto-assign.yml +26 -0
- package/CODE_OF_CONDUCT.MD +115 -0
- package/README.md +963 -40
- package/dist/analyzing/checkMultiplePatterns.d.ts +14 -0
- package/dist/analyzing/checkMultiplePatterns.js +75 -0
- package/dist/analyzing/checkSubsequence.d.ts +14 -0
- package/dist/analyzing/checkSubsequence.js +33 -0
- package/dist/analyzing/contentWordCount.d.ts +11 -0
- package/dist/analyzing/contentWordCount.js +23 -0
- package/dist/analyzing/functionWordCount.d.ts +11 -0
- package/dist/analyzing/functionWordCount.js +33 -0
- package/dist/analyzing/index.d.ts +14 -0
- package/dist/analyzing/index.js +22 -2
- package/dist/analyzing/lexicographicalRank.d.ts +26 -0
- package/dist/analyzing/lexicographicalRank.js +66 -0
- package/dist/analyzing/patternCount.d.ts +6 -5
- package/dist/analyzing/patternCount.js +19 -17
- package/dist/analyzing/stringRotation.d.ts +29 -0
- package/dist/analyzing/stringRotation.js +44 -0
- package/dist/formatting/binary.d.ts +24 -0
- package/dist/formatting/binary.js +49 -0
- package/dist/formatting/creditCard.d.ts +8 -0
- package/dist/formatting/creditCard.js +28 -0
- package/dist/formatting/decimal.d.ts +21 -0
- package/dist/formatting/decimal.js +73 -0
- package/dist/formatting/duration.d.ts +27 -0
- package/dist/formatting/duration.js +92 -0
- package/dist/formatting/fileSize.d.ts +18 -0
- package/dist/formatting/fileSize.js +39 -0
- package/dist/formatting/hexadecimal.d.ts +14 -0
- package/dist/formatting/hexadecimal.js +38 -0
- package/dist/formatting/index.d.ts +42 -0
- package/dist/formatting/index.js +57 -1
- package/dist/formatting/listToString.d.ts +17 -0
- package/dist/formatting/listToString.js +35 -0
- package/dist/formatting/octal.d.ts +19 -0
- package/dist/formatting/octal.js +31 -0
- package/dist/formatting/ordinal.d.ts +20 -0
- package/dist/formatting/ordinal.js +43 -0
- package/dist/formatting/percentage.d.ts +19 -0
- package/dist/formatting/percentage.js +31 -0
- package/dist/formatting/romanNumerals.d.ts +20 -0
- package/dist/formatting/romanNumerals.js +53 -0
- package/dist/formatting/scientific.d.ts +14 -0
- package/dist/formatting/scientific.js +24 -0
- package/dist/formatting/temperature.d.ts +6 -0
- package/dist/formatting/temperature.js +27 -0
- package/dist/formatting/trim.d.ts +10 -0
- package/dist/formatting/trim.js +20 -0
- package/dist/index.d.ts +30 -0
- package/dist/tests/analyzing/checkMultiplePatterns.test.d.ts +1 -0
- package/dist/tests/analyzing/checkMultiplePatterns.test.js +81 -0
- package/dist/tests/analyzing/checkSubsequence.test.d.ts +1 -0
- package/dist/tests/analyzing/checkSubsequence.test.js +34 -0
- package/dist/tests/analyzing/contentWordCount.test.d.ts +1 -0
- package/dist/tests/analyzing/contentWordCount.test.js +20 -0
- package/dist/tests/analyzing/functionWordCount.test.d.ts +1 -0
- package/dist/tests/analyzing/functionWordCount.test.js +20 -0
- package/dist/tests/analyzing/lexicographicalRank.test.d.ts +1 -0
- package/dist/tests/analyzing/lexicographicalRank.test.js +43 -0
- package/dist/tests/analyzing/stringRotation.test.d.ts +1 -0
- package/dist/tests/analyzing/stringRotation.test.js +42 -0
- package/dist/tests/formatting/binary.test.d.ts +1 -0
- package/dist/tests/formatting/binary.test.js +53 -0
- package/dist/tests/formatting/creditCard.test.d.ts +1 -0
- package/dist/tests/formatting/creditCard.test.js +31 -0
- package/dist/tests/formatting/decimal.test.d.ts +1 -0
- package/dist/tests/formatting/decimal.test.js +62 -0
- package/dist/tests/formatting/duration.test.d.ts +1 -0
- package/dist/tests/formatting/duration.test.js +61 -0
- package/dist/tests/formatting/fileSize.test.d.ts +1 -0
- package/dist/tests/formatting/fileSize.test.js +39 -0
- package/dist/tests/formatting/hexadecimal.test.d.ts +1 -0
- package/dist/tests/formatting/hexadecimal.test.js +38 -0
- package/dist/tests/formatting/listToString.test.d.ts +1 -0
- package/dist/tests/formatting/listToString.test.js +37 -0
- package/dist/tests/formatting/octal.test.d.ts +1 -0
- package/dist/tests/formatting/octal.test.js +36 -0
- package/dist/tests/formatting/ordinal.test.d.ts +1 -0
- package/dist/tests/formatting/ordinal.test.js +37 -0
- package/dist/tests/formatting/percentage.test.d.ts +1 -0
- package/dist/tests/formatting/percentage.test.js +38 -0
- package/dist/tests/formatting/romanNumerals.test.d.ts +1 -0
- package/dist/tests/formatting/romanNumerals.test.js +35 -0
- package/dist/tests/formatting/scientific.test.d.ts +1 -0
- package/dist/tests/formatting/scientific.test.js +35 -0
- package/dist/tests/formatting/temperature.test.d.ts +1 -0
- package/dist/tests/formatting/temperature.test.js +34 -0
- package/dist/tests/formatting/trim.test.d.ts +1 -0
- package/dist/tests/formatting/trim.test.js +42 -0
- package/dist/tests/transformations/reverseString.test.d.ts +1 -0
- package/dist/tests/transformations/reverseString.test.js +41 -0
- package/dist/tests/transformations/stringCombinations.test.d.ts +1 -0
- package/dist/tests/transformations/stringCombinations.test.js +41 -0
- package/dist/tests/transformations/stringPermutations.test.d.ts +1 -0
- package/dist/tests/transformations/stringPermutations.test.js +110 -0
- package/dist/tests/validations/isAlphaNumeric.test.d.ts +1 -0
- package/dist/tests/validations/isAlphaNumeric.test.js +30 -0
- package/dist/tests/validations/isAlphabetic.test.d.ts +1 -0
- package/dist/tests/validations/isAlphabetic.test.js +32 -0
- package/dist/tests/validations/isAnagram.test.d.ts +1 -0
- package/dist/tests/validations/isAnagram.test.js +44 -0
- package/dist/tests/validations/isIPv6.test.d.ts +1 -0
- package/dist/tests/validations/isIPv6.test.js +65 -0
- package/dist/tests/validations/isLowerCase.test.d.ts +1 -0
- package/dist/tests/validations/isLowerCase.test.js +50 -0
- package/dist/tests/validations/isMacAddress.test.d.ts +1 -0
- package/dist/tests/validations/isMacAddress.test.js +72 -0
- package/dist/tests/validations/isPanagram.test.d.ts +1 -0
- package/dist/tests/validations/isPanagram.test.js +39 -0
- package/dist/tests/validations/isUpperCase.test.d.ts +1 -0
- package/dist/tests/validations/isUpperCase.test.js +50 -0
- package/dist/transformations/index.d.ts +10 -0
- package/dist/transformations/index.js +16 -2
- package/dist/transformations/reverseWordsInString .d.ts +9 -0
- package/dist/transformations/reverseWordsInString .js +49 -0
- package/dist/transformations/stringCombinations.d.ts +28 -0
- package/dist/transformations/stringCombinations.js +44 -0
- package/dist/transformations/stringPermutations.d.ts +53 -0
- package/dist/transformations/stringPermutations.js +179 -0
- package/dist/validations/index.d.ts +24 -0
- package/dist/validations/index.js +34 -2
- package/dist/validations/isAlphaNumeric.d.ts +11 -0
- package/dist/validations/isAlphaNumeric.js +22 -0
- package/dist/validations/isAlphabetic.d.ts +9 -0
- package/dist/validations/isAlphabetic.js +21 -0
- package/dist/validations/isAnagram.d.ts +13 -0
- package/dist/validations/isAnagram.js +23 -0
- package/dist/validations/isIPv6.d.ts +24 -0
- package/dist/validations/isIPv6.js +45 -0
- package/dist/validations/isLowerCase.d.ts +12 -0
- package/dist/validations/isLowerCase.js +32 -0
- package/dist/validations/isMacAddress.d.ts +27 -0
- package/dist/validations/isMacAddress.js +43 -0
- package/dist/validations/isPanagram.d.ts +20 -0
- package/dist/validations/isPanagram.js +35 -0
- package/dist/validations/isUpperCase.d.ts +12 -0
- package/dist/validations/isUpperCase.js +32 -0
- package/package.json +3 -3
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Finds occurrences of multiple patterns within a given text using Aho–Corasick algorithm.
|
|
3
|
+
*
|
|
4
|
+
* - Accepts an array of patterns.
|
|
5
|
+
* - Returns all matches of each pattern along with starting indices.
|
|
6
|
+
* - Handles overlapping matches.
|
|
7
|
+
* - Is case sensitive
|
|
8
|
+
*
|
|
9
|
+
* @param {string} text - The text to search within.
|
|
10
|
+
* @param {string[]} patterns - The array of patterns to search for.
|
|
11
|
+
* @returns {Record<string, number[]>} An object mapping each pattern to an array of match indices.
|
|
12
|
+
* @throws {TypeError} If input types are invalid.
|
|
13
|
+
*/
|
|
14
|
+
export declare function checkMultiplePatterns(text: string, patterns: string[]): Record<string, number[]>;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Finds occurrences of multiple patterns within a given text using Aho–Corasick algorithm.
|
|
4
|
+
*
|
|
5
|
+
* - Accepts an array of patterns.
|
|
6
|
+
* - Returns all matches of each pattern along with starting indices.
|
|
7
|
+
* - Handles overlapping matches.
|
|
8
|
+
* - Is case sensitive
|
|
9
|
+
*
|
|
10
|
+
* @param {string} text - The text to search within.
|
|
11
|
+
* @param {string[]} patterns - The array of patterns to search for.
|
|
12
|
+
* @returns {Record<string, number[]>} An object mapping each pattern to an array of match indices.
|
|
13
|
+
* @throws {TypeError} If input types are invalid.
|
|
14
|
+
*/
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.checkMultiplePatterns = checkMultiplePatterns;
|
|
17
|
+
function checkMultiplePatterns(text, patterns) {
|
|
18
|
+
if (typeof text !== 'string') {
|
|
19
|
+
throw new TypeError('Text must be a string');
|
|
20
|
+
}
|
|
21
|
+
if (!Array.isArray(patterns) || !patterns.every(p => typeof p === 'string')) {
|
|
22
|
+
throw new TypeError('Patterns must be an array of strings');
|
|
23
|
+
}
|
|
24
|
+
const result = {};
|
|
25
|
+
if (text.length === 0 || patterns.length === 0) {
|
|
26
|
+
return result;
|
|
27
|
+
}
|
|
28
|
+
const root = { next: {}, fail: null, output: [] };
|
|
29
|
+
for (const pattern of patterns) {
|
|
30
|
+
let node = root;
|
|
31
|
+
for (const ch of pattern) {
|
|
32
|
+
if (!node.next[ch])
|
|
33
|
+
node.next[ch] = { next: {}, fail: null, output: [] };
|
|
34
|
+
node = node.next[ch];
|
|
35
|
+
}
|
|
36
|
+
node.output.push(pattern);
|
|
37
|
+
result[pattern] = [];
|
|
38
|
+
}
|
|
39
|
+
const queue = [];
|
|
40
|
+
for (const ch in root.next) {
|
|
41
|
+
const node = root.next[ch];
|
|
42
|
+
node.fail = root;
|
|
43
|
+
queue.push(node);
|
|
44
|
+
}
|
|
45
|
+
while (queue.length) {
|
|
46
|
+
const current = queue.shift();
|
|
47
|
+
for (const ch in current.next) {
|
|
48
|
+
const child = current.next[ch];
|
|
49
|
+
let fail = current.fail;
|
|
50
|
+
// Find deepest fail link with the same transition
|
|
51
|
+
while (fail && !fail.next[ch]) {
|
|
52
|
+
fail = fail.fail;
|
|
53
|
+
}
|
|
54
|
+
child.fail = fail ? fail.next[ch] : root;
|
|
55
|
+
child.output = child.output.concat(child.fail.output);
|
|
56
|
+
queue.push(child);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
let node = root;
|
|
60
|
+
for (let i = 0; i < text.length; i++) {
|
|
61
|
+
const ch = text[i];
|
|
62
|
+
while (node && !node.next[ch]) {
|
|
63
|
+
node = node.fail;
|
|
64
|
+
}
|
|
65
|
+
if (!node) {
|
|
66
|
+
node = root;
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
node = node.next[ch];
|
|
70
|
+
for (const pattern of node.output) {
|
|
71
|
+
result[pattern].push(i - pattern.length + 1);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return result;
|
|
75
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks whether the second string is a subsequence of the first string.
|
|
3
|
+
*
|
|
4
|
+
* A subsequence means all characters of the second string appear in the first string
|
|
5
|
+
* in the same relative order, but not necessarily consecutively.
|
|
6
|
+
*
|
|
7
|
+
* Is case sensitive
|
|
8
|
+
*
|
|
9
|
+
* @param {string} str1 - The string to check against.
|
|
10
|
+
* @param {string} str2 - The candidate subsequence.
|
|
11
|
+
* @returns {boolean} True if str2 is a subsequence of str1, otherwise false.
|
|
12
|
+
* @throws {TypeError} If either input is not a string.
|
|
13
|
+
*/
|
|
14
|
+
export declare function checkSubsequence(str1: string, str2: string): boolean;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.checkSubsequence = checkSubsequence;
|
|
4
|
+
/**
|
|
5
|
+
* Checks whether the second string is a subsequence of the first string.
|
|
6
|
+
*
|
|
7
|
+
* A subsequence means all characters of the second string appear in the first string
|
|
8
|
+
* in the same relative order, but not necessarily consecutively.
|
|
9
|
+
*
|
|
10
|
+
* Is case sensitive
|
|
11
|
+
*
|
|
12
|
+
* @param {string} str1 - The string to check against.
|
|
13
|
+
* @param {string} str2 - The candidate subsequence.
|
|
14
|
+
* @returns {boolean} True if str2 is a subsequence of str1, otherwise false.
|
|
15
|
+
* @throws {TypeError} If either input is not a string.
|
|
16
|
+
*/
|
|
17
|
+
function checkSubsequence(str1, str2) {
|
|
18
|
+
if (typeof str1 !== "string" || typeof str2 !== "string") {
|
|
19
|
+
throw new TypeError("Both inputs must be strings");
|
|
20
|
+
}
|
|
21
|
+
// empty subsequence is always valid
|
|
22
|
+
if (str2 === "")
|
|
23
|
+
return true;
|
|
24
|
+
let i = 0; // pointer for str2 (the subsequence)
|
|
25
|
+
let j = 0; // pointer for str1 (the main string)
|
|
26
|
+
while (i < str2.length && j < str1.length) {
|
|
27
|
+
if (str2[i] === str1[j]) {
|
|
28
|
+
i++;
|
|
29
|
+
}
|
|
30
|
+
j++;
|
|
31
|
+
}
|
|
32
|
+
return i === str2.length;
|
|
33
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Counts the number of content words in a given text.
|
|
3
|
+
*
|
|
4
|
+
* Content words are words that carry lexical meaning (nouns, verbs, adjectives, adverbs),
|
|
5
|
+
* excluding function words such as prepositions, pronouns, and articles.
|
|
6
|
+
*
|
|
7
|
+
* @param {string} text - The text to analyze.
|
|
8
|
+
* @returns {number} The count of content words in the text.
|
|
9
|
+
* @throws {TypeError} If the input is not a string.
|
|
10
|
+
*/
|
|
11
|
+
export declare function contentWordCount(text: string): number;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.contentWordCount = contentWordCount;
|
|
4
|
+
const functionWordCount_1 = require("./functionWordCount");
|
|
5
|
+
const wordCount_1 = require("./wordCount");
|
|
6
|
+
/**
|
|
7
|
+
* Counts the number of content words in a given text.
|
|
8
|
+
*
|
|
9
|
+
* Content words are words that carry lexical meaning (nouns, verbs, adjectives, adverbs),
|
|
10
|
+
* excluding function words such as prepositions, pronouns, and articles.
|
|
11
|
+
*
|
|
12
|
+
* @param {string} text - The text to analyze.
|
|
13
|
+
* @returns {number} The count of content words in the text.
|
|
14
|
+
* @throws {TypeError} If the input is not a string.
|
|
15
|
+
*/
|
|
16
|
+
function contentWordCount(text) {
|
|
17
|
+
if (typeof text !== 'string') {
|
|
18
|
+
throw new TypeError('Input must be a string');
|
|
19
|
+
}
|
|
20
|
+
const totalWords = (0, wordCount_1.wordCount)(text);
|
|
21
|
+
const functionWords = (0, functionWordCount_1.functionWordCount)(text);
|
|
22
|
+
return totalWords - functionWords;
|
|
23
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Counts the number of function words in a given text.
|
|
3
|
+
*
|
|
4
|
+
* Function words are common words (e.g., prepositions, pronouns, conjunctions, articles, etc.)
|
|
5
|
+
* that carry grammatical meaning rather than lexical meaning.
|
|
6
|
+
*
|
|
7
|
+
* @param {string} text - The text to analyze.
|
|
8
|
+
* @returns {number} The count of function words in the text.
|
|
9
|
+
* @throws {TypeError} If the input is not a string.
|
|
10
|
+
*/
|
|
11
|
+
export declare function functionWordCount(text: string): number;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.functionWordCount = functionWordCount;
|
|
4
|
+
/**
|
|
5
|
+
* Counts the number of function words in a given text.
|
|
6
|
+
*
|
|
7
|
+
* Function words are common words (e.g., prepositions, pronouns, conjunctions, articles, etc.)
|
|
8
|
+
* that carry grammatical meaning rather than lexical meaning.
|
|
9
|
+
*
|
|
10
|
+
* @param {string} text - The text to analyze.
|
|
11
|
+
* @returns {number} The count of function words in the text.
|
|
12
|
+
* @throws {TypeError} If the input is not a string.
|
|
13
|
+
*/
|
|
14
|
+
function functionWordCount(text) {
|
|
15
|
+
if (typeof text !== 'string') {
|
|
16
|
+
throw new TypeError('Input must be a string');
|
|
17
|
+
}
|
|
18
|
+
const functionWords = new Set([
|
|
19
|
+
'a', 'an', 'the', 'and', 'but', 'or', 'nor', 'so', 'yet',
|
|
20
|
+
'for', 'of', 'in', 'on', 'at', 'by', 'to', 'from', 'with', 'about',
|
|
21
|
+
'as', 'into', 'like', 'through', 'after', 'over', 'between', 'out',
|
|
22
|
+
'against', 'during', 'without', 'before', 'under', 'around', 'among',
|
|
23
|
+
'is', 'am', 'are', 'was', 'were', 'be', 'been', 'being',
|
|
24
|
+
'he', 'she', 'it', 'they', 'we', 'you', 'i', 'me', 'him', 'her',
|
|
25
|
+
'them', 'us', 'my', 'your', 'his', 'their', 'our',
|
|
26
|
+
'this', 'that', 'these', 'those',
|
|
27
|
+
'who', 'whom', 'which', 'what', 'when', 'where', 'why', 'how'
|
|
28
|
+
]);
|
|
29
|
+
// ✅ Normalize text: lowercase + remove punctuation
|
|
30
|
+
const cleanedText = text.toLowerCase().replace(/[^\w\s]/g, '');
|
|
31
|
+
const words = cleanedText.trim().split(/\s+/);
|
|
32
|
+
return words.filter(word => functionWords.has(word)).length;
|
|
33
|
+
}
|
|
@@ -6,6 +6,12 @@ export { wordCount } from './wordCount';
|
|
|
6
6
|
export { stringSimilarity } from './stringSimilarity';
|
|
7
7
|
export { patternCount } from './patternCount';
|
|
8
8
|
export { vowelConsonantCount } from './vowelConsonantCount';
|
|
9
|
+
export { checkMultiplePatterns } from './checkMultiplePatterns';
|
|
10
|
+
export { checkSubsequence } from './checkSubsequence';
|
|
11
|
+
export { functionWordCount } from './functionWordCount';
|
|
12
|
+
export { contentWordCount } from './contentWordCount';
|
|
13
|
+
export { checkStringRotations } from './stringRotation';
|
|
14
|
+
export { lexicographicalRank } from './lexicographicalRank';
|
|
9
15
|
import { characterCount } from './characterCount';
|
|
10
16
|
import { characterFrequency } from './characterFrequency';
|
|
11
17
|
import { complexity } from './complexity';
|
|
@@ -14,6 +20,10 @@ import { wordCount } from './wordCount';
|
|
|
14
20
|
import { stringSimilarity } from './stringSimilarity';
|
|
15
21
|
import { patternCount } from './patternCount';
|
|
16
22
|
import { vowelConsonantCount } from './vowelConsonantCount';
|
|
23
|
+
import { checkMultiplePatterns } from './checkMultiplePatterns';
|
|
24
|
+
import { checkSubsequence } from './checkSubsequence';
|
|
25
|
+
import { checkStringRotations } from './stringRotation';
|
|
26
|
+
import { lexicographicalRank } from './lexicographicalRank';
|
|
17
27
|
export declare const analyzing: {
|
|
18
28
|
characterCount: typeof characterCount;
|
|
19
29
|
characterFrequency: typeof characterFrequency;
|
|
@@ -23,4 +33,8 @@ export declare const analyzing: {
|
|
|
23
33
|
stringSimilarity: typeof stringSimilarity;
|
|
24
34
|
patternCount: typeof patternCount;
|
|
25
35
|
vowelConsonantCount: typeof vowelConsonantCount;
|
|
36
|
+
checkMultiplePatterns: typeof checkMultiplePatterns;
|
|
37
|
+
checkSubsequence: typeof checkSubsequence;
|
|
38
|
+
checkStringRotations: typeof checkStringRotations;
|
|
39
|
+
lexicographicalRank: typeof lexicographicalRank;
|
|
26
40
|
};
|
package/dist/analyzing/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
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;
|
|
3
|
+
exports.analyzing = exports.lexicographicalRank = exports.checkStringRotations = exports.contentWordCount = exports.functionWordCount = exports.checkSubsequence = exports.checkMultiplePatterns = exports.vowelConsonantCount = exports.patternCount = exports.stringSimilarity = exports.wordCount = exports.readingDuration = exports.complexity = exports.characterFrequency = exports.characterCount = void 0;
|
|
4
4
|
var characterCount_1 = require("./characterCount");
|
|
5
5
|
Object.defineProperty(exports, "characterCount", { enumerable: true, get: function () { return characterCount_1.characterCount; } });
|
|
6
6
|
var characterFrequency_1 = require("./characterFrequency");
|
|
@@ -17,6 +17,18 @@ var patternCount_1 = require("./patternCount");
|
|
|
17
17
|
Object.defineProperty(exports, "patternCount", { enumerable: true, get: function () { return patternCount_1.patternCount; } });
|
|
18
18
|
var vowelConsonantCount_1 = require("./vowelConsonantCount");
|
|
19
19
|
Object.defineProperty(exports, "vowelConsonantCount", { enumerable: true, get: function () { return vowelConsonantCount_1.vowelConsonantCount; } });
|
|
20
|
+
var checkMultiplePatterns_1 = require("./checkMultiplePatterns");
|
|
21
|
+
Object.defineProperty(exports, "checkMultiplePatterns", { enumerable: true, get: function () { return checkMultiplePatterns_1.checkMultiplePatterns; } });
|
|
22
|
+
var checkSubsequence_1 = require("./checkSubsequence");
|
|
23
|
+
Object.defineProperty(exports, "checkSubsequence", { enumerable: true, get: function () { return checkSubsequence_1.checkSubsequence; } });
|
|
24
|
+
var functionWordCount_1 = require("./functionWordCount");
|
|
25
|
+
Object.defineProperty(exports, "functionWordCount", { enumerable: true, get: function () { return functionWordCount_1.functionWordCount; } });
|
|
26
|
+
var contentWordCount_1 = require("./contentWordCount");
|
|
27
|
+
Object.defineProperty(exports, "contentWordCount", { enumerable: true, get: function () { return contentWordCount_1.contentWordCount; } });
|
|
28
|
+
var stringRotation_1 = require("./stringRotation");
|
|
29
|
+
Object.defineProperty(exports, "checkStringRotations", { enumerable: true, get: function () { return stringRotation_1.checkStringRotations; } });
|
|
30
|
+
var lexicographicalRank_1 = require("./lexicographicalRank");
|
|
31
|
+
Object.defineProperty(exports, "lexicographicalRank", { enumerable: true, get: function () { return lexicographicalRank_1.lexicographicalRank; } });
|
|
20
32
|
const characterCount_2 = require("./characterCount");
|
|
21
33
|
const characterFrequency_2 = require("./characterFrequency");
|
|
22
34
|
const complexity_2 = require("./complexity");
|
|
@@ -25,6 +37,10 @@ const wordCount_2 = require("./wordCount");
|
|
|
25
37
|
const stringSimilarity_2 = require("./stringSimilarity");
|
|
26
38
|
const patternCount_2 = require("./patternCount");
|
|
27
39
|
const vowelConsonantCount_2 = require("./vowelConsonantCount");
|
|
40
|
+
const checkMultiplePatterns_2 = require("./checkMultiplePatterns");
|
|
41
|
+
const checkSubsequence_2 = require("./checkSubsequence");
|
|
42
|
+
const stringRotation_2 = require("./stringRotation");
|
|
43
|
+
const lexicographicalRank_2 = require("./lexicographicalRank");
|
|
28
44
|
exports.analyzing = {
|
|
29
45
|
characterCount: characterCount_2.characterCount,
|
|
30
46
|
characterFrequency: characterFrequency_2.characterFrequency,
|
|
@@ -33,5 +49,9 @@ exports.analyzing = {
|
|
|
33
49
|
wordCount: wordCount_2.wordCount,
|
|
34
50
|
stringSimilarity: stringSimilarity_2.stringSimilarity,
|
|
35
51
|
patternCount: patternCount_2.patternCount,
|
|
36
|
-
vowelConsonantCount: vowelConsonantCount_2.vowelConsonantCount
|
|
52
|
+
vowelConsonantCount: vowelConsonantCount_2.vowelConsonantCount,
|
|
53
|
+
checkMultiplePatterns: checkMultiplePatterns_2.checkMultiplePatterns,
|
|
54
|
+
checkSubsequence: checkSubsequence_2.checkSubsequence,
|
|
55
|
+
checkStringRotations: stringRotation_2.checkStringRotations,
|
|
56
|
+
lexicographicalRank: lexicographicalRank_2.lexicographicalRank
|
|
37
57
|
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calculates the lexicographic rank of a string among all its unique permutations.
|
|
3
|
+
*
|
|
4
|
+
* The rank is 1-based (i.e., the first permutation has rank 1).
|
|
5
|
+
* Handles strings with duplicate characters correctly by adjusting for repetition.
|
|
6
|
+
*
|
|
7
|
+
* @param {string} str - The input string.
|
|
8
|
+
* @returns {number} The 1-based lexicographic rank of the string.
|
|
9
|
+
* @throws {TypeError} If the input is not a string.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* lexicographicRank("acb"); // 2
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* lexicographicRank("string"); // 598
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* lexicographicRank("cba"); // 6
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* lexicographicRank("aba"); // 2
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* lexicographicRank("a"); // 1
|
|
25
|
+
*/
|
|
26
|
+
export declare function lexicographicalRank(str: string): number;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.lexicographicalRank = lexicographicalRank;
|
|
4
|
+
/**
|
|
5
|
+
* Calculates the lexicographic rank of a string among all its unique permutations.
|
|
6
|
+
*
|
|
7
|
+
* The rank is 1-based (i.e., the first permutation has rank 1).
|
|
8
|
+
* Handles strings with duplicate characters correctly by adjusting for repetition.
|
|
9
|
+
*
|
|
10
|
+
* @param {string} str - The input string.
|
|
11
|
+
* @returns {number} The 1-based lexicographic rank of the string.
|
|
12
|
+
* @throws {TypeError} If the input is not a string.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* lexicographicRank("acb"); // 2
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* lexicographicRank("string"); // 598
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* lexicographicRank("cba"); // 6
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* lexicographicRank("aba"); // 2
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* lexicographicRank("a"); // 1
|
|
28
|
+
*/
|
|
29
|
+
function lexicographicalRank(str) {
|
|
30
|
+
if (typeof str !== 'string') {
|
|
31
|
+
throw new TypeError('Input must be a string');
|
|
32
|
+
}
|
|
33
|
+
if (str.length === 0)
|
|
34
|
+
return 1;
|
|
35
|
+
const factorial = (n) => (n <= 1 ? 1 : n * factorial(n - 1));
|
|
36
|
+
const charCount = {};
|
|
37
|
+
for (const ch of str) {
|
|
38
|
+
charCount[ch] = (charCount[ch] || 0) + 1;
|
|
39
|
+
}
|
|
40
|
+
const chars = Object.keys(charCount).sort();
|
|
41
|
+
let rank = 1;
|
|
42
|
+
for (let i = 0; i < str.length; i++) {
|
|
43
|
+
const ch = str[i];
|
|
44
|
+
for (const smaller of chars) {
|
|
45
|
+
if (smaller >= ch)
|
|
46
|
+
break;
|
|
47
|
+
if (charCount[smaller] > 0) {
|
|
48
|
+
charCount[smaller]--;
|
|
49
|
+
let denom = 1;
|
|
50
|
+
const remaining = str.length - i - 1;
|
|
51
|
+
for (const count of Object.values(charCount)) {
|
|
52
|
+
denom *= factorial(count);
|
|
53
|
+
}
|
|
54
|
+
rank += factorial(remaining) / denom;
|
|
55
|
+
charCount[smaller]++;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
if (charCount[ch] > 0) {
|
|
59
|
+
charCount[ch]--;
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
break; // shouldn't happen unless str has invalid chars
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return rank;
|
|
66
|
+
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Counts the number of times a specific pattern occurs in a given text,
|
|
3
|
+
* including overlapping occurrences.
|
|
3
4
|
*
|
|
4
|
-
*
|
|
5
|
+
* Uses the Knuth-Morris-Pratt (KMP) pattern matching algorithm for efficient searching.
|
|
5
6
|
*
|
|
6
|
-
* @param
|
|
7
|
-
* @param
|
|
8
|
-
* @returns
|
|
7
|
+
* @param text - The text to search within
|
|
8
|
+
* @param pattern - The pattern to count
|
|
9
|
+
* @returns The number of times the pattern occurs (including overlapping)
|
|
9
10
|
*/
|
|
10
11
|
export declare function patternCount(text: string, pattern: string): number;
|
|
@@ -2,50 +2,52 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.patternCount = patternCount;
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
5
|
+
* Counts the number of times a specific pattern occurs in a given text,
|
|
6
|
+
* including overlapping occurrences.
|
|
6
7
|
*
|
|
7
|
-
*
|
|
8
|
+
* Uses the Knuth-Morris-Pratt (KMP) pattern matching algorithm for efficient searching.
|
|
8
9
|
*
|
|
9
|
-
* @param
|
|
10
|
-
* @param
|
|
11
|
-
* @returns
|
|
10
|
+
* @param text - The text to search within
|
|
11
|
+
* @param pattern - The pattern to count
|
|
12
|
+
* @returns The number of times the pattern occurs (including overlapping)
|
|
12
13
|
*/
|
|
13
14
|
function patternCount(text, pattern) {
|
|
14
|
-
if (pattern
|
|
15
|
-
return 0; //
|
|
16
|
-
}
|
|
15
|
+
if (!pattern)
|
|
16
|
+
return 0; // Return 0 for empty pattern
|
|
17
17
|
const prefixFunction = computePrefixFunction(pattern);
|
|
18
18
|
let count = 0;
|
|
19
19
|
let j = 0; // Index for pattern
|
|
20
20
|
for (let i = 0; i < text.length; i++) {
|
|
21
21
|
while (j > 0 && text[i] !== pattern[j]) {
|
|
22
|
-
j = prefixFunction[j - 1];
|
|
22
|
+
j = prefixFunction[j - 1]; // fallback in pattern
|
|
23
23
|
}
|
|
24
|
-
if (text[i] === pattern[j])
|
|
24
|
+
if (text[i] === pattern[j])
|
|
25
25
|
j++;
|
|
26
|
-
}
|
|
27
26
|
if (j === pattern.length) {
|
|
28
27
|
count++;
|
|
29
|
-
j = prefixFunction[j - 1]; //
|
|
28
|
+
j = prefixFunction[j - 1]; // allow overlapping matches
|
|
30
29
|
}
|
|
31
30
|
}
|
|
32
31
|
return count;
|
|
33
32
|
}
|
|
34
33
|
/**
|
|
35
34
|
* Computes the prefix function (partial match table) for KMP algorithm.
|
|
36
|
-
*
|
|
37
|
-
*
|
|
35
|
+
*
|
|
36
|
+
* The prefix function stores the length of the longest proper prefix
|
|
37
|
+
* which is also a suffix for each prefix of the pattern.
|
|
38
|
+
*
|
|
39
|
+
* @param pattern - Pattern string
|
|
40
|
+
* @returns Array of prefix lengths
|
|
38
41
|
*/
|
|
39
42
|
function computePrefixFunction(pattern) {
|
|
40
43
|
const prefixFunction = new Array(pattern.length).fill(0);
|
|
41
44
|
let j = 0;
|
|
42
45
|
for (let i = 1; i < pattern.length; i++) {
|
|
43
46
|
while (j > 0 && pattern[i] !== pattern[j]) {
|
|
44
|
-
j = prefixFunction[j - 1];
|
|
47
|
+
j = prefixFunction[j - 1]; // fallback
|
|
45
48
|
}
|
|
46
|
-
if (pattern[i] === pattern[j])
|
|
49
|
+
if (pattern[i] === pattern[j])
|
|
47
50
|
j++;
|
|
48
|
-
}
|
|
49
51
|
prefixFunction[i] = j;
|
|
50
52
|
}
|
|
51
53
|
return prefixFunction;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if one string is a rotation of another.
|
|
3
|
+
*
|
|
4
|
+
* A string `str2` is a rotation of `str1` if it can be obtained by shifting
|
|
5
|
+
* the characters of `str1` in a circular fashion.
|
|
6
|
+
*
|
|
7
|
+
* The check is case-sensitive and supports special characters and numbers.
|
|
8
|
+
*
|
|
9
|
+
* @param {string} str1 - The original string.
|
|
10
|
+
* @param {string} str2 - The string to check if it is a rotation of str1.
|
|
11
|
+
* @returns {boolean} True if str2 is a rotation of str1, otherwise false.
|
|
12
|
+
* @throws {TypeError} If either input is not a string.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* checkStringRotations("abcd", "cdab"); // true
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* checkStringRotations("abc", "acb"); // false
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* checkStringRotations("hello", "ohell"); // true
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* checkStringRotations("", ""); // true
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* checkStringRotations("abc", "ab"); // false
|
|
28
|
+
*/
|
|
29
|
+
export declare function checkStringRotations(str1: string, str2: string): boolean;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.checkStringRotations = checkStringRotations;
|
|
4
|
+
/**
|
|
5
|
+
* Checks if one string is a rotation of another.
|
|
6
|
+
*
|
|
7
|
+
* A string `str2` is a rotation of `str1` if it can be obtained by shifting
|
|
8
|
+
* the characters of `str1` in a circular fashion.
|
|
9
|
+
*
|
|
10
|
+
* The check is case-sensitive and supports special characters and numbers.
|
|
11
|
+
*
|
|
12
|
+
* @param {string} str1 - The original string.
|
|
13
|
+
* @param {string} str2 - The string to check if it is a rotation of str1.
|
|
14
|
+
* @returns {boolean} True if str2 is a rotation of str1, otherwise false.
|
|
15
|
+
* @throws {TypeError} If either input is not a string.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* checkStringRotations("abcd", "cdab"); // true
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* checkStringRotations("abc", "acb"); // false
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* checkStringRotations("hello", "ohell"); // true
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* checkStringRotations("", ""); // true
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* checkStringRotations("abc", "ab"); // false
|
|
31
|
+
*/
|
|
32
|
+
function checkStringRotations(str1, str2) {
|
|
33
|
+
if (typeof str1 !== 'string' || typeof str2 !== 'string') {
|
|
34
|
+
throw new TypeError('Both inputs must be strings');
|
|
35
|
+
}
|
|
36
|
+
// Edge case: both empty strings
|
|
37
|
+
if (str1 === '' && str2 === '')
|
|
38
|
+
return true;
|
|
39
|
+
// If lengths differ, they cannot be rotations
|
|
40
|
+
if (str1.length !== str2.length)
|
|
41
|
+
return false;
|
|
42
|
+
// Concatenate str1 with itself and check if str2 is a substring
|
|
43
|
+
return (str1 + str1).includes(str2);
|
|
44
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a decimal integer to its binary (base-2) string representation.
|
|
3
|
+
*
|
|
4
|
+
* - Supports negative numbers (prefixed with '-')
|
|
5
|
+
* - Optional grouping from the least significant bit for readability
|
|
6
|
+
*
|
|
7
|
+
* Examples:
|
|
8
|
+
* 5 → "101"
|
|
9
|
+
* 10 → "1010"
|
|
10
|
+
* 255 → "11111111"
|
|
11
|
+
* 0 → "0"
|
|
12
|
+
*
|
|
13
|
+
* Grouping examples (from right to left):
|
|
14
|
+
* formatToBinary(255, { group: 4 }) → "1111 1111"
|
|
15
|
+
* formatToBinary(10, { group: 2 }) → "10 10"
|
|
16
|
+
*
|
|
17
|
+
* @param {number} num - The decimal integer to convert.
|
|
18
|
+
* @param {{ group?: number }} [options] - Optional grouping configuration.
|
|
19
|
+
* @returns {string} The binary string representation.
|
|
20
|
+
* @throws {TypeError} If input is not a number, is NaN, or not an integer.
|
|
21
|
+
*/
|
|
22
|
+
export declare function formatToBinary(num: number, options?: {
|
|
23
|
+
group?: number;
|
|
24
|
+
}): string;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.formatToBinary = formatToBinary;
|
|
4
|
+
/**
|
|
5
|
+
* Converts a decimal integer to its binary (base-2) string representation.
|
|
6
|
+
*
|
|
7
|
+
* - Supports negative numbers (prefixed with '-')
|
|
8
|
+
* - Optional grouping from the least significant bit for readability
|
|
9
|
+
*
|
|
10
|
+
* Examples:
|
|
11
|
+
* 5 → "101"
|
|
12
|
+
* 10 → "1010"
|
|
13
|
+
* 255 → "11111111"
|
|
14
|
+
* 0 → "0"
|
|
15
|
+
*
|
|
16
|
+
* Grouping examples (from right to left):
|
|
17
|
+
* formatToBinary(255, { group: 4 }) → "1111 1111"
|
|
18
|
+
* formatToBinary(10, { group: 2 }) → "10 10"
|
|
19
|
+
*
|
|
20
|
+
* @param {number} num - The decimal integer to convert.
|
|
21
|
+
* @param {{ group?: number }} [options] - Optional grouping configuration.
|
|
22
|
+
* @returns {string} The binary string representation.
|
|
23
|
+
* @throws {TypeError} If input is not a number, is NaN, or not an integer.
|
|
24
|
+
*/
|
|
25
|
+
function formatToBinary(num, options) {
|
|
26
|
+
if (typeof num !== 'number' || Number.isNaN(num)) {
|
|
27
|
+
throw new TypeError('Input must be a number');
|
|
28
|
+
}
|
|
29
|
+
if (!Number.isInteger(num)) {
|
|
30
|
+
throw new TypeError('Input must be an integer');
|
|
31
|
+
}
|
|
32
|
+
const isNegative = num < 0;
|
|
33
|
+
const absoluteValue = Math.abs(num);
|
|
34
|
+
// Handle zero explicitly to avoid "-0" or empty strings
|
|
35
|
+
const core = absoluteValue.toString(2);
|
|
36
|
+
const groupSize = options === null || options === void 0 ? void 0 : options.group;
|
|
37
|
+
if (groupSize !== undefined) {
|
|
38
|
+
if (typeof groupSize !== 'number' ||
|
|
39
|
+
Number.isNaN(groupSize) ||
|
|
40
|
+
!Number.isInteger(groupSize) ||
|
|
41
|
+
groupSize <= 0) {
|
|
42
|
+
throw new TypeError('Group size must be a positive integer');
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
const grouped = groupSize && core.length > groupSize
|
|
46
|
+
? core.replace(new RegExp(`\\B(?=(\\d{${groupSize}})+(?!\\d))`, 'g'), ' ')
|
|
47
|
+
: core;
|
|
48
|
+
return isNegative ? `-${grouped}` : grouped;
|
|
49
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Formats a credit card number by grouping digits into readable parts.
|
|
3
|
+
*
|
|
4
|
+
* @param {string} cardNumber - The credit card number to format.
|
|
5
|
+
* @returns {string} The formatted credit card number.
|
|
6
|
+
* @throws {TypeError} If the input is not a string.
|
|
7
|
+
*/
|
|
8
|
+
export declare function formatCreditCard(cardNumber: string): string;
|