nhb-toolbox 2.8.1 → 2.8.3
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.d.ts +2 -2
- package/dist/colors/initials.d.ts.map +1 -1
- 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.d.ts +10 -10
- package/dist/guards/non-primitives.js +27 -44
- package/dist/guards/primitives.d.ts +12 -12
- package/dist/guards/primitives.js +24 -38
- package/dist/guards/specials.d.ts +12 -12
- package/dist/guards/specials.js +35 -49
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- 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,27 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isArray = isArray;
|
|
4
|
-
exports.isObject = isObject;
|
|
5
|
-
exports.isFunction = isFunction;
|
|
6
|
-
exports.isDate = isDate;
|
|
7
|
-
exports.isObjectWithKeys = isObjectWithKeys;
|
|
8
|
-
exports.isEmptyObject = isEmptyObject;
|
|
9
|
-
exports.isArrayOfType = isArrayOfType;
|
|
10
|
-
exports.isPromise = isPromise;
|
|
11
|
-
exports.isSet = isSet;
|
|
12
|
-
exports.isMap = isMap;
|
|
13
|
-
exports.isRegExp = isRegExp;
|
|
14
|
-
exports.isError = isError;
|
|
15
|
-
exports.isBigInt = isBigInt;
|
|
16
|
-
exports.isJSON = isJSON;
|
|
17
|
-
exports.isReturningPromise = isReturningPromise;
|
|
18
|
-
const primitives_1 = require("./primitives");
|
|
1
|
+
import { isString } from './primitives';
|
|
19
2
|
/**
|
|
20
3
|
* Type guard to check if a value is an array.
|
|
21
4
|
* @param value - The value to check.
|
|
22
5
|
* @returns `true` if the value is an array, otherwise `false`.
|
|
23
6
|
*/
|
|
24
|
-
function isArray(value) {
|
|
7
|
+
export function isArray(value) {
|
|
25
8
|
return Array.isArray(value);
|
|
26
9
|
}
|
|
27
10
|
/**
|
|
@@ -29,7 +12,7 @@ function isArray(value) {
|
|
|
29
12
|
* @param value - The value to check.
|
|
30
13
|
* @returns `true` if the value is an object, otherwise `false`.
|
|
31
14
|
*/
|
|
32
|
-
function isObject(value) {
|
|
15
|
+
export function isObject(value) {
|
|
33
16
|
return value !== null && typeof value === 'object' && !isArray(value);
|
|
34
17
|
}
|
|
35
18
|
/**
|
|
@@ -37,7 +20,7 @@ function isObject(value) {
|
|
|
37
20
|
* @param value - The value to check.
|
|
38
21
|
* @returns `true` if the value is a function, otherwise `false`.
|
|
39
22
|
*/
|
|
40
|
-
function isFunction(value) {
|
|
23
|
+
export function isFunction(value) {
|
|
41
24
|
return typeof value === 'function';
|
|
42
25
|
}
|
|
43
26
|
/**
|
|
@@ -45,7 +28,7 @@ function isFunction(value) {
|
|
|
45
28
|
* @param value - The value to check.
|
|
46
29
|
* @returns `true` if the value is a Date object, otherwise `false`.
|
|
47
30
|
*/
|
|
48
|
-
function isDate(value) {
|
|
31
|
+
export function isDate(value) {
|
|
49
32
|
return value instanceof Date;
|
|
50
33
|
}
|
|
51
34
|
/**
|
|
@@ -54,81 +37,81 @@ function isDate(value) {
|
|
|
54
37
|
* @param keys - The set of keys the object should contain.
|
|
55
38
|
* @returns `true` if the value is an object with the specified keys, otherwise `false`.
|
|
56
39
|
*/
|
|
57
|
-
function isObjectWithKeys(value, keys) {
|
|
40
|
+
export function isObjectWithKeys(value, keys) {
|
|
58
41
|
return isObject(value) && keys.every((key) => key in value);
|
|
59
42
|
}
|
|
60
43
|
/**
|
|
61
|
-
* Type guard to check if a value is an empty object.
|
|
44
|
+
* * Type guard to check if a value is an empty object.
|
|
62
45
|
* @param value - The value to check.
|
|
63
46
|
* @returns `true` if the value is an empty object, otherwise `false`.
|
|
64
47
|
*/
|
|
65
|
-
function isEmptyObject(value) {
|
|
48
|
+
export function isEmptyObject(value) {
|
|
66
49
|
return isObject(value) && Object.keys(value).length === 0;
|
|
67
50
|
}
|
|
68
51
|
/**
|
|
69
|
-
* Type guard to check if a value is an array of a specific type.
|
|
52
|
+
* * Type guard to check if a value is an array of a specific type.
|
|
70
53
|
* @param value - The value to check.
|
|
71
54
|
* @param typeCheck - The type guard function to check each item of the array.
|
|
72
55
|
* @returns `true` if the value is an array of the specified type, otherwise `false`.
|
|
73
56
|
*/
|
|
74
|
-
function isArrayOfType(value, typeCheck) {
|
|
57
|
+
export function isArrayOfType(value, typeCheck) {
|
|
75
58
|
return isArray(value) && value.every(typeCheck);
|
|
76
59
|
}
|
|
77
60
|
/**
|
|
78
|
-
* Type guard to check if a value is a Promise.
|
|
61
|
+
* * Type guard to check if a value is a Promise.
|
|
79
62
|
* @param value - The value to check.
|
|
80
63
|
* @returns `true` if the value is a Promise, otherwise `false`.
|
|
81
64
|
*/
|
|
82
|
-
function isPromise(value) {
|
|
65
|
+
export function isPromise(value) {
|
|
83
66
|
return isObject(value) && isFunction(value.then);
|
|
84
67
|
}
|
|
85
68
|
/**
|
|
86
|
-
* Type guard to check if a value is a Set.
|
|
69
|
+
* * Type guard to check if a value is a Set.
|
|
87
70
|
* @param value - The value to check.
|
|
88
71
|
* @returns `true` if the value is a Set, otherwise `false`.
|
|
89
72
|
*/
|
|
90
|
-
function isSet(value) {
|
|
73
|
+
export function isSet(value) {
|
|
91
74
|
return value instanceof Set;
|
|
92
75
|
}
|
|
93
76
|
/**
|
|
94
|
-
* Type guard to check if a value is a Map.
|
|
77
|
+
* * Type guard to check if a value is a Map.
|
|
95
78
|
* @param value - The value to check.
|
|
96
79
|
* @returns `true` if the value is a Map, otherwise `false`.
|
|
97
80
|
*/
|
|
98
|
-
function isMap(value) {
|
|
81
|
+
export function isMap(value) {
|
|
99
82
|
return value instanceof Map;
|
|
100
83
|
}
|
|
101
84
|
/**
|
|
102
|
-
* Type guard to check if a value is a RegExp.
|
|
85
|
+
* * Type guard to check if a value is a RegExp.
|
|
103
86
|
* @param value - The value to check.
|
|
104
87
|
* @returns `true` if the value is a RegExp, otherwise `false`.
|
|
105
88
|
*/
|
|
106
|
-
function isRegExp(value) {
|
|
89
|
+
export function isRegExp(value) {
|
|
107
90
|
return value instanceof RegExp;
|
|
108
91
|
}
|
|
109
92
|
/**
|
|
110
|
-
* Type guard to check if a value is an Error object.
|
|
93
|
+
* * Type guard to check if a value is an Error object.
|
|
111
94
|
* @param value - The value to check.
|
|
112
95
|
* @returns `true` if the value is an Error object, otherwise `false`.
|
|
113
96
|
*/
|
|
114
|
-
function isError(value) {
|
|
97
|
+
export function isError(value) {
|
|
115
98
|
return value instanceof Error;
|
|
116
99
|
}
|
|
117
100
|
/**
|
|
118
|
-
* Type guard to check if a value is a BigInt.
|
|
101
|
+
* * Type guard to check if a value is a BigInt.
|
|
119
102
|
* @param value - The value to check.
|
|
120
103
|
* @returns `true` if the value is a BigInt, otherwise `false`.
|
|
121
104
|
*/
|
|
122
|
-
function isBigInt(value) {
|
|
105
|
+
export function isBigInt(value) {
|
|
123
106
|
return typeof value === 'bigint';
|
|
124
107
|
}
|
|
125
108
|
/**
|
|
126
|
-
* Type guard to check if a string is valid JSON.
|
|
109
|
+
* * Type guard to check if a string is valid JSON.
|
|
127
110
|
* @param value - The value to check.
|
|
128
111
|
* @returns `true` if the value is valid JSON, otherwise `false`.
|
|
129
112
|
*/
|
|
130
|
-
function isJSON(value) {
|
|
131
|
-
if (!
|
|
113
|
+
export function isJSON(value) {
|
|
114
|
+
if (!isString(value))
|
|
132
115
|
return false;
|
|
133
116
|
try {
|
|
134
117
|
JSON.parse(value);
|
|
@@ -139,10 +122,10 @@ function isJSON(value) {
|
|
|
139
122
|
}
|
|
140
123
|
}
|
|
141
124
|
/**
|
|
142
|
-
* Type guard to check if a function returns a Promise.
|
|
125
|
+
* * Type guard to check if a function returns a Promise.
|
|
143
126
|
* @param fn - The function to check.
|
|
144
127
|
* @returns `true` if the function returns a Promise, otherwise `false`.
|
|
145
128
|
*/
|
|
146
|
-
function isReturningPromise(fn) {
|
|
129
|
+
export function isReturningPromise(fn) {
|
|
147
130
|
return isFunction(fn) && fn.constructor.name === 'AsyncFunction';
|
|
148
131
|
}
|
|
@@ -1,72 +1,72 @@
|
|
|
1
1
|
import type { FalsyPrimitive } from '../types';
|
|
2
2
|
/**
|
|
3
|
-
* Type guard to check if a value is a number.
|
|
3
|
+
* * Type guard to check if a value is a number.
|
|
4
4
|
* @param value - The value to check.
|
|
5
5
|
* @returns `true` if the value is a number, otherwise `false`.
|
|
6
6
|
*/
|
|
7
7
|
export declare function isNumber(value: unknown): value is number;
|
|
8
8
|
/**
|
|
9
|
-
* Type guard to check if a value is a string.
|
|
9
|
+
* * Type guard to check if a value is a string.
|
|
10
10
|
* @param value - The value to check.
|
|
11
11
|
* @returns `true` if the value is a string, otherwise `false`.
|
|
12
12
|
*/
|
|
13
13
|
export declare function isString(value: unknown): value is string;
|
|
14
14
|
/**
|
|
15
|
-
* Type guard to check if a value is an integer.
|
|
15
|
+
* * Type guard to check if a value is an integer.
|
|
16
16
|
* @param value - The value to check.
|
|
17
17
|
* @returns `true` if the value is an integer, otherwise `false`.
|
|
18
18
|
*/
|
|
19
19
|
export declare function isInteger(value: unknown): value is number;
|
|
20
20
|
/**
|
|
21
|
-
* Type guard to check if a value is a positive integer.
|
|
21
|
+
* * Type guard to check if a value is a positive integer.
|
|
22
22
|
* @param value - The value to check.
|
|
23
23
|
* @returns `true` if the value is a positive integer, otherwise `false`.
|
|
24
24
|
*/
|
|
25
25
|
export declare function isPositiveInteger(value: unknown): value is number;
|
|
26
26
|
/**
|
|
27
|
-
* Type guard to check if a value is a boolean.
|
|
27
|
+
* * Type guard to check if a value is a boolean.
|
|
28
28
|
* @param value - The value to check.
|
|
29
29
|
* @returns `true` if the value is a boolean, otherwise `false`.
|
|
30
30
|
*/
|
|
31
31
|
export declare function isBoolean(value: unknown): value is boolean;
|
|
32
32
|
/**
|
|
33
|
-
* Type guard to check if a value is null.
|
|
33
|
+
* * Type guard to check if a value is null.
|
|
34
34
|
* @param value - The value to check.
|
|
35
35
|
* @returns `true` if the value is null, otherwise `false`.
|
|
36
36
|
*/
|
|
37
37
|
export declare function isNull(value: unknown): value is null;
|
|
38
38
|
/**
|
|
39
|
-
* Type guard to check if a value is undefined.
|
|
39
|
+
* * Type guard to check if a value is undefined.
|
|
40
40
|
* @param value - The value to check.
|
|
41
41
|
* @returns `true` if the value is undefined, otherwise `false`.
|
|
42
42
|
*/
|
|
43
43
|
export declare function isUndefined(value: unknown): value is undefined;
|
|
44
44
|
/**
|
|
45
|
-
* Type guard to check if a value is a symbol.
|
|
45
|
+
* * Type guard to check if a value is a symbol.
|
|
46
46
|
* @param value - The value to check.
|
|
47
47
|
* @returns `true` if the value is a symbol, otherwise `false`.
|
|
48
48
|
*/
|
|
49
49
|
export declare function isSymbol(value: unknown): value is symbol;
|
|
50
50
|
/**
|
|
51
|
-
* Type guard to check if a value is a primitive.
|
|
51
|
+
* * Type guard to check if a value is a primitive.
|
|
52
52
|
* @param value - The value to check.
|
|
53
53
|
* @returns `true` if the value is a primitive, otherwise `false`.
|
|
54
54
|
*/
|
|
55
55
|
export declare function isPrimitive(value: unknown): value is string | number | boolean | symbol | null | undefined;
|
|
56
56
|
/**
|
|
57
|
-
* Type guard to check if a value is a non-empty string.
|
|
57
|
+
* * Type guard to check if a value is a non-empty string.
|
|
58
58
|
* @param value - The value to check.
|
|
59
59
|
* @returns `true` if the value is a non-empty string, otherwise `false`.
|
|
60
60
|
*/
|
|
61
61
|
export declare function isNonEmptyString(value: unknown): value is string;
|
|
62
62
|
/**
|
|
63
|
-
* Type guard to check if a value is falsy.
|
|
63
|
+
* * Type guard to check if a value is falsy.
|
|
64
64
|
* @param value - The value to check.
|
|
65
65
|
* @returns `true` if the value is falsy, otherwise `false`.
|
|
66
66
|
*/
|
|
67
67
|
export declare function isFalsy(value: unknown): value is FalsyPrimitive;
|
|
68
68
|
/**
|
|
69
|
-
* Type guard to check if a value is truthy.
|
|
69
|
+
* * Type guard to check if a value is truthy.
|
|
70
70
|
* @param value - The value to check.
|
|
71
71
|
* @returns `true` if the value is truthy (not null or undefined), otherwise `false`.
|
|
72
72
|
*/
|
|
@@ -1,111 +1,97 @@
|
|
|
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
|
-
* Type guard to check if a value is a number.
|
|
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
|
/**
|
|
24
|
-
* Type guard to check if a value is a string.
|
|
10
|
+
* * Type guard to check if a value is a string.
|
|
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
|
/**
|
|
32
|
-
* Type guard to check if a value is an integer.
|
|
18
|
+
* * Type guard to check if a value is an integer.
|
|
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
|
/**
|
|
40
|
-
* Type guard to check if a value is a positive integer.
|
|
26
|
+
* * Type guard to check if a value is a positive integer.
|
|
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
|
/**
|
|
48
|
-
* Type guard to check if a value is a boolean.
|
|
34
|
+
* * Type guard to check if a value is a boolean.
|
|
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
|
/**
|
|
56
|
-
* Type guard to check if a value is null.
|
|
42
|
+
* * Type guard to check if a value is null.
|
|
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
|
/**
|
|
64
|
-
* Type guard to check if a value is undefined.
|
|
50
|
+
* * Type guard to check if a value is undefined.
|
|
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
|
/**
|
|
72
|
-
* Type guard to check if a value is a symbol.
|
|
58
|
+
* * Type guard to check if a value is a symbol.
|
|
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
|
/**
|
|
80
|
-
* Type guard to check if a value is a primitive.
|
|
66
|
+
* * Type guard to check if a value is a primitive.
|
|
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
|
}
|
|
88
74
|
/**
|
|
89
|
-
* Type guard to check if a value is a non-empty string.
|
|
75
|
+
* * Type guard to check if a value is a non-empty string.
|
|
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
|
/**
|
|
97
|
-
* Type guard to check if a value is falsy.
|
|
83
|
+
* * Type guard to check if a value is falsy.
|
|
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
|
/**
|
|
105
|
-
* Type guard to check if a value is truthy.
|
|
91
|
+
* * Type guard to check if a value is truthy.
|
|
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
|
}
|
|
@@ -1,69 +1,69 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Type guard to check if a value is a valid email string.
|
|
2
|
+
* * Type guard to check if a value is a valid email string.
|
|
3
3
|
* @param value - The value to check.
|
|
4
4
|
* @returns `true` if the value is a valid email, otherwise `false`.
|
|
5
5
|
*/
|
|
6
6
|
export declare function isEmail(value: unknown): value is string;
|
|
7
7
|
/**
|
|
8
|
-
* Type guard to check if a value is an array of valid email strings.
|
|
8
|
+
* * Type guard to check if a value is an array of valid email strings.
|
|
9
9
|
* @param value - The value to check.
|
|
10
10
|
* @returns `true` if the value is an array of valid email strings, otherwise `false`.
|
|
11
11
|
*/
|
|
12
12
|
export declare function isEmailArray(value: unknown): value is string[];
|
|
13
13
|
/**
|
|
14
|
-
* Type guard to check if a value is a valid date string.
|
|
14
|
+
* * Type guard to check if a value is a valid date string.
|
|
15
15
|
* @param value - The value to check.
|
|
16
16
|
* @returns `true` if the value is a valid date string, otherwise `false`.
|
|
17
17
|
*/
|
|
18
18
|
export declare function isDateString(value: unknown): value is string;
|
|
19
19
|
/**
|
|
20
|
-
* Type guard to check if a value is a valid UUID (v4).
|
|
20
|
+
* * Type guard to check if a value is a valid UUID (v4).
|
|
21
21
|
* @param value - The value to check.
|
|
22
22
|
* @returns `true` if the value is a valid UUID, otherwise `false`.
|
|
23
23
|
*/
|
|
24
24
|
export declare function isUUID(value: unknown): value is string;
|
|
25
25
|
/**
|
|
26
|
-
* Type guard to check if the code is running in a browser environment.
|
|
26
|
+
* * Type guard to check if the code is running in a browser environment.
|
|
27
27
|
* @returns `true` if the code is running in a browser, otherwise `false`.
|
|
28
28
|
*/
|
|
29
29
|
export declare function isBrowser(): boolean;
|
|
30
30
|
/**
|
|
31
|
-
* Type guard to check if the code is running in a Node.js environment.
|
|
31
|
+
* * Type guard to check if the code is running in a Node.js environment.
|
|
32
32
|
* @returns `true` if the code is running in Node.js, otherwise `false`.
|
|
33
33
|
*/
|
|
34
34
|
export declare function isNode(): boolean;
|
|
35
35
|
/**
|
|
36
|
-
* Type guard to check if a value is a valid URL.
|
|
36
|
+
* * Type guard to check if a value is a valid URL.
|
|
37
37
|
* @param value - The value to check.
|
|
38
38
|
* @returns `true` if the value is a valid URL, otherwise `false`.
|
|
39
39
|
*/
|
|
40
40
|
export declare function isURL(value: unknown): value is string;
|
|
41
41
|
/**
|
|
42
|
-
* Type guard to check if a value is a valid Base64 encoded string.
|
|
42
|
+
* * Type guard to check if a value is a valid Base64 encoded string.
|
|
43
43
|
* @param value - The value to check.
|
|
44
44
|
* @returns `true` if the value is a valid Base64 string, otherwise `false`.
|
|
45
45
|
*/
|
|
46
46
|
export declare function isBase64(value: unknown): value is string;
|
|
47
47
|
/**
|
|
48
|
-
* Type guard to check if a value is a valid phone number.
|
|
48
|
+
* * Type guard to check if a value is a valid phone number.
|
|
49
49
|
* @param value - The value to check.
|
|
50
50
|
* @returns `true` if the value is a valid phone number, otherwise `false`.
|
|
51
51
|
*/
|
|
52
52
|
export declare function isPhoneNumber(value: unknown): value is string;
|
|
53
53
|
/**
|
|
54
|
-
* Type guard to check if a value is a valid IP address (IPv4 or IPv6).
|
|
54
|
+
* * Type guard to check if a value is a valid IP address (IPv4 or IPv6).
|
|
55
55
|
* @param value - The value to check.
|
|
56
56
|
* @returns `true` if the value is a valid IP address, otherwise `false`.
|
|
57
57
|
*/
|
|
58
58
|
export declare function isIPAddress(value: unknown): value is string;
|
|
59
59
|
/**
|
|
60
|
-
* Type guard to check if the current environment matches a given string.
|
|
60
|
+
* * Type guard to check if the current environment matches a given string.
|
|
61
61
|
* @param env - The expected environment (e.g., "production", "development").
|
|
62
62
|
* @returns `true` if the current environment matches, otherwise `false`.
|
|
63
63
|
*/
|
|
64
64
|
export declare function isEnvironment(env: string): boolean;
|
|
65
65
|
/**
|
|
66
|
-
* Type guard to check if a value is a numeric string.
|
|
66
|
+
* * Type guard to check if a value is a numeric string.
|
|
67
67
|
* @param value - The value to check.
|
|
68
68
|
* @returns `true` if the value is a numeric string, otherwise `false`.
|
|
69
69
|
*/
|
package/dist/guards/specials.js
CHANGED
|
@@ -1,77 +1,63 @@
|
|
|
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
|
-
* Type guard to check if a value is a valid email string.
|
|
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
|
/**
|
|
27
|
-
* Type guard to check if a value is an array of valid email strings.
|
|
13
|
+
* * Type guard to check if a value is an array of valid email strings.
|
|
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
|
-
* Type guard to check if a value is a valid date string.
|
|
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
|
-
* Type guard to check if a value is a valid UUID (v4).
|
|
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
|
-
* Type guard to check if the code is running in a browser environment.
|
|
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
|
-
* Type guard to check if the code is running in a Node.js environment.
|
|
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);
|
|
66
52
|
}
|
|
67
53
|
/**
|
|
68
|
-
* Type guard to check if a value is a valid URL.
|
|
54
|
+
* * Type guard to check if a value is a valid URL.
|
|
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 {
|
|
@@ -79,44 +65,44 @@ function isURL(value) {
|
|
|
79
65
|
}
|
|
80
66
|
}
|
|
81
67
|
/**
|
|
82
|
-
* Type guard to check if a value is a valid Base64 encoded string.
|
|
68
|
+
* * Type guard to check if a value is a valid Base64 encoded string.
|
|
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
|
/**
|
|
91
|
-
* Type guard to check if a value is a valid phone number.
|
|
77
|
+
* * Type guard to check if a value is a valid phone number.
|
|
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
|
-
* Type guard to check if a value is a valid IP address (IPv4 or IPv6).
|
|
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
|
/**
|
|
108
|
-
* Type guard to check if the current environment matches a given string.
|
|
94
|
+
* * Type guard to check if the current environment matches a given string.
|
|
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
|
/**
|
|
116
|
-
* Type guard to check if a value is a numeric string.
|
|
102
|
+
* * Type guard to check if a value is a numeric string.
|
|
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.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export { generateAnagrams } from './string/anagram';
|
|
|
3
3
|
export { convertStringCase, replaceAllInString } from './string/convert';
|
|
4
4
|
export { calculateHCF as calculateGCD, calculateHCF, calculateLCM as calculateLCD, calculateLCM, convertToDecimal, getRandomNumber, isEven, isEven as isEvenNumber, isMultiple, isOdd, isOdd as isOddNumber, } from './number/basics';
|
|
5
5
|
export { numberToWords } from './number/convert';
|
|
6
|
-
export { findPrimeNumbers, isPrime } from './number/prime';
|
|
6
|
+
export { findPrimeNumbers, isPrime, isPrime as isPrimeNumber, } from './number/prime';
|
|
7
7
|
export { getNumbersInRange } from './number/range';
|
|
8
8
|
export { getColorForInitial } from './colors/initials';
|
|
9
9
|
export { generateRandomColorInHexRGB, generateRandomHSLColor, } from './colors/random';
|
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,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAGzE,OAAO,EACN,YAAY,IAAI,YAAY,EAC5B,YAAY,EACZ,YAAY,IAAI,YAAY,EAC5B,YAAY,EACZ,gBAAgB,EAChB,eAAe,EACf,MAAM,EACN,MA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