nhb-toolbox 2.8.1 → 2.8.2
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/basics.js +7 -15
- package/dist/array/sort.js +1 -4
- package/dist/array/transform.js +4 -9
- package/dist/array/types.js +1 -2
- package/dist/colors/Color.js +17 -21
- package/dist/colors/constants.js +2 -5
- package/dist/colors/convert.js +56 -73
- package/dist/colors/helpers.js +13 -29
- package/dist/colors/initials.js +13 -16
- package/dist/colors/random.js +7 -12
- package/dist/colors/types.js +1 -2
- package/dist/form/convert.js +4 -9
- package/dist/form/guards.js +4 -10
- package/dist/form/transform.js +9 -13
- package/dist/form/types.js +1 -2
- package/dist/guards/non-primitives.js +17 -34
- package/dist/guards/primitives.js +12 -26
- package/dist/guards/specials.js +23 -37
- package/dist/index.js +25 -156
- package/dist/number/basics.js +11 -21
- package/dist/number/constants.js +4 -7
- package/dist/number/convert.js +5 -8
- package/dist/number/helpers.js +11 -18
- package/dist/number/prime.js +3 -8
- package/dist/number/range.js +12 -15
- package/dist/number/types.js +1 -2
- package/dist/object/basics.js +8 -16
- package/dist/object/convert.js +1 -4
- package/dist/object/objectify.js +22 -32
- package/dist/object/sanitize.js +8 -11
- package/dist/object/types.js +1 -2
- package/dist/string/anagram.js +1 -4
- package/dist/string/basics.js +4 -11
- package/dist/string/constants.js +1 -4
- package/dist/string/convert.js +4 -9
- package/dist/string/types.js +1 -2
- package/dist/types/index.js +1 -2
- package/dist/utils/index.js +8 -15
- package/package.json +2 -1
|
@@ -1,23 +1,9 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isNumber = isNumber;
|
|
4
|
-
exports.isString = isString;
|
|
5
|
-
exports.isInteger = isInteger;
|
|
6
|
-
exports.isPositiveInteger = isPositiveInteger;
|
|
7
|
-
exports.isBoolean = isBoolean;
|
|
8
|
-
exports.isNull = isNull;
|
|
9
|
-
exports.isUndefined = isUndefined;
|
|
10
|
-
exports.isSymbol = isSymbol;
|
|
11
|
-
exports.isPrimitive = isPrimitive;
|
|
12
|
-
exports.isNonEmptyString = isNonEmptyString;
|
|
13
|
-
exports.isFalsy = isFalsy;
|
|
14
|
-
exports.isTruthy = isTruthy;
|
|
15
1
|
/**
|
|
16
2
|
* Type guard to check if a value is a number.
|
|
17
3
|
* @param value - The value to check.
|
|
18
4
|
* @returns `true` if the value is a number, otherwise `false`.
|
|
19
5
|
*/
|
|
20
|
-
function isNumber(value) {
|
|
6
|
+
export function isNumber(value) {
|
|
21
7
|
return typeof value === 'number' && !isNaN(value);
|
|
22
8
|
}
|
|
23
9
|
/**
|
|
@@ -25,7 +11,7 @@ function isNumber(value) {
|
|
|
25
11
|
* @param value - The value to check.
|
|
26
12
|
* @returns `true` if the value is a string, otherwise `false`.
|
|
27
13
|
*/
|
|
28
|
-
function isString(value) {
|
|
14
|
+
export function isString(value) {
|
|
29
15
|
return typeof value === 'string';
|
|
30
16
|
}
|
|
31
17
|
/**
|
|
@@ -33,7 +19,7 @@ function isString(value) {
|
|
|
33
19
|
* @param value - The value to check.
|
|
34
20
|
* @returns `true` if the value is an integer, otherwise `false`.
|
|
35
21
|
*/
|
|
36
|
-
function isInteger(value) {
|
|
22
|
+
export function isInteger(value) {
|
|
37
23
|
return isNumber(value) && Number.isInteger(value);
|
|
38
24
|
}
|
|
39
25
|
/**
|
|
@@ -41,7 +27,7 @@ function isInteger(value) {
|
|
|
41
27
|
* @param value - The value to check.
|
|
42
28
|
* @returns `true` if the value is a positive integer, otherwise `false`.
|
|
43
29
|
*/
|
|
44
|
-
function isPositiveInteger(value) {
|
|
30
|
+
export function isPositiveInteger(value) {
|
|
45
31
|
return isInteger(value) && value > 0;
|
|
46
32
|
}
|
|
47
33
|
/**
|
|
@@ -49,7 +35,7 @@ function isPositiveInteger(value) {
|
|
|
49
35
|
* @param value - The value to check.
|
|
50
36
|
* @returns `true` if the value is a boolean, otherwise `false`.
|
|
51
37
|
*/
|
|
52
|
-
function isBoolean(value) {
|
|
38
|
+
export function isBoolean(value) {
|
|
53
39
|
return typeof value === 'boolean';
|
|
54
40
|
}
|
|
55
41
|
/**
|
|
@@ -57,7 +43,7 @@ function isBoolean(value) {
|
|
|
57
43
|
* @param value - The value to check.
|
|
58
44
|
* @returns `true` if the value is null, otherwise `false`.
|
|
59
45
|
*/
|
|
60
|
-
function isNull(value) {
|
|
46
|
+
export function isNull(value) {
|
|
61
47
|
return value === null;
|
|
62
48
|
}
|
|
63
49
|
/**
|
|
@@ -65,7 +51,7 @@ function isNull(value) {
|
|
|
65
51
|
* @param value - The value to check.
|
|
66
52
|
* @returns `true` if the value is undefined, otherwise `false`.
|
|
67
53
|
*/
|
|
68
|
-
function isUndefined(value) {
|
|
54
|
+
export function isUndefined(value) {
|
|
69
55
|
return value === undefined;
|
|
70
56
|
}
|
|
71
57
|
/**
|
|
@@ -73,7 +59,7 @@ function isUndefined(value) {
|
|
|
73
59
|
* @param value - The value to check.
|
|
74
60
|
* @returns `true` if the value is a symbol, otherwise `false`.
|
|
75
61
|
*/
|
|
76
|
-
function isSymbol(value) {
|
|
62
|
+
export function isSymbol(value) {
|
|
77
63
|
return typeof value === 'symbol';
|
|
78
64
|
}
|
|
79
65
|
/**
|
|
@@ -81,7 +67,7 @@ function isSymbol(value) {
|
|
|
81
67
|
* @param value - The value to check.
|
|
82
68
|
* @returns `true` if the value is a primitive, otherwise `false`.
|
|
83
69
|
*/
|
|
84
|
-
function isPrimitive(value) {
|
|
70
|
+
export function isPrimitive(value) {
|
|
85
71
|
return (value === null ||
|
|
86
72
|
['string', 'number', 'boolean', 'symbol', 'undefined'].includes(typeof value));
|
|
87
73
|
}
|
|
@@ -90,7 +76,7 @@ function isPrimitive(value) {
|
|
|
90
76
|
* @param value - The value to check.
|
|
91
77
|
* @returns `true` if the value is a non-empty string, otherwise `false`.
|
|
92
78
|
*/
|
|
93
|
-
function isNonEmptyString(value) {
|
|
79
|
+
export function isNonEmptyString(value) {
|
|
94
80
|
return isString(value) && value?.trim().length > 0;
|
|
95
81
|
}
|
|
96
82
|
/**
|
|
@@ -98,7 +84,7 @@ function isNonEmptyString(value) {
|
|
|
98
84
|
* @param value - The value to check.
|
|
99
85
|
* @returns `true` if the value is falsy, otherwise `false`.
|
|
100
86
|
*/
|
|
101
|
-
function isFalsy(value) {
|
|
87
|
+
export function isFalsy(value) {
|
|
102
88
|
return !value;
|
|
103
89
|
}
|
|
104
90
|
/**
|
|
@@ -106,6 +92,6 @@ function isFalsy(value) {
|
|
|
106
92
|
* @param value - The value to check.
|
|
107
93
|
* @returns `true` if the value is truthy (not null or undefined), otherwise `false`.
|
|
108
94
|
*/
|
|
109
|
-
function isTruthy(value) {
|
|
95
|
+
export function isTruthy(value) {
|
|
110
96
|
return Boolean(value);
|
|
111
97
|
}
|
package/dist/guards/specials.js
CHANGED
|
@@ -1,26 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.isEmail = isEmail;
|
|
4
|
-
exports.isEmailArray = isEmailArray;
|
|
5
|
-
exports.isDateString = isDateString;
|
|
6
|
-
exports.isUUID = isUUID;
|
|
7
|
-
exports.isBrowser = isBrowser;
|
|
8
|
-
exports.isNode = isNode;
|
|
9
|
-
exports.isURL = isURL;
|
|
10
|
-
exports.isBase64 = isBase64;
|
|
11
|
-
exports.isPhoneNumber = isPhoneNumber;
|
|
12
|
-
exports.isIPAddress = isIPAddress;
|
|
13
|
-
exports.isEnvironment = isEnvironment;
|
|
14
|
-
exports.isNumericString = isNumericString;
|
|
15
|
-
const non_primitives_1 = require("./non-primitives");
|
|
16
|
-
const primitives_1 = require("./primitives");
|
|
1
|
+
import { isArray } from './non-primitives';
|
|
2
|
+
import { isString } from './primitives';
|
|
17
3
|
/**
|
|
18
4
|
* Type guard to check if a value is a valid email string.
|
|
19
5
|
* @param value - The value to check.
|
|
20
6
|
* @returns `true` if the value is a valid email, otherwise `false`.
|
|
21
7
|
*/
|
|
22
|
-
function isEmail(value) {
|
|
23
|
-
return (
|
|
8
|
+
export function isEmail(value) {
|
|
9
|
+
return (isString(value) &&
|
|
24
10
|
/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(value));
|
|
25
11
|
}
|
|
26
12
|
/**
|
|
@@ -28,38 +14,38 @@ function isEmail(value) {
|
|
|
28
14
|
* @param value - The value to check.
|
|
29
15
|
* @returns `true` if the value is an array of valid email strings, otherwise `false`.
|
|
30
16
|
*/
|
|
31
|
-
function isEmailArray(value) {
|
|
32
|
-
return
|
|
17
|
+
export function isEmailArray(value) {
|
|
18
|
+
return isArray(value) && value.every(isEmail);
|
|
33
19
|
}
|
|
34
20
|
/**
|
|
35
21
|
* Type guard to check if a value is a valid date string.
|
|
36
22
|
* @param value - The value to check.
|
|
37
23
|
* @returns `true` if the value is a valid date string, otherwise `false`.
|
|
38
24
|
*/
|
|
39
|
-
function isDateString(value) {
|
|
40
|
-
return
|
|
25
|
+
export function isDateString(value) {
|
|
26
|
+
return isString(value) && !isNaN(Date.parse(value));
|
|
41
27
|
}
|
|
42
28
|
/**
|
|
43
29
|
* Type guard to check if a value is a valid UUID (v4).
|
|
44
30
|
* @param value - The value to check.
|
|
45
31
|
* @returns `true` if the value is a valid UUID, otherwise `false`.
|
|
46
32
|
*/
|
|
47
|
-
function isUUID(value) {
|
|
48
|
-
return (
|
|
33
|
+
export function isUUID(value) {
|
|
34
|
+
return (isString(value) &&
|
|
49
35
|
/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(value));
|
|
50
36
|
}
|
|
51
37
|
/**
|
|
52
38
|
* Type guard to check if the code is running in a browser environment.
|
|
53
39
|
* @returns `true` if the code is running in a browser, otherwise `false`.
|
|
54
40
|
*/
|
|
55
|
-
function isBrowser() {
|
|
41
|
+
export function isBrowser() {
|
|
56
42
|
return typeof window !== 'undefined' && typeof document !== 'undefined';
|
|
57
43
|
}
|
|
58
44
|
/**
|
|
59
45
|
* Type guard to check if the code is running in a Node.js environment.
|
|
60
46
|
* @returns `true` if the code is running in Node.js, otherwise `false`.
|
|
61
47
|
*/
|
|
62
|
-
function isNode() {
|
|
48
|
+
export function isNode() {
|
|
63
49
|
return (typeof process !== 'undefined' &&
|
|
64
50
|
process.versions != null &&
|
|
65
51
|
process.versions.node != null);
|
|
@@ -69,9 +55,9 @@ function isNode() {
|
|
|
69
55
|
* @param value - The value to check.
|
|
70
56
|
* @returns `true` if the value is a valid URL, otherwise `false`.
|
|
71
57
|
*/
|
|
72
|
-
function isURL(value) {
|
|
58
|
+
export function isURL(value) {
|
|
73
59
|
try {
|
|
74
|
-
new URL(
|
|
60
|
+
new URL(isString(value) ? value : '');
|
|
75
61
|
return true;
|
|
76
62
|
}
|
|
77
63
|
catch {
|
|
@@ -83,8 +69,8 @@ function isURL(value) {
|
|
|
83
69
|
* @param value - The value to check.
|
|
84
70
|
* @returns `true` if the value is a valid Base64 string, otherwise `false`.
|
|
85
71
|
*/
|
|
86
|
-
function isBase64(value) {
|
|
87
|
-
return (
|
|
72
|
+
export function isBase64(value) {
|
|
73
|
+
return (isString(value) &&
|
|
88
74
|
/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(value));
|
|
89
75
|
}
|
|
90
76
|
/**
|
|
@@ -92,16 +78,16 @@ function isBase64(value) {
|
|
|
92
78
|
* @param value - The value to check.
|
|
93
79
|
* @returns `true` if the value is a valid phone number, otherwise `false`.
|
|
94
80
|
*/
|
|
95
|
-
function isPhoneNumber(value) {
|
|
96
|
-
return
|
|
81
|
+
export function isPhoneNumber(value) {
|
|
82
|
+
return isString(value) && /^\+?[1-9]\d{1,14}$/.test(value);
|
|
97
83
|
}
|
|
98
84
|
/**
|
|
99
85
|
* Type guard to check if a value is a valid IP address (IPv4 or IPv6).
|
|
100
86
|
* @param value - The value to check.
|
|
101
87
|
* @returns `true` if the value is a valid IP address, otherwise `false`.
|
|
102
88
|
*/
|
|
103
|
-
function isIPAddress(value) {
|
|
104
|
-
return (
|
|
89
|
+
export function isIPAddress(value) {
|
|
90
|
+
return (isString(value) &&
|
|
105
91
|
/^(?:\d{1,3}\.){3}\d{1,3}$|^([a-f0-9:]+:+)+[a-f0-9]+$/i.test(value));
|
|
106
92
|
}
|
|
107
93
|
/**
|
|
@@ -109,7 +95,7 @@ function isIPAddress(value) {
|
|
|
109
95
|
* @param env - The expected environment (e.g., "production", "development").
|
|
110
96
|
* @returns `true` if the current environment matches, otherwise `false`.
|
|
111
97
|
*/
|
|
112
|
-
function isEnvironment(env) {
|
|
98
|
+
export function isEnvironment(env) {
|
|
113
99
|
return process.env.NODE_ENV === env;
|
|
114
100
|
}
|
|
115
101
|
/**
|
|
@@ -117,6 +103,6 @@ function isEnvironment(env) {
|
|
|
117
103
|
* @param value - The value to check.
|
|
118
104
|
* @returns `true` if the value is a numeric string, otherwise `false`.
|
|
119
105
|
*/
|
|
120
|
-
function isNumericString(value) {
|
|
121
|
-
return
|
|
106
|
+
export function isNumericString(value) {
|
|
107
|
+
return isString(value) && /^\d+(\.\d+)?$/.test(value);
|
|
122
108
|
}
|
package/dist/index.js
CHANGED
|
@@ -1,166 +1,35 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.removeDuplicatesFromArray = exports.createOptionsArray = exports.sortAnArray = exports.shuffleArray = exports.isValidEmptyArray = exports.isInvalidOrEmptyArray = exports.getLastArrayElement = exports.flattenArray = exports.filterArrayOfObjects = exports.Colour = exports.Color = exports.convertRgbToRgba = exports.convertRgbToHsl = exports.convertRgbToHex = exports.convertRgbaToHsla = exports.convertRgbaToHex8 = exports.convertHslToRgb = exports.convertHslToHex = exports.convertHslaToRgba = exports.convertHslaToHex8 = exports.convertHexToRgb = exports.convertHexToHsl = exports.convertHex8ToRgba = exports.convertHex8ToHsla = exports.convertColorCode = exports.generateRandomHSLColor = exports.generateRandomColorInHexRGB = exports.getColorForInitial = exports.getNumbersInRange = exports.isPrime = exports.findPrimeNumbers = exports.numberToWords = exports.isOddNumber = exports.isOdd = exports.isMultiple = exports.isEvenNumber = exports.isEven = exports.getRandomNumber = exports.convertToDecimal = exports.calculateLCM = exports.calculateLCD = exports.calculateHCF = exports.calculateGCD = exports.replaceAllInString = exports.convertStringCase = exports.generateAnagrams = exports.truncateString = exports.trimString = exports.generateRandomID = exports.capitalizeString = void 0;
|
|
4
|
-
exports.isObjectWithKeys = exports.isObjectEmpty = exports.isMap = exports.isJSONObject = exports.isJSON = exports.isFunction = exports.isError = exports.isEmptyObjectGuard = exports.isDate = exports.isBigInt = exports.isArrayOfType = exports.isArray = exports.doesReturnPromise = exports.isUndefined = exports.isTruthy = exports.isSymbol = exports.isString = exports.isPrimitive = exports.isPositiveInteger = exports.isNumber = exports.isNull = exports.isNonEmptyString = exports.isInteger = exports.isFalsy = exports.isBoolean = exports.throttleAction = exports.isDeepEqual = exports.debounceAction = exports.convertArrayToString = exports.convertObjectValues = exports.sanitizeData = exports.mergeObjects = exports.mergeAndFlattenObjects = exports.flattenObjectKeyValue = exports.flattenObjectDotNotation = exports.extractUpdatedFields = exports.extractUpdatedAndNewFields = exports.extractNewFields = exports.isObject = exports.isEmptyObject = exports.generateQueryParams = exports.countObjectFields = exports.cloneObject = exports.isOriginFileObj = exports.isFileUpload = exports.isCustomFileArray = exports.isCustomFile = exports.createControlledFormData = exports.isEmptyFormData = exports.convertIntoFormData = void 0;
|
|
5
|
-
exports.isValidURL = exports.isValidEmail = exports.isUUID = exports.isURL = exports.isPhoneNumber = exports.isNumericString = exports.isNodeEnvironment = exports.isNodeENV = exports.isNode = exports.isIPAddress = exports.isExpectedNodeENV = exports.isEnvironment = exports.isEmailArray = exports.isEmail = exports.isDateString = exports.isBrowser = exports.isBase64 = exports.isValidSet = exports.isValidObject = exports.isValidMap = exports.isValidJSON = exports.isSet = exports.isReturningPromise = exports.isRegularExpression = exports.isRegExp = exports.isPromise = void 0;
|
|
6
1
|
// ! String Utilities
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
Object.defineProperty(exports, "trimString", { enumerable: true, get: function () { return basics_1.trimString; } });
|
|
11
|
-
Object.defineProperty(exports, "truncateString", { enumerable: true, get: function () { return basics_1.truncateString; } });
|
|
12
|
-
var anagram_1 = require("./string/anagram");
|
|
13
|
-
Object.defineProperty(exports, "generateAnagrams", { enumerable: true, get: function () { return anagram_1.generateAnagrams; } });
|
|
14
|
-
var convert_1 = require("./string/convert");
|
|
15
|
-
Object.defineProperty(exports, "convertStringCase", { enumerable: true, get: function () { return convert_1.convertStringCase; } });
|
|
16
|
-
Object.defineProperty(exports, "replaceAllInString", { enumerable: true, get: function () { return convert_1.replaceAllInString; } });
|
|
2
|
+
export { capitalizeString, generateRandomID, trimString, truncateString, } from './string/basics';
|
|
3
|
+
export { generateAnagrams } from './string/anagram';
|
|
4
|
+
export { convertStringCase, replaceAllInString } from './string/convert';
|
|
17
5
|
// ! Number Utilities
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
Object.defineProperty(exports, "calculateLCM", { enumerable: true, get: function () { return basics_2.calculateLCM; } });
|
|
23
|
-
Object.defineProperty(exports, "convertToDecimal", { enumerable: true, get: function () { return basics_2.convertToDecimal; } });
|
|
24
|
-
Object.defineProperty(exports, "getRandomNumber", { enumerable: true, get: function () { return basics_2.getRandomNumber; } });
|
|
25
|
-
Object.defineProperty(exports, "isEven", { enumerable: true, get: function () { return basics_2.isEven; } });
|
|
26
|
-
Object.defineProperty(exports, "isEvenNumber", { enumerable: true, get: function () { return basics_2.isEven; } });
|
|
27
|
-
Object.defineProperty(exports, "isMultiple", { enumerable: true, get: function () { return basics_2.isMultiple; } });
|
|
28
|
-
Object.defineProperty(exports, "isOdd", { enumerable: true, get: function () { return basics_2.isOdd; } });
|
|
29
|
-
Object.defineProperty(exports, "isOddNumber", { enumerable: true, get: function () { return basics_2.isOdd; } });
|
|
30
|
-
var convert_2 = require("./number/convert");
|
|
31
|
-
Object.defineProperty(exports, "numberToWords", { enumerable: true, get: function () { return convert_2.numberToWords; } });
|
|
32
|
-
var prime_1 = require("./number/prime");
|
|
33
|
-
Object.defineProperty(exports, "findPrimeNumbers", { enumerable: true, get: function () { return prime_1.findPrimeNumbers; } });
|
|
34
|
-
Object.defineProperty(exports, "isPrime", { enumerable: true, get: function () { return prime_1.isPrime; } });
|
|
35
|
-
var range_1 = require("./number/range");
|
|
36
|
-
Object.defineProperty(exports, "getNumbersInRange", { enumerable: true, get: function () { return range_1.getNumbersInRange; } });
|
|
6
|
+
export { calculateHCF as calculateGCD, calculateHCF, calculateLCM as calculateLCD, calculateLCM, convertToDecimal, getRandomNumber, isEven, isEven as isEvenNumber, isMultiple, isOdd, isOdd as isOddNumber, } from './number/basics';
|
|
7
|
+
export { numberToWords } from './number/convert';
|
|
8
|
+
export { findPrimeNumbers, isPrime } from './number/prime';
|
|
9
|
+
export { getNumbersInRange } from './number/range';
|
|
37
10
|
// ! Color Utilities
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
Object.defineProperty(exports, "generateRandomHSLColor", { enumerable: true, get: function () { return random_1.generateRandomHSLColor; } });
|
|
43
|
-
var convert_3 = require("./colors/convert");
|
|
44
|
-
Object.defineProperty(exports, "convertColorCode", { enumerable: true, get: function () { return convert_3.convertColorCode; } });
|
|
45
|
-
Object.defineProperty(exports, "convertHex8ToHsla", { enumerable: true, get: function () { return convert_3.convertHex8ToHsla; } });
|
|
46
|
-
Object.defineProperty(exports, "convertHex8ToRgba", { enumerable: true, get: function () { return convert_3.convertHex8ToRgba; } });
|
|
47
|
-
Object.defineProperty(exports, "convertHexToHsl", { enumerable: true, get: function () { return convert_3.convertHexToHsl; } });
|
|
48
|
-
Object.defineProperty(exports, "convertHexToRgb", { enumerable: true, get: function () { return convert_3.convertHexToRgb; } });
|
|
49
|
-
Object.defineProperty(exports, "convertHslaToHex8", { enumerable: true, get: function () { return convert_3.convertHslaToHex8; } });
|
|
50
|
-
Object.defineProperty(exports, "convertHslaToRgba", { enumerable: true, get: function () { return convert_3.convertHslaToRgba; } });
|
|
51
|
-
Object.defineProperty(exports, "convertHslToHex", { enumerable: true, get: function () { return convert_3.convertHslToHex; } });
|
|
52
|
-
Object.defineProperty(exports, "convertHslToRgb", { enumerable: true, get: function () { return convert_3.convertHslToRgb; } });
|
|
53
|
-
Object.defineProperty(exports, "convertRgbaToHex8", { enumerable: true, get: function () { return convert_3.convertRgbaToHex8; } });
|
|
54
|
-
Object.defineProperty(exports, "convertRgbaToHsla", { enumerable: true, get: function () { return convert_3.convertRgbaToHsla; } });
|
|
55
|
-
Object.defineProperty(exports, "convertRgbToHex", { enumerable: true, get: function () { return convert_3.convertRgbToHex; } });
|
|
56
|
-
Object.defineProperty(exports, "convertRgbToHsl", { enumerable: true, get: function () { return convert_3.convertRgbToHsl; } });
|
|
57
|
-
Object.defineProperty(exports, "convertRgbToRgba", { enumerable: true, get: function () { return convert_3.convertRgbToRgba; } });
|
|
58
|
-
var Color_1 = require("./colors/Color");
|
|
59
|
-
Object.defineProperty(exports, "Color", { enumerable: true, get: function () { return Color_1.Color; } });
|
|
60
|
-
Object.defineProperty(exports, "Colour", { enumerable: true, get: function () { return Color_1.Color; } });
|
|
11
|
+
export { getColorForInitial } from './colors/initials';
|
|
12
|
+
export { generateRandomColorInHexRGB, generateRandomHSLColor, } from './colors/random';
|
|
13
|
+
export { convertColorCode, convertHex8ToHsla, convertHex8ToRgba, convertHexToHsl, convertHexToRgb, convertHslaToHex8, convertHslaToRgba, convertHslToHex, convertHslToRgb, convertRgbaToHex8, convertRgbaToHsla, convertRgbToHex, convertRgbToHsl, convertRgbToRgba, } from './colors/convert';
|
|
14
|
+
export { Color, Color as Colour } from './colors/Color';
|
|
61
15
|
// ! Array Utilities
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
Object.defineProperty(exports, "getLastArrayElement", { enumerable: true, get: function () { return basics_3.getLastArrayElement; } });
|
|
66
|
-
Object.defineProperty(exports, "isInvalidOrEmptyArray", { enumerable: true, get: function () { return basics_3.isInvalidOrEmptyArray; } });
|
|
67
|
-
Object.defineProperty(exports, "isValidEmptyArray", { enumerable: true, get: function () { return basics_3.isInvalidOrEmptyArray; } });
|
|
68
|
-
Object.defineProperty(exports, "shuffleArray", { enumerable: true, get: function () { return basics_3.shuffleArray; } });
|
|
69
|
-
var sort_1 = require("./array/sort");
|
|
70
|
-
Object.defineProperty(exports, "sortAnArray", { enumerable: true, get: function () { return sort_1.sortAnArray; } });
|
|
71
|
-
var transform_1 = require("./array/transform");
|
|
72
|
-
Object.defineProperty(exports, "createOptionsArray", { enumerable: true, get: function () { return transform_1.createOptionsArray; } });
|
|
73
|
-
Object.defineProperty(exports, "removeDuplicatesFromArray", { enumerable: true, get: function () { return transform_1.removeDuplicatesFromArray; } });
|
|
16
|
+
export { filterArrayOfObjects, flattenArray, getLastArrayElement, isInvalidOrEmptyArray, isInvalidOrEmptyArray as isValidEmptyArray, shuffleArray, } from './array/basics';
|
|
17
|
+
export { sortAnArray } from './array/sort';
|
|
18
|
+
export { createOptionsArray, removeDuplicatesFromArray, } from './array/transform';
|
|
74
19
|
// ! Form Utilities
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
var transform_2 = require("./form/transform");
|
|
79
|
-
Object.defineProperty(exports, "createControlledFormData", { enumerable: true, get: function () { return transform_2.createControlledFormData; } });
|
|
80
|
-
var guards_1 = require("./form/guards");
|
|
81
|
-
Object.defineProperty(exports, "isCustomFile", { enumerable: true, get: function () { return guards_1.isCustomFile; } });
|
|
82
|
-
Object.defineProperty(exports, "isCustomFileArray", { enumerable: true, get: function () { return guards_1.isCustomFileArray; } });
|
|
83
|
-
Object.defineProperty(exports, "isFileUpload", { enumerable: true, get: function () { return guards_1.isFileUpload; } });
|
|
84
|
-
Object.defineProperty(exports, "isOriginFileObj", { enumerable: true, get: function () { return guards_1.isOriginFileObj; } });
|
|
20
|
+
export { convertIntoFormData, isEmptyFormData } from './form/convert';
|
|
21
|
+
export { createControlledFormData } from './form/transform';
|
|
22
|
+
export { isCustomFile, isCustomFileArray, isFileUpload, isOriginFileObj, } from './form/guards';
|
|
85
23
|
// ! Object Utilities
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
Object.defineProperty(exports, "isEmptyObject", { enumerable: true, get: function () { return basics_4.isEmptyObject; } });
|
|
91
|
-
Object.defineProperty(exports, "isObject", { enumerable: true, get: function () { return basics_4.isObject; } });
|
|
92
|
-
var objectify_1 = require("./object/objectify");
|
|
93
|
-
Object.defineProperty(exports, "extractNewFields", { enumerable: true, get: function () { return objectify_1.extractNewFields; } });
|
|
94
|
-
Object.defineProperty(exports, "extractUpdatedAndNewFields", { enumerable: true, get: function () { return objectify_1.extractUpdatedAndNewFields; } });
|
|
95
|
-
Object.defineProperty(exports, "extractUpdatedFields", { enumerable: true, get: function () { return objectify_1.extractUpdatedFields; } });
|
|
96
|
-
Object.defineProperty(exports, "flattenObjectDotNotation", { enumerable: true, get: function () { return objectify_1.flattenObjectDotNotation; } });
|
|
97
|
-
Object.defineProperty(exports, "flattenObjectKeyValue", { enumerable: true, get: function () { return objectify_1.flattenObjectKeyValue; } });
|
|
98
|
-
Object.defineProperty(exports, "mergeAndFlattenObjects", { enumerable: true, get: function () { return objectify_1.mergeAndFlattenObjects; } });
|
|
99
|
-
Object.defineProperty(exports, "mergeObjects", { enumerable: true, get: function () { return objectify_1.mergeObjects; } });
|
|
100
|
-
var sanitize_1 = require("./object/sanitize");
|
|
101
|
-
Object.defineProperty(exports, "sanitizeData", { enumerable: true, get: function () { return sanitize_1.sanitizeData; } });
|
|
102
|
-
var convert_5 = require("./object/convert");
|
|
103
|
-
Object.defineProperty(exports, "convertObjectValues", { enumerable: true, get: function () { return convert_5.convertObjectValues; } });
|
|
24
|
+
export { cloneObject, countObjectFields, generateQueryParams, isEmptyObject, isObject, } from './object/basics';
|
|
25
|
+
export { extractNewFields, extractUpdatedAndNewFields, extractUpdatedFields, flattenObjectDotNotation, flattenObjectKeyValue, mergeAndFlattenObjects, mergeObjects, } from './object/objectify';
|
|
26
|
+
export { sanitizeData } from './object/sanitize';
|
|
27
|
+
export { convertObjectValues } from './object/convert';
|
|
104
28
|
// ! Other Utilities
|
|
105
|
-
|
|
106
|
-
Object.defineProperty(exports, "convertArrayToString", { enumerable: true, get: function () { return utils_1.convertArrayToString; } });
|
|
107
|
-
Object.defineProperty(exports, "debounceAction", { enumerable: true, get: function () { return utils_1.debounceAction; } });
|
|
108
|
-
Object.defineProperty(exports, "isDeepEqual", { enumerable: true, get: function () { return utils_1.isDeepEqual; } });
|
|
109
|
-
Object.defineProperty(exports, "throttleAction", { enumerable: true, get: function () { return utils_1.throttleAction; } });
|
|
29
|
+
export { convertArrayToString, debounceAction, isDeepEqual, throttleAction, } from './utils';
|
|
110
30
|
// ! Primitive Type Guards
|
|
111
|
-
|
|
112
|
-
Object.defineProperty(exports, "isBoolean", { enumerable: true, get: function () { return primitives_1.isBoolean; } });
|
|
113
|
-
Object.defineProperty(exports, "isFalsy", { enumerable: true, get: function () { return primitives_1.isFalsy; } });
|
|
114
|
-
Object.defineProperty(exports, "isInteger", { enumerable: true, get: function () { return primitives_1.isInteger; } });
|
|
115
|
-
Object.defineProperty(exports, "isNonEmptyString", { enumerable: true, get: function () { return primitives_1.isNonEmptyString; } });
|
|
116
|
-
Object.defineProperty(exports, "isNull", { enumerable: true, get: function () { return primitives_1.isNull; } });
|
|
117
|
-
Object.defineProperty(exports, "isNumber", { enumerable: true, get: function () { return primitives_1.isNumber; } });
|
|
118
|
-
Object.defineProperty(exports, "isPositiveInteger", { enumerable: true, get: function () { return primitives_1.isPositiveInteger; } });
|
|
119
|
-
Object.defineProperty(exports, "isPrimitive", { enumerable: true, get: function () { return primitives_1.isPrimitive; } });
|
|
120
|
-
Object.defineProperty(exports, "isString", { enumerable: true, get: function () { return primitives_1.isString; } });
|
|
121
|
-
Object.defineProperty(exports, "isSymbol", { enumerable: true, get: function () { return primitives_1.isSymbol; } });
|
|
122
|
-
Object.defineProperty(exports, "isTruthy", { enumerable: true, get: function () { return primitives_1.isTruthy; } });
|
|
123
|
-
Object.defineProperty(exports, "isUndefined", { enumerable: true, get: function () { return primitives_1.isUndefined; } });
|
|
31
|
+
export { isBoolean, isFalsy, isInteger, isNonEmptyString, isNull, isNumber, isPositiveInteger, isPrimitive, isString, isSymbol, isTruthy, isUndefined, } from './guards/primitives';
|
|
124
32
|
// ! Non-Primitive Type Guards
|
|
125
|
-
|
|
126
|
-
Object.defineProperty(exports, "doesReturnPromise", { enumerable: true, get: function () { return non_primitives_1.isReturningPromise; } });
|
|
127
|
-
Object.defineProperty(exports, "isArray", { enumerable: true, get: function () { return non_primitives_1.isArray; } });
|
|
128
|
-
Object.defineProperty(exports, "isArrayOfType", { enumerable: true, get: function () { return non_primitives_1.isArrayOfType; } });
|
|
129
|
-
Object.defineProperty(exports, "isBigInt", { enumerable: true, get: function () { return non_primitives_1.isBigInt; } });
|
|
130
|
-
Object.defineProperty(exports, "isDate", { enumerable: true, get: function () { return non_primitives_1.isDate; } });
|
|
131
|
-
Object.defineProperty(exports, "isEmptyObjectGuard", { enumerable: true, get: function () { return non_primitives_1.isEmptyObject; } });
|
|
132
|
-
Object.defineProperty(exports, "isError", { enumerable: true, get: function () { return non_primitives_1.isError; } });
|
|
133
|
-
Object.defineProperty(exports, "isFunction", { enumerable: true, get: function () { return non_primitives_1.isFunction; } });
|
|
134
|
-
Object.defineProperty(exports, "isJSON", { enumerable: true, get: function () { return non_primitives_1.isJSON; } });
|
|
135
|
-
Object.defineProperty(exports, "isJSONObject", { enumerable: true, get: function () { return non_primitives_1.isJSON; } });
|
|
136
|
-
Object.defineProperty(exports, "isMap", { enumerable: true, get: function () { return non_primitives_1.isMap; } });
|
|
137
|
-
Object.defineProperty(exports, "isObjectEmpty", { enumerable: true, get: function () { return non_primitives_1.isEmptyObject; } });
|
|
138
|
-
Object.defineProperty(exports, "isObjectWithKeys", { enumerable: true, get: function () { return non_primitives_1.isObjectWithKeys; } });
|
|
139
|
-
Object.defineProperty(exports, "isPromise", { enumerable: true, get: function () { return non_primitives_1.isPromise; } });
|
|
140
|
-
Object.defineProperty(exports, "isRegExp", { enumerable: true, get: function () { return non_primitives_1.isRegExp; } });
|
|
141
|
-
Object.defineProperty(exports, "isRegularExpression", { enumerable: true, get: function () { return non_primitives_1.isRegExp; } });
|
|
142
|
-
Object.defineProperty(exports, "isReturningPromise", { enumerable: true, get: function () { return non_primitives_1.isReturningPromise; } });
|
|
143
|
-
Object.defineProperty(exports, "isSet", { enumerable: true, get: function () { return non_primitives_1.isSet; } });
|
|
144
|
-
Object.defineProperty(exports, "isValidJSON", { enumerable: true, get: function () { return non_primitives_1.isJSON; } });
|
|
145
|
-
Object.defineProperty(exports, "isValidMap", { enumerable: true, get: function () { return non_primitives_1.isMap; } });
|
|
146
|
-
Object.defineProperty(exports, "isValidObject", { enumerable: true, get: function () { return non_primitives_1.isObject; } });
|
|
147
|
-
Object.defineProperty(exports, "isValidSet", { enumerable: true, get: function () { return non_primitives_1.isSet; } });
|
|
33
|
+
export { isReturningPromise as doesReturnPromise, isArray, isArrayOfType, isBigInt, isDate, isEmptyObject as isEmptyObjectGuard, isError, isFunction, isJSON, isJSON as isJSONObject, isMap, isEmptyObject as isObjectEmpty, isObjectWithKeys, isPromise, isRegExp, isRegExp as isRegularExpression, isReturningPromise, isSet, isJSON as isValidJSON, isMap as isValidMap, isObject as isValidObject, isSet as isValidSet, } from './guards/non-primitives';
|
|
148
34
|
// ! Special Type Guards
|
|
149
|
-
|
|
150
|
-
Object.defineProperty(exports, "isBase64", { enumerable: true, get: function () { return specials_1.isBase64; } });
|
|
151
|
-
Object.defineProperty(exports, "isBrowser", { enumerable: true, get: function () { return specials_1.isBrowser; } });
|
|
152
|
-
Object.defineProperty(exports, "isDateString", { enumerable: true, get: function () { return specials_1.isDateString; } });
|
|
153
|
-
Object.defineProperty(exports, "isEmail", { enumerable: true, get: function () { return specials_1.isEmail; } });
|
|
154
|
-
Object.defineProperty(exports, "isEmailArray", { enumerable: true, get: function () { return specials_1.isEmailArray; } });
|
|
155
|
-
Object.defineProperty(exports, "isEnvironment", { enumerable: true, get: function () { return specials_1.isEnvironment; } });
|
|
156
|
-
Object.defineProperty(exports, "isExpectedNodeENV", { enumerable: true, get: function () { return specials_1.isEnvironment; } });
|
|
157
|
-
Object.defineProperty(exports, "isIPAddress", { enumerable: true, get: function () { return specials_1.isIPAddress; } });
|
|
158
|
-
Object.defineProperty(exports, "isNode", { enumerable: true, get: function () { return specials_1.isNode; } });
|
|
159
|
-
Object.defineProperty(exports, "isNodeENV", { enumerable: true, get: function () { return specials_1.isEnvironment; } });
|
|
160
|
-
Object.defineProperty(exports, "isNodeEnvironment", { enumerable: true, get: function () { return specials_1.isEnvironment; } });
|
|
161
|
-
Object.defineProperty(exports, "isNumericString", { enumerable: true, get: function () { return specials_1.isNumericString; } });
|
|
162
|
-
Object.defineProperty(exports, "isPhoneNumber", { enumerable: true, get: function () { return specials_1.isPhoneNumber; } });
|
|
163
|
-
Object.defineProperty(exports, "isURL", { enumerable: true, get: function () { return specials_1.isURL; } });
|
|
164
|
-
Object.defineProperty(exports, "isUUID", { enumerable: true, get: function () { return specials_1.isUUID; } });
|
|
165
|
-
Object.defineProperty(exports, "isValidEmail", { enumerable: true, get: function () { return specials_1.isEmail; } });
|
|
166
|
-
Object.defineProperty(exports, "isValidURL", { enumerable: true, get: function () { return specials_1.isURL; } });
|
|
35
|
+
export { isBase64, isBrowser, isDateString, isEmail, isEmailArray, isEnvironment, isEnvironment as isExpectedNodeENV, isIPAddress, isNode, isEnvironment as isNodeENV, isEnvironment as isNodeEnvironment, isNumericString, isPhoneNumber, isURL, isUUID, isEmail as isValidEmail, isURL as isValidURL, } from './guards/specials';
|
package/dist/number/basics.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isMultiple = exports.isOdd = exports.isEven = exports.calculateLCM = exports.calculateHCF = exports.convertToDecimal = exports.getRandomNumber = void 0;
|
|
4
|
-
const helpers_1 = require("./helpers");
|
|
1
|
+
import { _find2NumbersHCF, _find2NumbersLCM } from './helpers';
|
|
5
2
|
/**
|
|
6
3
|
* * Utility to generate a random number between a given range.
|
|
7
4
|
* * If no options are provided, it will generate a random number between `0` and `100` (inclusive).
|
|
@@ -10,12 +7,12 @@ const helpers_1 = require("./helpers");
|
|
|
10
7
|
* @param options - Options for configuring random number generator.
|
|
11
8
|
* @returns Random number.
|
|
12
9
|
*/
|
|
13
|
-
const getRandomNumber = (options) => {
|
|
10
|
+
export const getRandomNumber = (options) => {
|
|
14
11
|
const { min = 0, max = 100, includeMin = true, includeMax = true, } = options || {};
|
|
15
12
|
let minimum = min, maximum = max;
|
|
16
13
|
if (min > max) {
|
|
17
14
|
[minimum, maximum] = [max, min];
|
|
18
|
-
return
|
|
15
|
+
return getRandomNumber({
|
|
19
16
|
min: minimum,
|
|
20
17
|
max: maximum,
|
|
21
18
|
includeMin,
|
|
@@ -43,7 +40,6 @@ const getRandomNumber = (options) => {
|
|
|
43
40
|
}
|
|
44
41
|
return 0;
|
|
45
42
|
};
|
|
46
|
-
exports.getRandomNumber = getRandomNumber;
|
|
47
43
|
/**
|
|
48
44
|
* * Utility to round a number to given decimal places.
|
|
49
45
|
*
|
|
@@ -51,7 +47,7 @@ exports.getRandomNumber = getRandomNumber;
|
|
|
51
47
|
* @param options - Options for rounding behavior, including decimal places and return type.
|
|
52
48
|
* @returns Converted number as `number` (default) or `string` (if `isString` is `true`).
|
|
53
49
|
*/
|
|
54
|
-
const convertToDecimal = (input, options) => {
|
|
50
|
+
export const convertToDecimal = (input, options) => {
|
|
55
51
|
const { decimalPlaces = 2, isString = false } = options || {};
|
|
56
52
|
let number;
|
|
57
53
|
if (typeof input === 'number') {
|
|
@@ -64,55 +60,50 @@ const convertToDecimal = (input, options) => {
|
|
|
64
60
|
number.toFixed(decimalPlaces)
|
|
65
61
|
: Number(number.toFixed(decimalPlaces));
|
|
66
62
|
};
|
|
67
|
-
exports.convertToDecimal = convertToDecimal;
|
|
68
63
|
/**
|
|
69
64
|
* * Calculates the HCF/GCD of multiple numbers.
|
|
70
65
|
*
|
|
71
66
|
* @param numbers - List of numbers to find the HCF/GCD for.
|
|
72
67
|
* @returns The HCF/GCD of all the provided numbers.
|
|
73
68
|
*/
|
|
74
|
-
const calculateHCF = (...numbers) => {
|
|
69
|
+
export const calculateHCF = (...numbers) => {
|
|
75
70
|
let hcf = numbers[0];
|
|
76
71
|
for (let i = 1; i < numbers.length; i++) {
|
|
77
|
-
hcf =
|
|
72
|
+
hcf = _find2NumbersHCF(hcf, numbers[i]);
|
|
78
73
|
}
|
|
79
74
|
return hcf;
|
|
80
75
|
};
|
|
81
|
-
exports.calculateHCF = calculateHCF;
|
|
82
76
|
/**
|
|
83
77
|
* * Calculates the LCM/LCD of multiple numbers.
|
|
84
78
|
*
|
|
85
79
|
* @param numbers - List of numbers to find the LCM/LCD for.
|
|
86
80
|
* @returns The LCM/LCD of all the provided numbers.
|
|
87
81
|
*/
|
|
88
|
-
const calculateLCM = (...numbers) => {
|
|
82
|
+
export const calculateLCM = (...numbers) => {
|
|
89
83
|
let lcm = numbers[0];
|
|
90
84
|
for (let i = 1; i < numbers.length; i++) {
|
|
91
|
-
lcm =
|
|
85
|
+
lcm = _find2NumbersLCM(lcm, numbers[i]);
|
|
92
86
|
}
|
|
93
87
|
return lcm;
|
|
94
88
|
};
|
|
95
|
-
exports.calculateLCM = calculateLCM;
|
|
96
89
|
/**
|
|
97
90
|
* * Check if a number is even or not.
|
|
98
91
|
*
|
|
99
92
|
* @param input The number to check.
|
|
100
93
|
* @returns Boolean: `true` if even and `false` if not even.
|
|
101
94
|
*/
|
|
102
|
-
const isEven = (input) => {
|
|
95
|
+
export const isEven = (input) => {
|
|
103
96
|
return input % 2 === 0;
|
|
104
97
|
};
|
|
105
|
-
exports.isEven = isEven;
|
|
106
98
|
/**
|
|
107
99
|
* * Checks if a number is odd or not.
|
|
108
100
|
*
|
|
109
101
|
* @param input The number to check.
|
|
110
102
|
* @returns Boolean: `true` if odd and `false` if not odd.
|
|
111
103
|
*/
|
|
112
|
-
const isOdd = (input) => {
|
|
104
|
+
export const isOdd = (input) => {
|
|
113
105
|
return input % 2 !== 0;
|
|
114
106
|
};
|
|
115
|
-
exports.isOdd = isOdd;
|
|
116
107
|
/**
|
|
117
108
|
* * Checks if a number is a multiple of another number.
|
|
118
109
|
*
|
|
@@ -120,7 +111,6 @@ exports.isOdd = isOdd;
|
|
|
120
111
|
* @param multipleOf - The number to check against.
|
|
121
112
|
* @returns `true` if `input` is a multiple of `multipleOf`, otherwise `false`.
|
|
122
113
|
*/
|
|
123
|
-
const isMultiple = (input, multipleOf) => {
|
|
114
|
+
export const isMultiple = (input, multipleOf) => {
|
|
124
115
|
return input % multipleOf === 0;
|
|
125
116
|
};
|
|
126
|
-
exports.isMultiple = isMultiple;
|
package/dist/number/constants.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.thousands = exports.tens = exports.teens = exports.ones = void 0;
|
|
4
|
-
exports.ones = [
|
|
1
|
+
export const ones = [
|
|
5
2
|
'',
|
|
6
3
|
'one',
|
|
7
4
|
'two',
|
|
@@ -13,7 +10,7 @@ exports.ones = [
|
|
|
13
10
|
'eight',
|
|
14
11
|
'nine',
|
|
15
12
|
];
|
|
16
|
-
|
|
13
|
+
export const teens = [
|
|
17
14
|
'',
|
|
18
15
|
'eleven',
|
|
19
16
|
'twelve',
|
|
@@ -25,7 +22,7 @@ exports.teens = [
|
|
|
25
22
|
'eighteen',
|
|
26
23
|
'nineteen',
|
|
27
24
|
];
|
|
28
|
-
|
|
25
|
+
export const tens = [
|
|
29
26
|
'',
|
|
30
27
|
'ten',
|
|
31
28
|
'twenty',
|
|
@@ -37,7 +34,7 @@ exports.tens = [
|
|
|
37
34
|
'eighty',
|
|
38
35
|
'ninety',
|
|
39
36
|
];
|
|
40
|
-
|
|
37
|
+
export const thousands = [
|
|
41
38
|
'',
|
|
42
39
|
'thousand',
|
|
43
40
|
'million',
|
package/dist/number/convert.js
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.numberToWords = numberToWords;
|
|
4
|
-
const constants_1 = require("./constants");
|
|
5
|
-
const helpers_1 = require("./helpers");
|
|
1
|
+
import { thousands } from './constants';
|
|
2
|
+
import { _convertLessThanThousand } from './helpers';
|
|
6
3
|
/**
|
|
7
4
|
* * Converts a number to words
|
|
8
5
|
* @param number - The number to convert into words.
|
|
9
6
|
* @returns The number converted in words.
|
|
10
7
|
*/
|
|
11
|
-
function numberToWords(number) {
|
|
8
|
+
export function numberToWords(number) {
|
|
12
9
|
const isNegative = number < 0;
|
|
13
10
|
if (number === 0)
|
|
14
11
|
return 'zero';
|
|
@@ -18,8 +15,8 @@ function numberToWords(number) {
|
|
|
18
15
|
while (number > 0) {
|
|
19
16
|
if (number % 1000 !== 0) {
|
|
20
17
|
const isLastGroup = i === 0 && number % 100 < 100;
|
|
21
|
-
const prefix =
|
|
22
|
-
result = `${prefix} ${
|
|
18
|
+
const prefix = _convertLessThanThousand(number % 1000, isLastGroup);
|
|
19
|
+
result = `${prefix} ${thousands[i]} ${result}`;
|
|
23
20
|
}
|
|
24
21
|
number = Math.floor(number / 1000);
|
|
25
22
|
i++;
|