nhb-toolbox 2.8.3 → 2.8.5
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/dist/colors/convert.d.ts +11 -3
- package/dist/colors/convert.d.ts.map +1 -1
- package/dist/colors/convert.js +4 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/string/convert.d.ts +20 -1
- package/dist/string/convert.d.ts.map +1 -1
- package/dist/string/convert.js +38 -5
- package/dist/string/types.d.ts +9 -0
- package/dist/string/types.d.ts.map +1 -1
- package/dist/string/utilities.d.ts +20 -0
- package/dist/string/utilities.d.ts.map +1 -0
- package/dist/string/utilities.js +40 -0
- package/package.json +1 -1
package/dist/colors/convert.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Hex6, Hex8, HSL, HSLA, RGB, RGBA } from './types';
|
|
1
|
+
import type { Hex, Hex6, Hex8, HSL, HSLA, RGB, RGBA } from './types';
|
|
2
2
|
/**
|
|
3
3
|
* * Converts HSL to RGB color format.
|
|
4
4
|
*
|
|
@@ -32,7 +32,7 @@ export declare const convertHslToHex: (h: number, s: number, l: number) => Hex6;
|
|
|
32
32
|
* @param hex - A string representing the color in Hex format (e.g., `#FF0000`).
|
|
33
33
|
* @returns A string representing the color in HSL format (e.g., `hsl(0, 100%, 50%)`).
|
|
34
34
|
*/
|
|
35
|
-
export declare const convertHexToHsl: (hex: Hex6 |
|
|
35
|
+
export declare const convertHexToHsl: (hex: Hex6 | Hex) => HSL;
|
|
36
36
|
/**
|
|
37
37
|
* * Converts RGB to Hex color format.
|
|
38
38
|
*
|
|
@@ -48,7 +48,7 @@ export declare const convertRgbToHex: (r: number, g: number, b: number) => Hex6;
|
|
|
48
48
|
* @param hex - A string representing the color in Hex format (e.g., `#FF0000`).
|
|
49
49
|
* @returns A string representing the color in RGB format (e.g., `rgb(255, 0, 0)`).
|
|
50
50
|
*/
|
|
51
|
-
export declare const convertHexToRgb: (hex: Hex6 | string) => RGB;
|
|
51
|
+
export declare const convertHexToRgb: (hex: Hex6 | Hex | string) => RGB;
|
|
52
52
|
/**
|
|
53
53
|
* * Converts RGB to RGBA format, adding alpha (opacity).
|
|
54
54
|
*
|
|
@@ -91,6 +91,8 @@ export declare const convertHslaToRgba: (h: number, s: number, l: number, a?: nu
|
|
|
91
91
|
export declare const convertRgbaToHsla: (r: number, g: number, b: number, a?: number) => HSLA;
|
|
92
92
|
/**
|
|
93
93
|
* * Converts Hex8 to RGBA color format, including alpha channel.
|
|
94
|
+
* - `Special Note:` Cast the parameter to `Hex8` before converting to `RGBA`.
|
|
95
|
+
* @example convertHex8ToRgba('#FFF122DE' as Hex8)
|
|
94
96
|
*
|
|
95
97
|
* @param hex8 - A string representing the color in Hex8 format (e.g., `#FF000080`).
|
|
96
98
|
* @returns A string representing the color in RGBA format (e.g., `rgba(255, 0, 0, 0.5)`).
|
|
@@ -108,6 +110,8 @@ export declare const convertHex8ToRgba: (hex8: Hex8) => RGBA;
|
|
|
108
110
|
export declare const convertHslaToHex8: (h: number, s: number, l: number, a?: number) => Hex8;
|
|
109
111
|
/**
|
|
110
112
|
* * Converts Hex8 to HSLA color format.
|
|
113
|
+
* - `Special Note:` Cast the parameter to `Hex8` before converting to `HSLA`.
|
|
114
|
+
* @example convertHex8ToHsla('#FFF122DE' as Hex8)
|
|
111
115
|
*
|
|
112
116
|
* @param hex - A string representing the color in Hex format (e.g., `#FF0000DE`).
|
|
113
117
|
* @returns A string representing the color in HSLA format..
|
|
@@ -115,6 +119,8 @@ export declare const convertHslaToHex8: (h: number, s: number, l: number, a?: nu
|
|
|
115
119
|
export declare const convertHex8ToHsla: (hex8: Hex8) => HSLA;
|
|
116
120
|
/**
|
|
117
121
|
* * Converts a `Hex` color code to `RGB` and `HSL` formats.
|
|
122
|
+
* - `Special Note:` Cast the parameter to `Hex6` before converting to `RGB` and `HSL`.
|
|
123
|
+
* @example convertColorCode('#FFF122' as Hex6)
|
|
118
124
|
*
|
|
119
125
|
* @param color The `Hex` color code (e.g., `#3c6945`).
|
|
120
126
|
* @returns An object containing the `RGB` and `HSL` formats of the given `Hex` color.
|
|
@@ -145,6 +151,8 @@ export declare function convertColorCode(color: HSL): {
|
|
|
145
151
|
};
|
|
146
152
|
/**
|
|
147
153
|
* * Converts a `Hex8` color code to `RGB` and `HSL` formats.
|
|
154
|
+
* - `Special Note:` Cast the parameter to `Hex8` before converting to `RGBA` and `HSLA`.
|
|
155
|
+
* @example convertColorCode('#FFF122DE' as Hex8)
|
|
148
156
|
*
|
|
149
157
|
* @param color The `Hex8` color code (e.g., `#3c6945`).
|
|
150
158
|
* @returns An object containing the `RGB` and `HSL` formats of the given `Hex8` color.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"convert.d.ts","sourceRoot":"","sources":["../../src/colors/convert.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAGX,IAAI,EACJ,IAAI,EACJ,GAAG,EACH,IAAI,EAEJ,GAAG,EACH,IAAI,EACJ,MAAM,SAAS,CAAC;AAEjB;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe,MAAO,MAAM,KAAK,MAAM,KAAK,MAAM,KAAG,GAyBjE,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe,MAAO,MAAM,KAAK,MAAM,KAAK,MAAM,KAAG,GAkCjE,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe,MAAO,MAAM,KAAK,MAAM,KAAK,MAAM,KAAG,IAIjE,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,eAAe,QAAS,IAAI,GAAG,
|
|
1
|
+
{"version":3,"file":"convert.d.ts","sourceRoot":"","sources":["../../src/colors/convert.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAGX,GAAG,EACH,IAAI,EACJ,IAAI,EACJ,GAAG,EACH,IAAI,EAEJ,GAAG,EACH,IAAI,EACJ,MAAM,SAAS,C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,iBAAiB,SAAU,IAAI,KAAG,IAI9C,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,IAAI,GAAG;IAC9C,GAAG,EAAE,GAAG,CAAC;IACT,GAAG,EAAE,GAAG,CAAC;CACT,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,GAAG,GAAG;IAC7C,GAAG,EAAE,IAAI,CAAC;IACV,GAAG,EAAE,GAAG,CAAC;CACT,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,GAAG,GAAG;IAC7C,GAAG,EAAE,IAAI,CAAC;IACV,GAAG,EAAE,GAAG,CAAC;CACT,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,IAAI,GAAG;IAC9C,IAAI,EAAE,IAAI,CAAC;IACX,IAAI,EAAE,IAAI,CAAC;CACX,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,IAAI,GAAG;IAC9C,IAAI,EAAE,IAAI,CAAC;IACX,IAAI,EAAE,IAAI,CAAC;CACX,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,IAAI,GAAG;IAC9C,IAAI,EAAE,IAAI,CAAC;IACX,IAAI,EAAE,IAAI,CAAC;CACX,CAAC"}
|
package/dist/colors/convert.js
CHANGED
|
@@ -208,6 +208,8 @@ export const convertRgbaToHsla = (r, g, b, a = 1) => {
|
|
|
208
208
|
};
|
|
209
209
|
/**
|
|
210
210
|
* * Converts Hex8 to RGBA color format, including alpha channel.
|
|
211
|
+
* - `Special Note:` Cast the parameter to `Hex8` before converting to `RGBA`.
|
|
212
|
+
* @example convertHex8ToRgba('#FFF122DE' as Hex8)
|
|
211
213
|
*
|
|
212
214
|
* @param hex8 - A string representing the color in Hex8 format (e.g., `#FF000080`).
|
|
213
215
|
* @returns A string representing the color in RGBA format (e.g., `rgba(255, 0, 0, 0.5)`).
|
|
@@ -241,6 +243,8 @@ export const convertHslaToHex8 = (h, s, l, a = 1) => {
|
|
|
241
243
|
};
|
|
242
244
|
/**
|
|
243
245
|
* * Converts Hex8 to HSLA color format.
|
|
246
|
+
* - `Special Note:` Cast the parameter to `Hex8` before converting to `HSLA`.
|
|
247
|
+
* @example convertHex8ToHsla('#FFF122DE' as Hex8)
|
|
244
248
|
*
|
|
245
249
|
* @param hex - A string representing the color in Hex format (e.g., `#FF0000DE`).
|
|
246
250
|
* @returns A string representing the color in HSLA format..
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { capitalizeString, generateRandomID, trimString, truncateString, } from './string/basics';
|
|
2
2
|
export { generateAnagrams } from './string/anagram';
|
|
3
|
-
export { convertStringCase, replaceAllInString } from './string/convert';
|
|
3
|
+
export { convertStringCase, maskString, replaceAllInString, reverseString, slugifyString, } from './string/convert';
|
|
4
|
+
export { extractNumbersFromString, getLevenshteinDistance, isPalindrome, getLevenshteinDistance as levenshteinDistance, } from './string/utilities';
|
|
4
5
|
export { calculateHCF as calculateGCD, calculateHCF, calculateLCM as calculateLCD, calculateLCM, convertToDecimal, getRandomNumber, isEven, isEven as isEvenNumber, isMultiple, isOdd, isOdd as isOddNumber, } from './number/basics';
|
|
5
6
|
export { numberToWords } from './number/convert';
|
|
6
7
|
export { findPrimeNumbers, isPrime, isPrime as isPrimeNumber, } from './number/prime';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EACN,gBAAgB,EAChB,gBAAgB,EAChB,UAAU,EACV,cAAc,GACd,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAEpD,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","s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EACL,aAAa,IAAI,aAAa,EAC9B,gBAAgB,EAChB,SAAS,EACT,QAAQ,EACR,QAAQ,IAAI,mBAAmB,EAC/B,kBAAkB,EAClB,KAAK,EACL,MAAM,IAAI,WAAW,EACrB,KAAK,IAAI,UAAU,EACnB,QAAQ,IAAI,aAAa,EACzB,KAAK,IAAI,UAAU,GACnB,MAAM,yBAAyB,CAAC;AAGjC,OAAO,EACN,QAAQ,EACR,SAAS,EACT,YAAY,EACZ,OAAO,EACP,YAAY,EACZ,aAAa,EACb,aAAa,IAAI,iBAAiB,EAClC,WAAW,EACX,MAAM,EACN,aAAa,IAAI,SAAS,EAC1B,aAAa,IAAI,iBAAiB,EAClC,eAAe,EACf,aAAa,EACb,KAAK,EACL,MAAM,EACN,OAAO,IAAI,YAAY,EACvB,KAAK,IAAI,UAAU,GACnB,MAAM,mBAAmB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
// ! String Utilities
|
|
2
2
|
export { capitalizeString, generateRandomID, trimString, truncateString, } from './string/basics';
|
|
3
3
|
export { generateAnagrams } from './string/anagram';
|
|
4
|
-
export { convertStringCase, replaceAllInString } from './string/convert';
|
|
4
|
+
export { convertStringCase, maskString, replaceAllInString, reverseString, slugifyString, } from './string/convert';
|
|
5
|
+
export { extractNumbersFromString, getLevenshteinDistance, isPalindrome, getLevenshteinDistance as levenshteinDistance, } from './string/utilities';
|
|
5
6
|
// ! Number Utilities
|
|
6
7
|
export { calculateHCF as calculateGCD, calculateHCF, calculateLCM as calculateLCD, calculateLCM, convertToDecimal, getRandomNumber, isEven, isEven as isEvenNumber, isMultiple, isOdd, isOdd as isOddNumber, } from './number/basics';
|
|
7
8
|
export { numberToWords } from './number/convert';
|
package/dist/string/convert.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { CaseFormat } from './types';
|
|
1
|
+
import type { CaseFormat, MaskOptions } from './types';
|
|
2
2
|
/**
|
|
3
3
|
* Converts a string to a specified case format such as `camelCase`, `snake_case`, `kebab-case`, `PascalCase`, `Title Case`, `lowercase`, or `UPPERCASE`.
|
|
4
4
|
*
|
|
@@ -37,4 +37,23 @@ export declare function convertStringCase(string: string, format: CaseFormat): s
|
|
|
37
37
|
* @returns The modified/refined string with replacements applied.
|
|
38
38
|
*/
|
|
39
39
|
export declare const replaceAllInString: (input: string, find: string | RegExp, replace: string) => string;
|
|
40
|
+
/**
|
|
41
|
+
* * Converts a string into a URL-friendly slug.
|
|
42
|
+
* @param input - The string to be converted.
|
|
43
|
+
* @returns The slugified string.
|
|
44
|
+
*/
|
|
45
|
+
export declare const slugifyString: (input: string) => Lowercase<string>;
|
|
46
|
+
/**
|
|
47
|
+
* * Masks part of a string for privacy.
|
|
48
|
+
* @param input - The string to mask.
|
|
49
|
+
* @param options - Options for masking a string.
|
|
50
|
+
* @returns The masked string.
|
|
51
|
+
*/
|
|
52
|
+
export declare const maskString: (input: string, options?: MaskOptions) => string;
|
|
53
|
+
/**
|
|
54
|
+
* * Reverses a given string.
|
|
55
|
+
* @param input - The string to reverse.
|
|
56
|
+
* @returns The reversed string.
|
|
57
|
+
*/
|
|
58
|
+
export declare const reverseString: (input: string) => string;
|
|
40
59
|
//# sourceMappingURL=convert.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"convert.d.ts","sourceRoot":"","sources":["../../src/string/convert.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"convert.d.ts","sourceRoot":"","sources":["../../src/string/convert.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEvD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,GAAG,MAAM,CAqF5E;AAED;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,kBAAkB,UACvB,MAAM,QACP,MAAM,GAAG,MAAM,WACZ,MAAM,KACb,MAYF,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,aAAa,UAAW,MAAM,KAAG,SAAS,CAAC,MAAM,CAK7D,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,UAAU,UAAW,MAAM,YAAY,WAAW,KAAG,MAcjE,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,aAAa,UAAW,MAAM,KAAG,MAI7C,CAAC"}
|
package/dist/string/convert.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { trimString } from './basics';
|
|
1
2
|
import { LOWERCASE } from './constants';
|
|
2
3
|
/**
|
|
3
4
|
* Converts a string to a specified case format such as `camelCase`, `snake_case`, `kebab-case`, `PascalCase`, `Title Case`, `lowercase`, or `UPPERCASE`.
|
|
@@ -95,13 +96,45 @@ export function convertStringCase(string, format) {
|
|
|
95
96
|
* @returns The modified/refined string with replacements applied.
|
|
96
97
|
*/
|
|
97
98
|
export const replaceAllInString = (input, find, replace) => {
|
|
98
|
-
|
|
99
|
-
return '';
|
|
100
|
-
const trimmedString = input?.trim();
|
|
101
|
-
if (!trimmedString)
|
|
102
|
-
return '';
|
|
99
|
+
const trimmedString = trimString(input);
|
|
103
100
|
const regex = typeof find === 'string' ?
|
|
104
101
|
new RegExp(find, 'g')
|
|
105
102
|
: new RegExp(find, find.flags.includes('g') ? find.flags : find.flags + 'g');
|
|
106
103
|
return trimmedString?.replace(regex, replace);
|
|
107
104
|
};
|
|
105
|
+
/**
|
|
106
|
+
* * Converts a string into a URL-friendly slug.
|
|
107
|
+
* @param input - The string to be converted.
|
|
108
|
+
* @returns The slugified string.
|
|
109
|
+
*/
|
|
110
|
+
export const slugifyString = (input) => {
|
|
111
|
+
return trimString(input)
|
|
112
|
+
.toLowerCase()
|
|
113
|
+
.replace(/[^a-z0-9]+/g, '-')
|
|
114
|
+
.replace(/^-+|-+$/g, '');
|
|
115
|
+
};
|
|
116
|
+
/**
|
|
117
|
+
* * Masks part of a string for privacy.
|
|
118
|
+
* @param input - The string to mask.
|
|
119
|
+
* @param options - Options for masking a string.
|
|
120
|
+
* @returns The masked string.
|
|
121
|
+
*/
|
|
122
|
+
export const maskString = (input, options) => {
|
|
123
|
+
const { start = 1, end = 1, maskCharacter: maskChar = '*' } = options || {};
|
|
124
|
+
const trimmedString = trimString(input);
|
|
125
|
+
if (trimmedString.length <= start + end) {
|
|
126
|
+
return maskChar.repeat(trimmedString.length);
|
|
127
|
+
}
|
|
128
|
+
return (trimmedString.slice(0, start) +
|
|
129
|
+
maskChar.repeat(trimmedString.length - start - end) +
|
|
130
|
+
(end > 0 ? trimmedString.slice(-end) : ''));
|
|
131
|
+
};
|
|
132
|
+
/**
|
|
133
|
+
* * Reverses a given string.
|
|
134
|
+
* @param input - The string to reverse.
|
|
135
|
+
* @returns The reversed string.
|
|
136
|
+
*/
|
|
137
|
+
export const reverseString = (input) => {
|
|
138
|
+
const trimmedString = trimString(input);
|
|
139
|
+
return trimmedString.split('').reverse().join('');
|
|
140
|
+
};
|
package/dist/string/types.d.ts
CHANGED
|
@@ -35,5 +35,14 @@ export interface AnagramOptions {
|
|
|
35
35
|
}
|
|
36
36
|
/** - Case formats for converting a string */
|
|
37
37
|
export type CaseFormat = 'camelCase' | 'snake_case' | 'kebab-case' | 'PascalCase' | 'Title Case' | 'UPPERCASE' | 'lowercase';
|
|
38
|
+
/** Options for masking a string. */
|
|
39
|
+
export interface MaskOptions {
|
|
40
|
+
/** Number of characters to keep at the start. Defaults to `1`. */
|
|
41
|
+
start?: number;
|
|
42
|
+
/** Number of characters to keep at the end. Defaults to `1`. */
|
|
43
|
+
end?: number;
|
|
44
|
+
/** Character to use for masking. Defaults to `*`. */
|
|
45
|
+
maskCharacter?: string;
|
|
46
|
+
}
|
|
38
47
|
export {};
|
|
39
48
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/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+
* @param input - The string to extract numbers from.
|
|
4
|
+
* @returns An array of numbers found in the string.
|
|
5
|
+
*/
|
|
6
|
+
export declare const extractNumbersFromString: (input: string) => number[];
|
|
7
|
+
/**
|
|
8
|
+
* * Checks if a string is a palindrome.
|
|
9
|
+
* @param input - The string to check.
|
|
10
|
+
* @returns True if the string is a palindrome, otherwise false.
|
|
11
|
+
*/
|
|
12
|
+
export declare const isPalindrome: (input: string) => boolean;
|
|
13
|
+
/**
|
|
14
|
+
* * Computes the Levenshtein distance between two strings.
|
|
15
|
+
* @param a - First string.
|
|
16
|
+
* @param b - Second string.
|
|
17
|
+
* @returns The Levenshtein distance between the two strings.
|
|
18
|
+
*/
|
|
19
|
+
export declare const getLevenshteinDistance: (a: string, b: string) => number;
|
|
20
|
+
//# sourceMappingURL=utilities.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utilities.d.ts","sourceRoot":"","sources":["../../src/string/utilities.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,eAAO,MAAM,wBAAwB,UAAW,MAAM,KAAG,MAAM,EAE9D,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,YAAY,UAAW,MAAM,KAAG,OAG5C,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,sBAAsB,MAAO,MAAM,KAAK,MAAM,KAAG,MAqB7D,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { reverseString } from './convert';
|
|
2
|
+
/**
|
|
3
|
+
* * Extracts all numbers from a string as array of numbers.
|
|
4
|
+
* @param input - The string to extract numbers from.
|
|
5
|
+
* @returns An array of numbers found in the string.
|
|
6
|
+
*/
|
|
7
|
+
export const extractNumbersFromString = (input) => {
|
|
8
|
+
return (input.match(/\d+/g) || []).map(Number);
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* * Checks if a string is a palindrome.
|
|
12
|
+
* @param input - The string to check.
|
|
13
|
+
* @returns True if the string is a palindrome, otherwise false.
|
|
14
|
+
*/
|
|
15
|
+
export const isPalindrome = (input) => {
|
|
16
|
+
const normalized = input.toLowerCase().replace(/[^a-z0-9]/g, '');
|
|
17
|
+
return normalized === reverseString(normalized);
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* * Computes the Levenshtein distance between two strings.
|
|
21
|
+
* @param a - First string.
|
|
22
|
+
* @param b - Second string.
|
|
23
|
+
* @returns The Levenshtein distance between the two strings.
|
|
24
|
+
*/
|
|
25
|
+
export const getLevenshteinDistance = (a, b) => {
|
|
26
|
+
const lenA = a.length;
|
|
27
|
+
const lenB = b.length;
|
|
28
|
+
const dp = Array.from({ length: lenA + 1 }, (_, i) => Array.from({ length: lenB + 1 }, (_, j) => i === 0 ? j
|
|
29
|
+
: j === 0 ? i
|
|
30
|
+
: 0));
|
|
31
|
+
for (let i = 1; i <= lenA; i++) {
|
|
32
|
+
for (let j = 1; j <= lenB; j++) {
|
|
33
|
+
dp[i][j] =
|
|
34
|
+
a[i - 1] === b[j - 1] ?
|
|
35
|
+
dp[i - 1][j - 1]
|
|
36
|
+
: 1 + Math.min(dp[i - 1][j], dp[i][j - 1], dp[i - 1][j - 1]);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return dp[lenA][lenB];
|
|
40
|
+
};
|
package/package.json
CHANGED