nhb-toolbox 3.1.4 → 3.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/dist/array/transform.d.ts +25 -0
- package/dist/array/transform.d.ts.map +1 -1
- package/dist/array/transform.js +42 -0
- package/dist/index.d.ts +5 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -4
- package/dist/number/basics.d.ts +35 -0
- package/dist/number/basics.d.ts.map +1 -1
- package/dist/number/basics.js +53 -0
- package/dist/string/convert.d.ts +18 -0
- package/dist/string/convert.d.ts.map +1 -1
- package/dist/string/convert.js +24 -0
- package/dist/string/guards.d.ts +37 -0
- package/dist/string/guards.d.ts.map +1 -0
- package/dist/string/guards.js +50 -0
- package/dist/string/utilities.d.ts +0 -6
- package/dist/string/utilities.d.ts.map +1 -1
- package/dist/string/utilities.js +0 -10
- package/package.json +1 -1
|
@@ -15,4 +15,29 @@ export declare const createOptionsArray: <T extends GenericObject, K1 extends st
|
|
|
15
15
|
* @returns A new array with duplicates removed.
|
|
16
16
|
*/
|
|
17
17
|
export declare function removeDuplicatesFromArray<T>(array: T[]): T[];
|
|
18
|
+
/**
|
|
19
|
+
* * Splits an array into chunks of a given size.
|
|
20
|
+
*
|
|
21
|
+
* @param arr The array to split.
|
|
22
|
+
* @param chunkSize The size of each chunk.
|
|
23
|
+
* @returns An array of chunked arrays.
|
|
24
|
+
*/
|
|
25
|
+
export declare function splitArray<T>(arr: T[], chunkSize: number): T[][];
|
|
26
|
+
/**
|
|
27
|
+
* * Rotates an array left or right by a given number of steps.
|
|
28
|
+
*
|
|
29
|
+
* @param arr The array to rotate.
|
|
30
|
+
* @param steps The number of positions to rotate (positive: right, negative: left).
|
|
31
|
+
* @returns The rotated array.
|
|
32
|
+
*/
|
|
33
|
+
export declare function rotateArray<T>(arr: T[], steps: number): T[];
|
|
34
|
+
/**
|
|
35
|
+
* * Moves an element within an array from one index to another.
|
|
36
|
+
*
|
|
37
|
+
* @param arr The array to modify.
|
|
38
|
+
* @param fromIndex The index of the element to move.
|
|
39
|
+
* @param toIndex The new index for the element.
|
|
40
|
+
* @returns A new array with the element moved.
|
|
41
|
+
*/
|
|
42
|
+
export declare function moveArrayElement<T>(arr: T[], fromIndex: number, toIndex: number): T[];
|
|
18
43
|
//# sourceMappingURL=transform.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["../../src/array/transform.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAErD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE7C;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB,GAC9B,CAAC,SAAS,aAAa,EACvB,EAAE,SAAS,MAAM,YACjB,EAAE,SAAS,MAAM,kBAEX,CAAC,EAAE,UACD,aAAa,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,CAAC,KAC9B,GAAG,CAAC,IAAI,EAAE,GAAG,EAAE,GAAG,MAAM,GAAE,EAgB5B,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,yBAAyB,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,CAAC,EAAE,CAK5D"}
|
|
1
|
+
{"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["../../src/array/transform.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAErD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE7C;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB,GAC9B,CAAC,SAAS,aAAa,EACvB,EAAE,SAAS,MAAM,YACjB,EAAE,SAAS,MAAM,kBAEX,CAAC,EAAE,UACD,aAAa,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,CAAC,KAC9B,GAAG,CAAC,IAAI,EAAE,GAAG,EAAE,GAAG,MAAM,GAAE,EAgB5B,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,yBAAyB,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,CAAC,EAAE,CAK5D;AAED;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,EAAE,SAAS,EAAE,MAAM,GAAG,CAAC,EAAE,EAAE,CAQhE;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,EAAE,KAAK,EAAE,MAAM,GAAG,CAAC,EAAE,CAQ3D;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EACjC,GAAG,EAAE,CAAC,EAAE,EACR,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,GACb,CAAC,EAAE,CAQL"}
|
package/dist/array/transform.js
CHANGED
|
@@ -27,3 +27,45 @@ export const createOptionsArray = (data, config) => {
|
|
|
27
27
|
export function removeDuplicatesFromArray(array) {
|
|
28
28
|
return array.filter((item, index, self) => index === self.findIndex((el) => isDeepEqual(el, item)));
|
|
29
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* * Splits an array into chunks of a given size.
|
|
32
|
+
*
|
|
33
|
+
* @param arr The array to split.
|
|
34
|
+
* @param chunkSize The size of each chunk.
|
|
35
|
+
* @returns An array of chunked arrays.
|
|
36
|
+
*/
|
|
37
|
+
export function splitArray(arr, chunkSize) {
|
|
38
|
+
const result = [];
|
|
39
|
+
for (let i = 0; i < arr.length; i += chunkSize) {
|
|
40
|
+
result.push(arr.slice(i, i + chunkSize));
|
|
41
|
+
}
|
|
42
|
+
return result;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* * Rotates an array left or right by a given number of steps.
|
|
46
|
+
*
|
|
47
|
+
* @param arr The array to rotate.
|
|
48
|
+
* @param steps The number of positions to rotate (positive: right, negative: left).
|
|
49
|
+
* @returns The rotated array.
|
|
50
|
+
*/
|
|
51
|
+
export function rotateArray(arr, steps) {
|
|
52
|
+
const length = arr.length;
|
|
53
|
+
if (length === 0)
|
|
54
|
+
return arr;
|
|
55
|
+
const offset = ((steps % length) + length) % length;
|
|
56
|
+
return arr.slice(-offset).concat(arr.slice(0, -offset));
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* * Moves an element within an array from one index to another.
|
|
60
|
+
*
|
|
61
|
+
* @param arr The array to modify.
|
|
62
|
+
* @param fromIndex The index of the element to move.
|
|
63
|
+
* @param toIndex The new index for the element.
|
|
64
|
+
* @returns A new array with the element moved.
|
|
65
|
+
*/
|
|
66
|
+
export function moveArrayElement(arr, fromIndex, toIndex) {
|
|
67
|
+
const newArr = [...arr];
|
|
68
|
+
const [item] = newArr.splice(fromIndex, 1);
|
|
69
|
+
newArr.splice(toIndex, 0, item);
|
|
70
|
+
return newArr;
|
|
71
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
export { capitalizeString, generateRandomID, trimString, truncateString, } from './string/basics';
|
|
2
2
|
export { generateAnagrams } from './string/anagram';
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
5
|
-
export {
|
|
3
|
+
export { isCamelCase, isEmojiOnly, isKebabCase, isPalindrome, isPascalCase, isSnakeCase, } from './string/guards';
|
|
4
|
+
export { convertStringCase, extractEmails, extractURLs, maskString, normalizeString, replaceAllInString, reverseString, slugifyString, } from './string/convert';
|
|
5
|
+
export { extractNumbersFromString, getLevenshteinDistance, getLevenshteinDistance as levenshteinDistance, } from './string/utilities';
|
|
6
|
+
export { calculateHCF as calculateGCD, calculateHCF, calculateLCM as calculateLCD, calculateLCM, convertToDecimal, getFibonacciSeries as getFibonacci, getFibonacciSeries as getFibonacciNumbers, getFibonacciSeries, getRandomNumber, isEven, isEven as isEvenNumber, isFibonacci, isFibonacci as isParOfFibonacci, isFibonacci as isParOfFibonacciSeries, isMultiple, isOdd, isOdd as isOddNumber, isPerfectSquare, reverseNumber, sumDigits, } from './number/basics';
|
|
6
7
|
export { numberToWords as convertNumberToWords, convertToRomanNumerals, numberToWords, } from './number/convert';
|
|
7
8
|
export { findPrimeNumbers, isPrime, isPrime as isPrimeNumber, } from './number/prime';
|
|
8
9
|
export { clampNumber, formatCurrency as convertNumberToCurrency, formatCurrency, getRandomFloat as getRandomDecimal, getRandomFloat, roundToNearest as roundNumber, roundToNearest as roundNumberToNearestInterval, roundToNearest, roundToNearest as roundToNearestInterval, } from './number/utilities';
|
|
@@ -13,7 +14,7 @@ export { convertColorCode, convertHex8ToHsla, convertHex8ToRgba, convertHexToHsl
|
|
|
13
14
|
export { Color, Color as Colour } from './colors/Color';
|
|
14
15
|
export { filterArrayOfObjects, flattenArray, getLastArrayElement, isInvalidOrEmptyArray, isInvalidOrEmptyArray as isValidEmptyArray, shuffleArray, } from './array/basics';
|
|
15
16
|
export { sortAnArray } from './array/sort';
|
|
16
|
-
export { createOptionsArray, removeDuplicatesFromArray, } from './array/transform';
|
|
17
|
+
export { createOptionsArray, moveArrayElement, removeDuplicatesFromArray, rotateArray, splitArray, } from './array/transform';
|
|
17
18
|
export { createControlledFormData as convertIntoFormData, createControlledFormData, createControlledFormData as createFormData, } from './form/convert';
|
|
18
19
|
export { isCustomFile, isCustomFileArray, isFileArray, isFileList, isFileUpload, isOriginFileObj, isValidFormData, } from './form/guards';
|
|
19
20
|
export { cloneObject, countObjectFields } from './object/basics';
|
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,EACN,iBAAiB,EACjB,UAAU,EACV,kBAAkB,EAClB,aAAa,EACb,aAAa,GACb,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EACN,wBAAwB,EACxB,sBAAsB,EACtB,
|
|
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,EACN,WAAW,EACX,WAAW,EACX,WAAW,EACX,YAAY,EACZ,YAAY,EACZ,WAAW,GACX,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACN,iBAAiB,EACjB,aAAa,EACb,WAAW,EACX,UAAU,EACV,eAAe,EACf,kBAAkB,EAClB,aAAa,EACb,aAAa,GACb,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EACN,wBAAwB,EACxB,sBAAsB,EACtB,sBAAsB,IAAI,mBAAmB,GAC7C,MAAM,oBAAoB,CAAC;AAG5B,OAAO,EACN,YAAY,IAAI,YAAY,EAC5B,YAAY,EACZ,YAAY,IAAI,YAAY,EAC5B,YAAY,EACZ,gBAAgB,EAChB,kBAAkB,IAAI,YAAY,EAClC,kBAAkB,IAAI,mBAAmB,EACzC,kBAAkB,EAClB,eAAe,EACf,MAAM,EACN,MAAM,IAAI,YAAY,EACtB,WAAW,EACX,WAAW,IAAI,gBAAgB,EAC/B,WAAW,IAAI,sBAAsB,EACrC,UAAU,EACV,KAAK,EACL,KAAK,IAAI,WAAW,EACpB,eAAe,EACf,aAAa,EACb,SAAS,GACT,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACN,aAAa,IAAI,oBAAoB,EACrC,sBAAsB,EACtB,aAAa,GACb,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EACN,gBAAgB,EAChB,OAAO,EACP,OAAO,IAAI,aAAa,GACxB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EACN,WAAW,EACX,cAAc,IAAI,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,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,10 +1,11 @@
|
|
|
1
1
|
// ! String Utilities
|
|
2
2
|
export { capitalizeString, generateRandomID, trimString, truncateString, } from './string/basics';
|
|
3
3
|
export { generateAnagrams } from './string/anagram';
|
|
4
|
-
export {
|
|
5
|
-
export {
|
|
4
|
+
export { isCamelCase, isEmojiOnly, isKebabCase, isPalindrome, isPascalCase, isSnakeCase, } from './string/guards';
|
|
5
|
+
export { convertStringCase, extractEmails, extractURLs, maskString, normalizeString, replaceAllInString, reverseString, slugifyString, } from './string/convert';
|
|
6
|
+
export { extractNumbersFromString, getLevenshteinDistance, getLevenshteinDistance as levenshteinDistance, } from './string/utilities';
|
|
6
7
|
// ! Number Utilities
|
|
7
|
-
export { calculateHCF as calculateGCD, calculateHCF, calculateLCM as calculateLCD, calculateLCM, convertToDecimal, getRandomNumber, isEven, isEven as isEvenNumber, isMultiple, isOdd, isOdd as isOddNumber, } from './number/basics';
|
|
8
|
+
export { calculateHCF as calculateGCD, calculateHCF, calculateLCM as calculateLCD, calculateLCM, convertToDecimal, getFibonacciSeries as getFibonacci, getFibonacciSeries as getFibonacciNumbers, getFibonacciSeries, getRandomNumber, isEven, isEven as isEvenNumber, isFibonacci, isFibonacci as isParOfFibonacci, isFibonacci as isParOfFibonacciSeries, isMultiple, isOdd, isOdd as isOddNumber, isPerfectSquare, reverseNumber, sumDigits, } from './number/basics';
|
|
8
9
|
export { numberToWords as convertNumberToWords, convertToRomanNumerals, numberToWords, } from './number/convert';
|
|
9
10
|
export { findPrimeNumbers, isPrime, isPrime as isPrimeNumber, } from './number/prime';
|
|
10
11
|
export { clampNumber, formatCurrency as convertNumberToCurrency, formatCurrency, getRandomFloat as getRandomDecimal, getRandomFloat, roundToNearest as roundNumber, roundToNearest as roundNumberToNearestInterval, roundToNearest, roundToNearest as roundToNearestInterval, } from './number/utilities';
|
|
@@ -17,7 +18,7 @@ export { Color, Color as Colour } from './colors/Color';
|
|
|
17
18
|
// ! Array Utilities
|
|
18
19
|
export { filterArrayOfObjects, flattenArray, getLastArrayElement, isInvalidOrEmptyArray, isInvalidOrEmptyArray as isValidEmptyArray, shuffleArray, } from './array/basics';
|
|
19
20
|
export { sortAnArray } from './array/sort';
|
|
20
|
-
export { createOptionsArray, removeDuplicatesFromArray, } from './array/transform';
|
|
21
|
+
export { createOptionsArray, moveArrayElement, removeDuplicatesFromArray, rotateArray, splitArray, } from './array/transform';
|
|
21
22
|
// ! Form Utilities
|
|
22
23
|
export { createControlledFormData as convertIntoFormData, createControlledFormData, createControlledFormData as createFormData, } from './form/convert';
|
|
23
24
|
export { isCustomFile, isCustomFileArray, isFileArray, isFileList, isFileUpload, isOriginFileObj, isValidFormData, } from './form/guards';
|
package/dist/number/basics.d.ts
CHANGED
|
@@ -52,4 +52,39 @@ export declare const isOdd: (input: number) => boolean;
|
|
|
52
52
|
* @returns `true` if `input` is a multiple of `multipleOf`, otherwise `false`.
|
|
53
53
|
*/
|
|
54
54
|
export declare const isMultiple: (input: number, multipleOf: number) => boolean;
|
|
55
|
+
/**
|
|
56
|
+
* * Checks if a number is a perfect square.
|
|
57
|
+
*
|
|
58
|
+
* @param num The number to check.
|
|
59
|
+
* @returns `true` if the number is a perfect square, otherwise `false`.
|
|
60
|
+
*/
|
|
61
|
+
export declare function isPerfectSquare(num: number): boolean;
|
|
62
|
+
/**
|
|
63
|
+
* * Checks if a number is part of the Fibonacci sequence.
|
|
64
|
+
*
|
|
65
|
+
* @param num The number to check.
|
|
66
|
+
* @returns `true` if the number is a Fibonacci number, otherwise `false`.
|
|
67
|
+
*/
|
|
68
|
+
export declare function isFibonacci(num: number): boolean;
|
|
69
|
+
/**
|
|
70
|
+
* * Generates the first `n` Fibonacci numbers.
|
|
71
|
+
*
|
|
72
|
+
* @param n The number of Fibonacci numbers to generate.
|
|
73
|
+
* @returns An array containing the first `n` Fibonacci numbers.
|
|
74
|
+
*/
|
|
75
|
+
export declare function getFibonacciSeries(n: number): number[];
|
|
76
|
+
/**
|
|
77
|
+
* * Sums up all digits of a number.
|
|
78
|
+
*
|
|
79
|
+
* @param num The input number.
|
|
80
|
+
* @returns The sum of its digits.
|
|
81
|
+
*/
|
|
82
|
+
export declare function sumDigits(num: number): number;
|
|
83
|
+
/**
|
|
84
|
+
* * Reverses a number (e.g., `123` → `321`).
|
|
85
|
+
*
|
|
86
|
+
* @param num The number to reverse.
|
|
87
|
+
* @returns The reversed number.
|
|
88
|
+
*/
|
|
89
|
+
export declare function reverseNumber(num: number): number;
|
|
55
90
|
//# sourceMappingURL=basics.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"basics.d.ts","sourceRoot":"","sources":["../../src/number/basics.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACX,gBAAgB,EAChB,cAAc,EACd,mBAAmB,EACnB,MAAM,SAAS,CAAC;AAEjB;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe,aAAc,mBAAmB,KAAG,MA+C/D,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,GAAI,CAAC,SAAS,OAAO,GAAG,SAAS,iBACtD,MAAM,GAAG,GAAG,MAAM,EAAE,YACjB,cAAc,CAAC,CAAC,CAAC,KACzB,gBAAgB,CAAC,CAAC,CAQpB,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,YAAY,eAAgB,MAAM,EAAE,KAAG,MAQnD,CAAC;AAEF;;;;;GAKG;AACH,e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AAO,CAIhD;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAQtD;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAK7C;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAOjD"}
|
package/dist/number/basics.js
CHANGED
|
@@ -108,3 +108,56 @@ export const isOdd = (input) => {
|
|
|
108
108
|
export const isMultiple = (input, multipleOf) => {
|
|
109
109
|
return input % multipleOf === 0;
|
|
110
110
|
};
|
|
111
|
+
/**
|
|
112
|
+
* * Checks if a number is a perfect square.
|
|
113
|
+
*
|
|
114
|
+
* @param num The number to check.
|
|
115
|
+
* @returns `true` if the number is a perfect square, otherwise `false`.
|
|
116
|
+
*/
|
|
117
|
+
export function isPerfectSquare(num) {
|
|
118
|
+
return Number.isInteger(Math.sqrt(num));
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* * Checks if a number is part of the Fibonacci sequence.
|
|
122
|
+
*
|
|
123
|
+
* @param num The number to check.
|
|
124
|
+
* @returns `true` if the number is a Fibonacci number, otherwise `false`.
|
|
125
|
+
*/
|
|
126
|
+
export function isFibonacci(num) {
|
|
127
|
+
return (isPerfectSquare(5 * num * num + 4) || isPerfectSquare(5 * num * num - 4));
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* * Generates the first `n` Fibonacci numbers.
|
|
131
|
+
*
|
|
132
|
+
* @param n The number of Fibonacci numbers to generate.
|
|
133
|
+
* @returns An array containing the first `n` Fibonacci numbers.
|
|
134
|
+
*/
|
|
135
|
+
export function getFibonacciSeries(n) {
|
|
136
|
+
const series = [0, 1];
|
|
137
|
+
for (let i = 2; i < n; i++) {
|
|
138
|
+
series.push(series[i - 1] + series[i - 2]);
|
|
139
|
+
}
|
|
140
|
+
return series.slice(0, n);
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* * Sums up all digits of a number.
|
|
144
|
+
*
|
|
145
|
+
* @param num The input number.
|
|
146
|
+
* @returns The sum of its digits.
|
|
147
|
+
*/
|
|
148
|
+
export function sumDigits(num) {
|
|
149
|
+
return Math.abs(num)
|
|
150
|
+
.toString()
|
|
151
|
+
.split('')
|
|
152
|
+
.reduce((sum, digit) => sum + Number(digit), 0);
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* * Reverses a number (e.g., `123` → `321`).
|
|
156
|
+
*
|
|
157
|
+
* @param num The number to reverse.
|
|
158
|
+
* @returns The reversed number.
|
|
159
|
+
*/
|
|
160
|
+
export function reverseNumber(num) {
|
|
161
|
+
const reversed = parseInt(Math.abs(num).toString().split('').reverse().join(''), 10);
|
|
162
|
+
return num < 0 ? -reversed : reversed;
|
|
163
|
+
}
|
package/dist/string/convert.d.ts
CHANGED
|
@@ -56,4 +56,22 @@ export declare const maskString: (input: string, options?: MaskOptions) => strin
|
|
|
56
56
|
* @returns The reversed string.
|
|
57
57
|
*/
|
|
58
58
|
export declare const reverseString: (input: string) => string;
|
|
59
|
+
/**
|
|
60
|
+
* * Normalizes a string by removing diacritics (accents).
|
|
61
|
+
* @param str The input string.
|
|
62
|
+
* @returns The normalized string.
|
|
63
|
+
*/
|
|
64
|
+
export declare function normalizeString(str: string): string;
|
|
65
|
+
/**
|
|
66
|
+
* * Extracts all email addresses from a string.
|
|
67
|
+
* @param str The input string.
|
|
68
|
+
* @returns An array of extracted email addresses.
|
|
69
|
+
*/
|
|
70
|
+
export declare function extractEmails(str: string): string[];
|
|
71
|
+
/**
|
|
72
|
+
* * Extracts all URLs from a string.
|
|
73
|
+
* @param str The input string.
|
|
74
|
+
* @returns An array of extracted URLs.
|
|
75
|
+
*/
|
|
76
|
+
export declare function extractURLs(str: string): string[];
|
|
59
77
|
//# sourceMappingURL=convert.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
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"}
|
|
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;AAEF;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEnD;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,CAEnD;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,CAEjD"}
|
package/dist/string/convert.js
CHANGED
|
@@ -138,3 +138,27 @@ export const reverseString = (input) => {
|
|
|
138
138
|
const trimmedString = trimString(input);
|
|
139
139
|
return trimmedString.split('').reverse().join('');
|
|
140
140
|
};
|
|
141
|
+
/**
|
|
142
|
+
* * Normalizes a string by removing diacritics (accents).
|
|
143
|
+
* @param str The input string.
|
|
144
|
+
* @returns The normalized string.
|
|
145
|
+
*/
|
|
146
|
+
export function normalizeString(str) {
|
|
147
|
+
return str.normalize('NFD').replace(/[\u0300-\u036f]/g, '');
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* * Extracts all email addresses from a string.
|
|
151
|
+
* @param str The input string.
|
|
152
|
+
* @returns An array of extracted email addresses.
|
|
153
|
+
*/
|
|
154
|
+
export function extractEmails(str) {
|
|
155
|
+
return str.match(/[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/g) || [];
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* * Extracts all URLs from a string.
|
|
159
|
+
* @param str The input string.
|
|
160
|
+
* @returns An array of extracted URLs.
|
|
161
|
+
*/
|
|
162
|
+
export function extractURLs(str) {
|
|
163
|
+
return str.match(/https?:\/\/[^\s/$.?#].[^\s]*/g) || [];
|
|
164
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* * Checks if a string is a palindrome.
|
|
3
|
+
* @param input - The string to check.
|
|
4
|
+
* @returns True if the string is a palindrome, otherwise false.
|
|
5
|
+
*/
|
|
6
|
+
export declare const isPalindrome: (input: string) => boolean;
|
|
7
|
+
/**
|
|
8
|
+
* * Checks if a string is in camelCase format.
|
|
9
|
+
* @param str The string to check.
|
|
10
|
+
* @returns `true` if the string is in camelCase, otherwise `false`.
|
|
11
|
+
*/
|
|
12
|
+
export declare function isCamelCase(str: string): boolean;
|
|
13
|
+
/**
|
|
14
|
+
* * Checks if a string is in PascalCase format.
|
|
15
|
+
* @param str The string to check.
|
|
16
|
+
* @returns `true` if the string is in PascalCase, otherwise `false`.
|
|
17
|
+
*/
|
|
18
|
+
export declare function isPascalCase(str: string): boolean;
|
|
19
|
+
/**
|
|
20
|
+
* * Checks if a string is in snake_case format.
|
|
21
|
+
* @param str The string to check.
|
|
22
|
+
* @returns `true` if the string is in snake_case, otherwise `false`.
|
|
23
|
+
*/
|
|
24
|
+
export declare function isSnakeCase(str: string): boolean;
|
|
25
|
+
/**
|
|
26
|
+
* * Checks if a string is in kebab-case format.
|
|
27
|
+
* @param str The string to check.
|
|
28
|
+
* @returns `true` if the string is in kebab-case, otherwise `false`.
|
|
29
|
+
*/
|
|
30
|
+
export declare function isKebabCase(str: string): boolean;
|
|
31
|
+
/**
|
|
32
|
+
* * Checks if a string contains only emojis.
|
|
33
|
+
* @param str The string to check.
|
|
34
|
+
* @returns `true` if the string contains only emojis, otherwise `false`.
|
|
35
|
+
*/
|
|
36
|
+
export declare function isEmojiOnly(str: string): boolean;
|
|
37
|
+
//# sourceMappingURL=guards.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"guards.d.ts","sourceRoot":"","sources":["../../src/string/guards.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,eAAO,MAAM,YAAY,UAAW,MAAM,KAAG,OAG5C,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAEhD;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAEjD;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAEhD;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAEhD;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAEhD"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { reverseString } from './convert';
|
|
2
|
+
/**
|
|
3
|
+
* * Checks if a string is a palindrome.
|
|
4
|
+
* @param input - The string to check.
|
|
5
|
+
* @returns True if the string is a palindrome, otherwise false.
|
|
6
|
+
*/
|
|
7
|
+
export const isPalindrome = (input) => {
|
|
8
|
+
const normalized = input.toLowerCase().replace(/[^a-z0-9]/g, '');
|
|
9
|
+
return normalized === reverseString(normalized);
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* * Checks if a string is in camelCase format.
|
|
13
|
+
* @param str The string to check.
|
|
14
|
+
* @returns `true` if the string is in camelCase, otherwise `false`.
|
|
15
|
+
*/
|
|
16
|
+
export function isCamelCase(str) {
|
|
17
|
+
return /^[a-z]+([A-Z][a-z]*)*$/.test(str);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* * Checks if a string is in PascalCase format.
|
|
21
|
+
* @param str The string to check.
|
|
22
|
+
* @returns `true` if the string is in PascalCase, otherwise `false`.
|
|
23
|
+
*/
|
|
24
|
+
export function isPascalCase(str) {
|
|
25
|
+
return /^[A-Z][a-zA-Z]*$/.test(str);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* * Checks if a string is in snake_case format.
|
|
29
|
+
* @param str The string to check.
|
|
30
|
+
* @returns `true` if the string is in snake_case, otherwise `false`.
|
|
31
|
+
*/
|
|
32
|
+
export function isSnakeCase(str) {
|
|
33
|
+
return /^[a-z]+(_[a-z]+)*$/.test(str);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* * Checks if a string is in kebab-case format.
|
|
37
|
+
* @param str The string to check.
|
|
38
|
+
* @returns `true` if the string is in kebab-case, otherwise `false`.
|
|
39
|
+
*/
|
|
40
|
+
export function isKebabCase(str) {
|
|
41
|
+
return /^[a-z]+(-[a-z]+)*$/.test(str);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* * Checks if a string contains only emojis.
|
|
45
|
+
* @param str The string to check.
|
|
46
|
+
* @returns `true` if the string contains only emojis, otherwise `false`.
|
|
47
|
+
*/
|
|
48
|
+
export function isEmojiOnly(str) {
|
|
49
|
+
return /^[\p{Emoji}]+$/u.test(str);
|
|
50
|
+
}
|
|
@@ -4,12 +4,6 @@
|
|
|
4
4
|
* @returns An array of numbers found in the string.
|
|
5
5
|
*/
|
|
6
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
7
|
/**
|
|
14
8
|
* * Computes the Levenshtein distance between two strings.
|
|
15
9
|
* @param a - First string.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utilities.d.ts","sourceRoot":"","sources":["../../src/string/utilities.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utilities.d.ts","sourceRoot":"","sources":["../../src/string/utilities.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,eAAO,MAAM,wBAAwB,UAAW,MAAM,KAAG,MAAM,EAE9D,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,sBAAsB,MAAO,MAAM,KAAK,MAAM,KAAG,MAqB7D,CAAC"}
|
package/dist/string/utilities.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { reverseString } from './convert';
|
|
2
1
|
/**
|
|
3
2
|
* * Extracts all numbers from a string as array of numbers.
|
|
4
3
|
* @param input - The string to extract numbers from.
|
|
@@ -7,15 +6,6 @@ import { reverseString } from './convert';
|
|
|
7
6
|
export const extractNumbersFromString = (input) => {
|
|
8
7
|
return (input.match(/\d+/g) || []).map(Number);
|
|
9
8
|
};
|
|
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
9
|
/**
|
|
20
10
|
* * Computes the Levenshtein distance between two strings.
|
|
21
11
|
* @param a - First string.
|
package/package.json
CHANGED