stringzy 4.0.0 → 4.1.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/README.md +445 -34
- package/dist/analyzing/checkMultiplePatterns.d.ts +14 -0
- package/dist/analyzing/checkMultiplePatterns.js +63 -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 +11 -0
- package/dist/analyzing/index.js +18 -2
- 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/index.d.ts +13 -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/stringRotation.test.d.ts +1 -0
- package/dist/tests/analyzing/stringRotation.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 +40 -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/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 +9 -0
- package/dist/transformations/index.js +14 -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 +31 -0
- package/dist/transformations/stringPermutations.js +53 -0
- package/dist/validations/index.d.ts +21 -0
- package/dist/validations/index.js +30 -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/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,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generates all unique combinations (subsequences) of a given string,
|
|
3
|
+
* including the empty string.
|
|
4
|
+
*
|
|
5
|
+
* Handles duplicate characters by ensuring only unique combinations are returned.
|
|
6
|
+
* The order of combinations in the output array is not guaranteed.
|
|
7
|
+
*
|
|
8
|
+
* @param {string} str - The input string to generate combinations from.
|
|
9
|
+
* @returns {string[]} An array containing all unique combinations of the string.
|
|
10
|
+
* @throws {TypeError} If the input is not a string.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* stringCombinations("ab");
|
|
14
|
+
* // ["", "a", "b", "ab"]
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* stringCombinations("abc");
|
|
18
|
+
* // ["", "a", "b", "c", "ab", "ac", "bc", "abc"]
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* stringCombinations("aab");
|
|
22
|
+
* // ["", "a", "b", "aa", "ab", "aab"]
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* stringCombinations("");
|
|
26
|
+
* // [""]
|
|
27
|
+
*/
|
|
28
|
+
export declare function stringCombinations(str: string): string[];
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.stringCombinations = stringCombinations;
|
|
4
|
+
/**
|
|
5
|
+
* Generates all unique combinations (subsequences) of a given string,
|
|
6
|
+
* including the empty string.
|
|
7
|
+
*
|
|
8
|
+
* Handles duplicate characters by ensuring only unique combinations are returned.
|
|
9
|
+
* The order of combinations in the output array is not guaranteed.
|
|
10
|
+
*
|
|
11
|
+
* @param {string} str - The input string to generate combinations from.
|
|
12
|
+
* @returns {string[]} An array containing all unique combinations of the string.
|
|
13
|
+
* @throws {TypeError} If the input is not a string.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* stringCombinations("ab");
|
|
17
|
+
* // ["", "a", "b", "ab"]
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* stringCombinations("abc");
|
|
21
|
+
* // ["", "a", "b", "c", "ab", "ac", "bc", "abc"]
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* stringCombinations("aab");
|
|
25
|
+
* // ["", "a", "b", "aa", "ab", "aab"]
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* stringCombinations("");
|
|
29
|
+
* // [""]
|
|
30
|
+
*/
|
|
31
|
+
function stringCombinations(str) {
|
|
32
|
+
if (typeof str !== 'string') {
|
|
33
|
+
throw new TypeError('Input must be a string');
|
|
34
|
+
}
|
|
35
|
+
const results = new Set();
|
|
36
|
+
function backtrack(start, path) {
|
|
37
|
+
results.add(path);
|
|
38
|
+
for (let i = start; i < str.length; i++) {
|
|
39
|
+
backtrack(i + 1, path + str[i]);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
backtrack(0, '');
|
|
43
|
+
return Array.from(results);
|
|
44
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generates all unique permutations of a given string.
|
|
3
|
+
*
|
|
4
|
+
* Handles repeated characters by ensuring only unique permutations
|
|
5
|
+
* are included in the result. The order of permutations is not guaranteed.
|
|
6
|
+
*
|
|
7
|
+
* @param {string} str - The input string to generate permutations for.
|
|
8
|
+
* @returns {string[]} An array of unique permutations of the input string.
|
|
9
|
+
* @throws {TypeError} If the input is not a string.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* stringPermutations("ab");
|
|
13
|
+
* // ["ab", "ba"]
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* stringPermutations("abc");
|
|
17
|
+
* // ["abc", "acb", "bac", "bca", "cab", "cba"]
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* stringPermutations("aab");
|
|
21
|
+
* // ["aab", "aba", "baa"]
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* stringPermutations("");
|
|
25
|
+
* // [""]
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* stringPermutations("a");
|
|
29
|
+
* // ["a"]
|
|
30
|
+
*/
|
|
31
|
+
export declare function stringPermutations(str: string): string[];
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.stringPermutations = stringPermutations;
|
|
4
|
+
/**
|
|
5
|
+
* Generates all unique permutations of a given string.
|
|
6
|
+
*
|
|
7
|
+
* Handles repeated characters by ensuring only unique permutations
|
|
8
|
+
* are included in the result. The order of permutations is not guaranteed.
|
|
9
|
+
*
|
|
10
|
+
* @param {string} str - The input string to generate permutations for.
|
|
11
|
+
* @returns {string[]} An array of unique permutations of the input string.
|
|
12
|
+
* @throws {TypeError} If the input is not a string.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* stringPermutations("ab");
|
|
16
|
+
* // ["ab", "ba"]
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* stringPermutations("abc");
|
|
20
|
+
* // ["abc", "acb", "bac", "bca", "cab", "cba"]
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* stringPermutations("aab");
|
|
24
|
+
* // ["aab", "aba", "baa"]
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* stringPermutations("");
|
|
28
|
+
* // [""]
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* stringPermutations("a");
|
|
32
|
+
* // ["a"]
|
|
33
|
+
*/
|
|
34
|
+
function stringPermutations(str) {
|
|
35
|
+
if (typeof str !== 'string') {
|
|
36
|
+
throw new TypeError('Input must be a string');
|
|
37
|
+
}
|
|
38
|
+
if (str.length === 0)
|
|
39
|
+
return [''];
|
|
40
|
+
const results = new Set();
|
|
41
|
+
const permute = (prefix, remaining) => {
|
|
42
|
+
if (remaining.length === 0) {
|
|
43
|
+
results.add(prefix);
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
for (let i = 0; i < remaining.length; i++) {
|
|
47
|
+
permute(prefix + remaining[i], remaining.slice(0, i) + remaining.slice(i + 1));
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
permute('', str);
|
|
52
|
+
return Array.from(results);
|
|
53
|
+
}
|
|
@@ -7,6 +7,13 @@ export { isURL } from './isURL';
|
|
|
7
7
|
export { isIPv4 } from './isIPv4';
|
|
8
8
|
export { isHexColor } from './isHexColor';
|
|
9
9
|
export { isPalindrome } from './isPalindrome';
|
|
10
|
+
export { isLowerCase } from './isLowerCase';
|
|
11
|
+
export { isUpperCase } from './isUpperCase';
|
|
12
|
+
export { isAlphabetic } from './isAlphabetic';
|
|
13
|
+
export { isAlphaNumeric } from './isAlphaNumeric';
|
|
14
|
+
export { isAnagram } from './isAnagram';
|
|
15
|
+
export { isPanagram } from './isPanagram';
|
|
16
|
+
export { isMacAddress } from './isMacAddress';
|
|
10
17
|
import { isCoordinates } from './isCoordinates';
|
|
11
18
|
import { isDate } from './isDate';
|
|
12
19
|
import { isEmail } from './isEmail';
|
|
@@ -16,6 +23,13 @@ import { isURL } from './isURL';
|
|
|
16
23
|
import { isIPv4 } from './isIPv4';
|
|
17
24
|
import { isHexColor } from './isHexColor';
|
|
18
25
|
import { isPalindrome } from './isPalindrome';
|
|
26
|
+
import { isLowerCase } from './isLowerCase';
|
|
27
|
+
import { isUpperCase } from './isUpperCase';
|
|
28
|
+
import { isAlphabetic } from './isAlphabetic';
|
|
29
|
+
import { isAlphaNumeric } from './isAlphaNumeric';
|
|
30
|
+
import { isAnagram } from './isAnagram';
|
|
31
|
+
import { isPanagram } from './isPanagram';
|
|
32
|
+
import { isMacAddress } from './isMacAddress';
|
|
19
33
|
export declare const validations: {
|
|
20
34
|
isCoordinates: typeof isCoordinates;
|
|
21
35
|
isDate: typeof isDate;
|
|
@@ -26,4 +40,11 @@ export declare const validations: {
|
|
|
26
40
|
isIPv4: typeof isIPv4;
|
|
27
41
|
isHexColor: typeof isHexColor;
|
|
28
42
|
isPalindrome: typeof isPalindrome;
|
|
43
|
+
isLowerCase: typeof isLowerCase;
|
|
44
|
+
isUpperCase: typeof isUpperCase;
|
|
45
|
+
isAlphabetic: typeof isAlphabetic;
|
|
46
|
+
isAlphaNumeric: typeof isAlphaNumeric;
|
|
47
|
+
isAnagram: typeof isAnagram;
|
|
48
|
+
isPanagram: typeof isPanagram;
|
|
49
|
+
isMacAddress: typeof isMacAddress;
|
|
29
50
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.validations = exports.isPalindrome = exports.isHexColor = exports.isIPv4 = exports.isURL = exports.isSlug = exports.isEmpty = exports.isEmail = exports.isDate = exports.isCoordinates = void 0;
|
|
3
|
+
exports.validations = exports.isMacAddress = exports.isPanagram = exports.isAnagram = exports.isAlphaNumeric = exports.isAlphabetic = exports.isUpperCase = exports.isLowerCase = exports.isPalindrome = exports.isHexColor = exports.isIPv4 = exports.isURL = exports.isSlug = exports.isEmpty = exports.isEmail = exports.isDate = exports.isCoordinates = void 0;
|
|
4
4
|
var isCoordinates_1 = require("./isCoordinates");
|
|
5
5
|
Object.defineProperty(exports, "isCoordinates", { enumerable: true, get: function () { return isCoordinates_1.isCoordinates; } });
|
|
6
6
|
var isDate_1 = require("./isDate");
|
|
@@ -19,6 +19,20 @@ var isHexColor_1 = require("./isHexColor");
|
|
|
19
19
|
Object.defineProperty(exports, "isHexColor", { enumerable: true, get: function () { return isHexColor_1.isHexColor; } });
|
|
20
20
|
var isPalindrome_1 = require("./isPalindrome");
|
|
21
21
|
Object.defineProperty(exports, "isPalindrome", { enumerable: true, get: function () { return isPalindrome_1.isPalindrome; } });
|
|
22
|
+
var isLowerCase_1 = require("./isLowerCase");
|
|
23
|
+
Object.defineProperty(exports, "isLowerCase", { enumerable: true, get: function () { return isLowerCase_1.isLowerCase; } });
|
|
24
|
+
var isUpperCase_1 = require("./isUpperCase");
|
|
25
|
+
Object.defineProperty(exports, "isUpperCase", { enumerable: true, get: function () { return isUpperCase_1.isUpperCase; } });
|
|
26
|
+
var isAlphabetic_1 = require("./isAlphabetic");
|
|
27
|
+
Object.defineProperty(exports, "isAlphabetic", { enumerable: true, get: function () { return isAlphabetic_1.isAlphabetic; } });
|
|
28
|
+
var isAlphaNumeric_1 = require("./isAlphaNumeric");
|
|
29
|
+
Object.defineProperty(exports, "isAlphaNumeric", { enumerable: true, get: function () { return isAlphaNumeric_1.isAlphaNumeric; } });
|
|
30
|
+
var isAnagram_1 = require("./isAnagram");
|
|
31
|
+
Object.defineProperty(exports, "isAnagram", { enumerable: true, get: function () { return isAnagram_1.isAnagram; } });
|
|
32
|
+
var isPanagram_1 = require("./isPanagram");
|
|
33
|
+
Object.defineProperty(exports, "isPanagram", { enumerable: true, get: function () { return isPanagram_1.isPanagram; } });
|
|
34
|
+
var isMacAddress_1 = require("./isMacAddress");
|
|
35
|
+
Object.defineProperty(exports, "isMacAddress", { enumerable: true, get: function () { return isMacAddress_1.isMacAddress; } });
|
|
22
36
|
const isCoordinates_2 = require("./isCoordinates");
|
|
23
37
|
const isDate_2 = require("./isDate");
|
|
24
38
|
const isEmail_2 = require("./isEmail");
|
|
@@ -28,6 +42,13 @@ const isURL_2 = require("./isURL");
|
|
|
28
42
|
const isIPv4_2 = require("./isIPv4");
|
|
29
43
|
const isHexColor_2 = require("./isHexColor");
|
|
30
44
|
const isPalindrome_2 = require("./isPalindrome");
|
|
45
|
+
const isLowerCase_2 = require("./isLowerCase");
|
|
46
|
+
const isUpperCase_2 = require("./isUpperCase");
|
|
47
|
+
const isAlphabetic_2 = require("./isAlphabetic");
|
|
48
|
+
const isAlphaNumeric_2 = require("./isAlphaNumeric");
|
|
49
|
+
const isAnagram_2 = require("./isAnagram");
|
|
50
|
+
const isPanagram_2 = require("./isPanagram");
|
|
51
|
+
const isMacAddress_2 = require("./isMacAddress");
|
|
31
52
|
exports.validations = {
|
|
32
53
|
isCoordinates: isCoordinates_2.isCoordinates,
|
|
33
54
|
isDate: isDate_2.isDate,
|
|
@@ -37,5 +58,12 @@ exports.validations = {
|
|
|
37
58
|
isURL: isURL_2.isURL,
|
|
38
59
|
isIPv4: isIPv4_2.isIPv4,
|
|
39
60
|
isHexColor: isHexColor_2.isHexColor,
|
|
40
|
-
isPalindrome: isPalindrome_2.isPalindrome
|
|
61
|
+
isPalindrome: isPalindrome_2.isPalindrome,
|
|
62
|
+
isLowerCase: isLowerCase_2.isLowerCase,
|
|
63
|
+
isUpperCase: isUpperCase_2.isUpperCase,
|
|
64
|
+
isAlphabetic: isAlphabetic_2.isAlphabetic,
|
|
65
|
+
isAlphaNumeric: isAlphaNumeric_2.isAlphaNumeric,
|
|
66
|
+
isAnagram: isAnagram_2.isAnagram,
|
|
67
|
+
isPanagram: isPanagram_2.isPanagram,
|
|
68
|
+
isMacAddress: isMacAddress_2.isMacAddress
|
|
41
69
|
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks whether the given string is alphanumeric.
|
|
3
|
+
*
|
|
4
|
+
* The check ensures that the string contains only
|
|
5
|
+
* letters (a-z, A-Z) and digits (0-9).
|
|
6
|
+
*
|
|
7
|
+
* @param {string} str - The input string to check.
|
|
8
|
+
* @returns {boolean} True if the input is alphanumeric, false otherwise.
|
|
9
|
+
* @throws {TypeError} If the input is not a string.
|
|
10
|
+
*/
|
|
11
|
+
export declare function isAlphaNumeric(str: string): boolean;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isAlphaNumeric = isAlphaNumeric;
|
|
4
|
+
/**
|
|
5
|
+
* Checks whether the given string is alphanumeric.
|
|
6
|
+
*
|
|
7
|
+
* The check ensures that the string contains only
|
|
8
|
+
* letters (a-z, A-Z) and digits (0-9).
|
|
9
|
+
*
|
|
10
|
+
* @param {string} str - The input string to check.
|
|
11
|
+
* @returns {boolean} True if the input is alphanumeric, false otherwise.
|
|
12
|
+
* @throws {TypeError} If the input is not a string.
|
|
13
|
+
*/
|
|
14
|
+
function isAlphaNumeric(str) {
|
|
15
|
+
if (typeof str !== 'string') {
|
|
16
|
+
throw new TypeError('Input must be a string');
|
|
17
|
+
}
|
|
18
|
+
if (str.length === 0) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
return /^[a-z0-9]+$/i.test(str);
|
|
22
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks whether a given string contains only alphabetic characters (A-Z, a-z).
|
|
3
|
+
*
|
|
4
|
+
*
|
|
5
|
+
* @param {string} str - The input string to check.
|
|
6
|
+
* @returns {boolean} True if the input contains only alphabetic characters, otherwise false.
|
|
7
|
+
* @throws {TypeError} If the input is not a string.
|
|
8
|
+
*/
|
|
9
|
+
export declare function isAlphabetic(str: string): boolean;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isAlphabetic = isAlphabetic;
|
|
4
|
+
/**
|
|
5
|
+
* Checks whether a given string contains only alphabetic characters (A-Z, a-z).
|
|
6
|
+
*
|
|
7
|
+
*
|
|
8
|
+
* @param {string} str - The input string to check.
|
|
9
|
+
* @returns {boolean} True if the input contains only alphabetic characters, otherwise false.
|
|
10
|
+
* @throws {TypeError} If the input is not a string.
|
|
11
|
+
*/
|
|
12
|
+
function isAlphabetic(str) {
|
|
13
|
+
if (typeof str !== 'string') {
|
|
14
|
+
throw new TypeError('Input must be a string');
|
|
15
|
+
}
|
|
16
|
+
// empty string is not considered alphabetic
|
|
17
|
+
if (str === '')
|
|
18
|
+
return false;
|
|
19
|
+
// Regular expression to match only alphabetic characters
|
|
20
|
+
return /^[A-Za-z]+$/.test(str);
|
|
21
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks whether two strings are anagrams of each other.
|
|
3
|
+
*
|
|
4
|
+
* Rules:
|
|
5
|
+
* - Comparison is case-insensitive.
|
|
6
|
+
* - Spaces and punctuation are ignored.
|
|
7
|
+
*
|
|
8
|
+
* @param {string} str1 - The first input string.
|
|
9
|
+
* @param {string} str2 - The second input string.
|
|
10
|
+
* @returns {boolean} True if the inputs are anagrams, otherwise false.
|
|
11
|
+
* @throws {TypeError} If either input is not a string.
|
|
12
|
+
*/
|
|
13
|
+
export declare function isAnagram(str1: string, str2: string): boolean;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isAnagram = isAnagram;
|
|
4
|
+
/**
|
|
5
|
+
* Checks whether two strings are anagrams of each other.
|
|
6
|
+
*
|
|
7
|
+
* Rules:
|
|
8
|
+
* - Comparison is case-insensitive.
|
|
9
|
+
* - Spaces and punctuation are ignored.
|
|
10
|
+
*
|
|
11
|
+
* @param {string} str1 - The first input string.
|
|
12
|
+
* @param {string} str2 - The second input string.
|
|
13
|
+
* @returns {boolean} True if the inputs are anagrams, otherwise false.
|
|
14
|
+
* @throws {TypeError} If either input is not a string.
|
|
15
|
+
*/
|
|
16
|
+
function isAnagram(str1, str2) {
|
|
17
|
+
if (typeof str1 !== 'string' || typeof str2 !== 'string') {
|
|
18
|
+
throw new TypeError('Both inputs must be strings');
|
|
19
|
+
}
|
|
20
|
+
// Normalize: lowercase, remove spaces & punctuation
|
|
21
|
+
const normalize = (str) => str.toLowerCase().replace(/[^a-z0-9]/g, '').split('').sort().join('');
|
|
22
|
+
return normalize(str1) === normalize(str2);
|
|
23
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks whether the given string contains only lowercase alphabetic characters.
|
|
3
|
+
*
|
|
4
|
+
* - At least one alphabetic character must be present.
|
|
5
|
+
* - Digits, spaces, and special characters are ignored.
|
|
6
|
+
* - If any uppercase alphabetic character is found, it returns false.
|
|
7
|
+
*
|
|
8
|
+
* @param {string} str - The input string to check.
|
|
9
|
+
* @returns {boolean} True if all alphabetic characters are lowercase and at least one exists, false otherwise.
|
|
10
|
+
* @throws {TypeError} If the input is not a string.
|
|
11
|
+
*/
|
|
12
|
+
export declare function isLowerCase(str: string): boolean;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isLowerCase = isLowerCase;
|
|
4
|
+
/**
|
|
5
|
+
* Checks whether the given string contains only lowercase alphabetic characters.
|
|
6
|
+
*
|
|
7
|
+
* - At least one alphabetic character must be present.
|
|
8
|
+
* - Digits, spaces, and special characters are ignored.
|
|
9
|
+
* - If any uppercase alphabetic character is found, it returns false.
|
|
10
|
+
*
|
|
11
|
+
* @param {string} str - The input string to check.
|
|
12
|
+
* @returns {boolean} True if all alphabetic characters are lowercase and at least one exists, false otherwise.
|
|
13
|
+
* @throws {TypeError} If the input is not a string.
|
|
14
|
+
*/
|
|
15
|
+
function isLowerCase(str) {
|
|
16
|
+
if (typeof str !== 'string') {
|
|
17
|
+
throw new TypeError('Input must be a string');
|
|
18
|
+
}
|
|
19
|
+
if (str.length === 0) {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
let hasLetter = false;
|
|
23
|
+
for (const char of str) {
|
|
24
|
+
if (/[A-Z]/.test(char)) {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
if (/[a-z]/.test(char)) {
|
|
28
|
+
hasLetter = true;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return hasLetter;
|
|
32
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if a given string is a valid MAC address.
|
|
3
|
+
*
|
|
4
|
+
* Valid MAC addresses consist of six pairs of hexadecimal digits (0-9, A-F)
|
|
5
|
+
* separated either by colons (:) or hyphens (-). Example formats:
|
|
6
|
+
* - "00:1A:2B:3C:4D:5E"
|
|
7
|
+
* - "00-1A-2B-3C-4D-5E"
|
|
8
|
+
*
|
|
9
|
+
* Mixed or missing separators, invalid hex characters, or incorrect lengths
|
|
10
|
+
* are not allowed.
|
|
11
|
+
*
|
|
12
|
+
* @param {string} str - The string to validate as a MAC address.
|
|
13
|
+
* @returns {boolean} `true` if the string is a valid MAC address, otherwise `false`.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* isMacAddress("00:1A:2B:3C:4D:5E"); // true
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* isMacAddress("00-1A-2B-3C-4D-5E"); // true
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* isMacAddress("001A:2B:3C:4D:5E"); // false (wrong length)
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* isMacAddress("00:1G:2B:3C:4D:5E"); // false (invalid hex digit 'G')
|
|
26
|
+
*/
|
|
27
|
+
export declare function isMacAddress(str: string): boolean;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isMacAddress = isMacAddress;
|
|
4
|
+
/**
|
|
5
|
+
* Checks if a given string is a valid MAC address.
|
|
6
|
+
*
|
|
7
|
+
* Valid MAC addresses consist of six pairs of hexadecimal digits (0-9, A-F)
|
|
8
|
+
* separated either by colons (:) or hyphens (-). Example formats:
|
|
9
|
+
* - "00:1A:2B:3C:4D:5E"
|
|
10
|
+
* - "00-1A-2B-3C-4D-5E"
|
|
11
|
+
*
|
|
12
|
+
* Mixed or missing separators, invalid hex characters, or incorrect lengths
|
|
13
|
+
* are not allowed.
|
|
14
|
+
*
|
|
15
|
+
* @param {string} str - The string to validate as a MAC address.
|
|
16
|
+
* @returns {boolean} `true` if the string is a valid MAC address, otherwise `false`.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* isMacAddress("00:1A:2B:3C:4D:5E"); // true
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* isMacAddress("00-1A-2B-3C-4D-5E"); // true
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* isMacAddress("001A:2B:3C:4D:5E"); // false (wrong length)
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* isMacAddress("00:1G:2B:3C:4D:5E"); // false (invalid hex digit 'G')
|
|
29
|
+
*/
|
|
30
|
+
function isMacAddress(str) {
|
|
31
|
+
const macRegex = /^([0-9A-Fa-f]{2}([:-])){5}([0-9A-Fa-f]{2})$/;
|
|
32
|
+
// Check regex first
|
|
33
|
+
if (!macRegex.test(str))
|
|
34
|
+
return false;
|
|
35
|
+
// Ensure all separators are the same (either all ':' or all '-')
|
|
36
|
+
const separator = str[2];
|
|
37
|
+
const expectedSeparator = separator === ':' ? ':' : '-';
|
|
38
|
+
for (let i = 2; i < str.length; i += 3) {
|
|
39
|
+
if (str[i] !== expectedSeparator)
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if a given string is a pangram (contains every letter of the English alphabet at least once).
|
|
3
|
+
*
|
|
4
|
+
* The check is case-insensitive, and non-alphabetic characters (numbers, punctuation, spaces)
|
|
5
|
+
* are ignored. An empty string is not considered a pangram.
|
|
6
|
+
*
|
|
7
|
+
* @param {string} str - The input string to validate.
|
|
8
|
+
* @returns {boolean} True if the string is a pangram, otherwise false.
|
|
9
|
+
* @throws {TypeError} If the input is not a string.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* isPangram("The quick brown fox jumps over the lazy dog."); // true
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* isPangram("This is not a pangram."); // false
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* isPangram("Abcdefghijklmnopqrstuvwxyz"); // true
|
|
19
|
+
*/
|
|
20
|
+
export declare function isPanagram(str: string): boolean;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isPanagram = isPanagram;
|
|
4
|
+
/**
|
|
5
|
+
* Checks if a given string is a pangram (contains every letter of the English alphabet at least once).
|
|
6
|
+
*
|
|
7
|
+
* The check is case-insensitive, and non-alphabetic characters (numbers, punctuation, spaces)
|
|
8
|
+
* are ignored. An empty string is not considered a pangram.
|
|
9
|
+
*
|
|
10
|
+
* @param {string} str - The input string to validate.
|
|
11
|
+
* @returns {boolean} True if the string is a pangram, otherwise false.
|
|
12
|
+
* @throws {TypeError} If the input is not a string.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* isPangram("The quick brown fox jumps over the lazy dog."); // true
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* isPangram("This is not a pangram."); // false
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* isPangram("Abcdefghijklmnopqrstuvwxyz"); // true
|
|
22
|
+
*/
|
|
23
|
+
function isPanagram(str) {
|
|
24
|
+
if (typeof str !== 'string') {
|
|
25
|
+
throw new TypeError('Input must be a string');
|
|
26
|
+
}
|
|
27
|
+
if (str === '')
|
|
28
|
+
return false;
|
|
29
|
+
// Normalize string: lowercase and remove non-letters
|
|
30
|
+
const normalized = str.toLowerCase().replace(/[^a-z]/g, '');
|
|
31
|
+
// Create a set of unique letters
|
|
32
|
+
const uniqueLetters = new Set(normalized);
|
|
33
|
+
// Pangram if it has all 26 letters
|
|
34
|
+
return uniqueLetters.size === 26;
|
|
35
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks whether the given string contains only uppercase alphabetic characters.
|
|
3
|
+
*
|
|
4
|
+
* - At least one alphabetic character must be present.
|
|
5
|
+
* - Digits, spaces, and special characters are ignored.
|
|
6
|
+
* - If any lowercase alphabetic character is found, it returns false.
|
|
7
|
+
*
|
|
8
|
+
* @param {string} str - The input string to check.
|
|
9
|
+
* @returns {boolean} True if all alphabetic characters are uppercase and at least one exists, false otherwise.
|
|
10
|
+
* @throws {TypeError} If the input is not a string.
|
|
11
|
+
*/
|
|
12
|
+
export declare function isUpperCase(str: string): boolean;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isUpperCase = isUpperCase;
|
|
4
|
+
/**
|
|
5
|
+
* Checks whether the given string contains only uppercase alphabetic characters.
|
|
6
|
+
*
|
|
7
|
+
* - At least one alphabetic character must be present.
|
|
8
|
+
* - Digits, spaces, and special characters are ignored.
|
|
9
|
+
* - If any lowercase alphabetic character is found, it returns false.
|
|
10
|
+
*
|
|
11
|
+
* @param {string} str - The input string to check.
|
|
12
|
+
* @returns {boolean} True if all alphabetic characters are uppercase and at least one exists, false otherwise.
|
|
13
|
+
* @throws {TypeError} If the input is not a string.
|
|
14
|
+
*/
|
|
15
|
+
function isUpperCase(str) {
|
|
16
|
+
if (typeof str !== 'string') {
|
|
17
|
+
throw new TypeError('Input must be a string');
|
|
18
|
+
}
|
|
19
|
+
if (str.length === 0) {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
let hasLetter = false;
|
|
23
|
+
for (const char of str) {
|
|
24
|
+
if (/[a-z]/.test(char)) {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
if (/[A-Z]/.test(char)) {
|
|
28
|
+
hasLetter = true;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return hasLetter;
|
|
32
|
+
}
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "stringzy",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.1.0",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"build": "tsc",
|
|
8
|
-
"test": "npm run build && node --test",
|
|
8
|
+
"test": " npm run build && node --test",
|
|
9
9
|
"prepublishOnly": "npm run build",
|
|
10
10
|
"format": "prettier --write ."
|
|
11
11
|
},
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"url": "git+https://github.com/Samarth2190/stringzy.git"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
|
-
"@types/node": "^24.
|
|
48
|
+
"@types/node": "^24.5.2",
|
|
49
49
|
"prettier": "^3.6.2",
|
|
50
50
|
"typescript": "^5.8.3"
|
|
51
51
|
}
|