@luxass/utils 1.2.1 → 1.4.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/guards-DE5pQVvl.cjs +93 -0
- package/dist/guards-O1HGJraI.js +68 -0
- package/dist/guards.cjs +5 -19
- package/dist/guards.d-DXUlpL_S.d.cts +62 -0
- package/dist/guards.d-n1BzCANy.d.ts +62 -0
- package/dist/guards.d.cts +2 -58
- package/dist/guards.d.ts +2 -58
- package/dist/guards.js +3 -0
- package/dist/index.cjs +15 -58
- package/dist/index.d.cts +5 -4
- package/dist/index.d.ts +5 -4
- package/dist/index.js +5 -0
- package/dist/number-Bfr1z0Nr.js +26 -0
- package/dist/number-DRbo8lb6.cjs +33 -0
- package/dist/number.cjs +2 -7
- package/dist/number.d-C1FAMQlq.d.cts +23 -0
- package/dist/number.d-C2Xuq3Is.d.ts +23 -0
- package/dist/number.d.cts +2 -22
- package/dist/number.d.ts +2 -22
- package/dist/number.js +3 -0
- package/dist/string-C8IOUSBw.js +117 -0
- package/dist/string-CkqQ4Tys.cjs +154 -0
- package/dist/string.cjs +7 -33
- package/dist/string.d-DbrXP95T.d.cts +90 -0
- package/dist/string.d-Dv6EVJz4.d.ts +90 -0
- package/dist/string.d.cts +2 -79
- package/dist/string.d.ts +2 -79
- package/dist/string.js +3 -0
- package/dist/types.cjs +0 -2
- package/dist/types.d-BcKIY6l3.d.ts +72 -0
- package/dist/types.d-fcYBBT6c.d.cts +72 -0
- package/dist/types.d.cts +2 -66
- package/dist/types.d.ts +2 -66
- package/dist/types.js +0 -0
- package/package.json +21 -21
- package/dist/chunk-7RYURVAF.mjs +0 -6
- package/dist/chunk-MNDVPE25.mjs +0 -28
- package/dist/chunk-OKC7RR3A.mjs +0 -15
- package/dist/guards.mjs +0 -1
- package/dist/index.mjs +0 -3
- package/dist/number.mjs +0 -1
- package/dist/string.mjs +0 -1
- package/dist/types.mjs +0 -1
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
//#region src/guards.ts
|
|
4
|
+
/**
|
|
5
|
+
* Checks if a value is not null or undefined.
|
|
6
|
+
*
|
|
7
|
+
* @template T - The type of the input value.
|
|
8
|
+
* @param {T | null | undefined} v - The value to check for not being null or undefined.
|
|
9
|
+
* @returns {v is NonNullable<T>} - True if the value is not null or undefined, false otherwise.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* [true, false, 0, 1, "", "hello", null, undefined].filter(isNotNullish)
|
|
14
|
+
* // [true, false, 0, 1, "", "hello"]
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
function isNotNullish(v) {
|
|
18
|
+
return v != null;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Checks if a value is not null.
|
|
22
|
+
*
|
|
23
|
+
* @template T - The type of the input value.
|
|
24
|
+
* @param {T | null} v - The value to check for not being null.
|
|
25
|
+
* @returns {v is Exclude<T, null>} True if the value is not null, false otherwise.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* [true, false, 0, 1, "", "hello", null, undefined].filter(isNotNull)
|
|
30
|
+
* // [true, false, 0, 1, "", "hello", undefined]
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
function isNotNull(v) {
|
|
34
|
+
return v !== null;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Checks if a value is defined.
|
|
38
|
+
*
|
|
39
|
+
* @template T - The type of the input value.
|
|
40
|
+
* @param {T} v - The value to check for being defined.
|
|
41
|
+
* @returns {v is Exclude<T, undefined>} True if the value is defined, false otherwise.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```ts
|
|
45
|
+
* [true, false, 0, 1, "", "hello", null, undefined].filter(isDefined)
|
|
46
|
+
* // [true, false, 0, 1, "", "hello", null]
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
function isNotUndefined(v) {
|
|
50
|
+
return v !== void 0;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Checks if a value is truthy, excluding null and undefined.
|
|
54
|
+
*
|
|
55
|
+
* @template T - The type of the input value.
|
|
56
|
+
* @param {T} v - The value to check for truthiness.
|
|
57
|
+
* @returns {v is NonNullable<T>} True if the value is truthy, false otherwise.
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```ts
|
|
61
|
+
* [true, false, 0, 1, "", "hello", null, undefined].filter(isTruthy)
|
|
62
|
+
* // [true, 1, "hello"]
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
function isTruthy(v) {
|
|
66
|
+
return Boolean(v);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
//#endregion
|
|
70
|
+
Object.defineProperty(exports, 'isNotNull', {
|
|
71
|
+
enumerable: true,
|
|
72
|
+
get: function () {
|
|
73
|
+
return isNotNull;
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
Object.defineProperty(exports, 'isNotNullish', {
|
|
77
|
+
enumerable: true,
|
|
78
|
+
get: function () {
|
|
79
|
+
return isNotNullish;
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
Object.defineProperty(exports, 'isNotUndefined', {
|
|
83
|
+
enumerable: true,
|
|
84
|
+
get: function () {
|
|
85
|
+
return isNotUndefined;
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
Object.defineProperty(exports, 'isTruthy', {
|
|
89
|
+
enumerable: true,
|
|
90
|
+
get: function () {
|
|
91
|
+
return isTruthy;
|
|
92
|
+
}
|
|
93
|
+
});
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
//#region src/guards.ts
|
|
2
|
+
/**
|
|
3
|
+
* Checks if a value is not null or undefined.
|
|
4
|
+
*
|
|
5
|
+
* @template T - The type of the input value.
|
|
6
|
+
* @param {T | null | undefined} v - The value to check for not being null or undefined.
|
|
7
|
+
* @returns {v is NonNullable<T>} - True if the value is not null or undefined, false otherwise.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* [true, false, 0, 1, "", "hello", null, undefined].filter(isNotNullish)
|
|
12
|
+
* // [true, false, 0, 1, "", "hello"]
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
function isNotNullish(v) {
|
|
16
|
+
return v != null;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Checks if a value is not null.
|
|
20
|
+
*
|
|
21
|
+
* @template T - The type of the input value.
|
|
22
|
+
* @param {T | null} v - The value to check for not being null.
|
|
23
|
+
* @returns {v is Exclude<T, null>} True if the value is not null, false otherwise.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* [true, false, 0, 1, "", "hello", null, undefined].filter(isNotNull)
|
|
28
|
+
* // [true, false, 0, 1, "", "hello", undefined]
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
function isNotNull(v) {
|
|
32
|
+
return v !== null;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Checks if a value is defined.
|
|
36
|
+
*
|
|
37
|
+
* @template T - The type of the input value.
|
|
38
|
+
* @param {T} v - The value to check for being defined.
|
|
39
|
+
* @returns {v is Exclude<T, undefined>} True if the value is defined, false otherwise.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```ts
|
|
43
|
+
* [true, false, 0, 1, "", "hello", null, undefined].filter(isDefined)
|
|
44
|
+
* // [true, false, 0, 1, "", "hello", null]
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
function isNotUndefined(v) {
|
|
48
|
+
return v !== void 0;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Checks if a value is truthy, excluding null and undefined.
|
|
52
|
+
*
|
|
53
|
+
* @template T - The type of the input value.
|
|
54
|
+
* @param {T} v - The value to check for truthiness.
|
|
55
|
+
* @returns {v is NonNullable<T>} True if the value is truthy, false otherwise.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```ts
|
|
59
|
+
* [true, false, 0, 1, "", "hello", null, undefined].filter(isTruthy)
|
|
60
|
+
* // [true, 1, "hello"]
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
function isTruthy(v) {
|
|
64
|
+
return Boolean(v);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
//#endregion
|
|
68
|
+
export { isNotNull, isNotNullish, isNotUndefined, isTruthy };
|
package/dist/guards.cjs
CHANGED
|
@@ -1,20 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
const require_guards = require('./guards-DE5pQVvl.cjs');
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
function isNotNull(v) {
|
|
8
|
-
return v !== null;
|
|
9
|
-
}
|
|
10
|
-
function isNotUndefined(v) {
|
|
11
|
-
return v !== void 0;
|
|
12
|
-
}
|
|
13
|
-
function isTruthy(v) {
|
|
14
|
-
return Boolean(v);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
exports.isNotNull = isNotNull;
|
|
18
|
-
exports.isNotNullish = isNotNullish;
|
|
19
|
-
exports.isNotUndefined = isNotUndefined;
|
|
20
|
-
exports.isTruthy = isTruthy;
|
|
3
|
+
exports.isNotNull = require_guards.isNotNull
|
|
4
|
+
exports.isNotNullish = require_guards.isNotNullish
|
|
5
|
+
exports.isNotUndefined = require_guards.isNotUndefined
|
|
6
|
+
exports.isTruthy = require_guards.isTruthy
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
//#region src/guards.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Checks if a value is not null or undefined.
|
|
4
|
+
*
|
|
5
|
+
* @template T - The type of the input value.
|
|
6
|
+
* @param {T | null | undefined} v - The value to check for not being null or undefined.
|
|
7
|
+
* @returns {v is NonNullable<T>} - True if the value is not null or undefined, false otherwise.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* [true, false, 0, 1, "", "hello", null, undefined].filter(isNotNullish)
|
|
12
|
+
* // [true, false, 0, 1, "", "hello"]
|
|
13
|
+
* ```
|
|
14
|
+
*/declare function isNotNullish<T>(v: T | null | undefined): v is NonNullable<T>;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Checks if a value is not null.
|
|
18
|
+
*
|
|
19
|
+
* @template T - The type of the input value.
|
|
20
|
+
* @param {T | null} v - The value to check for not being null.
|
|
21
|
+
* @returns {v is Exclude<T, null>} True if the value is not null, false otherwise.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* [true, false, 0, 1, "", "hello", null, undefined].filter(isNotNull)
|
|
26
|
+
* // [true, false, 0, 1, "", "hello", undefined]
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
declare function isNotNull<T>(v: T | null): v is Exclude<T, null>;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Checks if a value is defined.
|
|
33
|
+
*
|
|
34
|
+
* @template T - The type of the input value.
|
|
35
|
+
* @param {T} v - The value to check for being defined.
|
|
36
|
+
* @returns {v is Exclude<T, undefined>} True if the value is defined, false otherwise.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```ts
|
|
40
|
+
* [true, false, 0, 1, "", "hello", null, undefined].filter(isDefined)
|
|
41
|
+
* // [true, false, 0, 1, "", "hello", null]
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
declare function isNotUndefined<T>(v: T): v is Exclude<T, undefined>;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Checks if a value is truthy, excluding null and undefined.
|
|
48
|
+
*
|
|
49
|
+
* @template T - The type of the input value.
|
|
50
|
+
* @param {T} v - The value to check for truthiness.
|
|
51
|
+
* @returns {v is NonNullable<T>} True if the value is truthy, false otherwise.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```ts
|
|
55
|
+
* [true, false, 0, 1, "", "hello", null, undefined].filter(isTruthy)
|
|
56
|
+
* // [true, 1, "hello"]
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
declare function isTruthy<T>(v: T): v is NonNullable<T>;
|
|
60
|
+
|
|
61
|
+
//#endregion
|
|
62
|
+
export { isNotNull, isNotNullish, isNotUndefined, isTruthy };
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
//#region src/guards.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Checks if a value is not null or undefined.
|
|
4
|
+
*
|
|
5
|
+
* @template T - The type of the input value.
|
|
6
|
+
* @param {T | null | undefined} v - The value to check for not being null or undefined.
|
|
7
|
+
* @returns {v is NonNullable<T>} - True if the value is not null or undefined, false otherwise.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* [true, false, 0, 1, "", "hello", null, undefined].filter(isNotNullish)
|
|
12
|
+
* // [true, false, 0, 1, "", "hello"]
|
|
13
|
+
* ```
|
|
14
|
+
*/declare function isNotNullish<T>(v: T | null | undefined): v is NonNullable<T>;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Checks if a value is not null.
|
|
18
|
+
*
|
|
19
|
+
* @template T - The type of the input value.
|
|
20
|
+
* @param {T | null} v - The value to check for not being null.
|
|
21
|
+
* @returns {v is Exclude<T, null>} True if the value is not null, false otherwise.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* [true, false, 0, 1, "", "hello", null, undefined].filter(isNotNull)
|
|
26
|
+
* // [true, false, 0, 1, "", "hello", undefined]
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
declare function isNotNull<T>(v: T | null): v is Exclude<T, null>;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Checks if a value is defined.
|
|
33
|
+
*
|
|
34
|
+
* @template T - The type of the input value.
|
|
35
|
+
* @param {T} v - The value to check for being defined.
|
|
36
|
+
* @returns {v is Exclude<T, undefined>} True if the value is defined, false otherwise.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```ts
|
|
40
|
+
* [true, false, 0, 1, "", "hello", null, undefined].filter(isDefined)
|
|
41
|
+
* // [true, false, 0, 1, "", "hello", null]
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
declare function isNotUndefined<T>(v: T): v is Exclude<T, undefined>;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Checks if a value is truthy, excluding null and undefined.
|
|
48
|
+
*
|
|
49
|
+
* @template T - The type of the input value.
|
|
50
|
+
* @param {T} v - The value to check for truthiness.
|
|
51
|
+
* @returns {v is NonNullable<T>} True if the value is truthy, false otherwise.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```ts
|
|
55
|
+
* [true, false, 0, 1, "", "hello", null, undefined].filter(isTruthy)
|
|
56
|
+
* // [true, 1, "hello"]
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
declare function isTruthy<T>(v: T): v is NonNullable<T>;
|
|
60
|
+
|
|
61
|
+
//#endregion
|
|
62
|
+
export { isNotNull as isNotNull$1, isNotNullish as isNotNullish$1, isNotUndefined as isNotUndefined$1, isTruthy as isTruthy$1 };
|
package/dist/guards.d.cts
CHANGED
|
@@ -1,58 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*
|
|
4
|
-
* @template T - The type of the input value.
|
|
5
|
-
* @param {T | null | undefined} v - The value to check for not being null or undefined.
|
|
6
|
-
* @returns {v is NonNullable<T>} - True if the value is not null or undefined, false otherwise.
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* ```ts
|
|
10
|
-
* [true, false, 0, 1, "", "hello", null, undefined].filter(isNotNullish)
|
|
11
|
-
* // [true, false, 0, 1, "", "hello"]
|
|
12
|
-
* ```
|
|
13
|
-
*/
|
|
14
|
-
declare function isNotNullish<T>(v: T | null | undefined): v is NonNullable<T>;
|
|
15
|
-
/**
|
|
16
|
-
* Checks if a value is not null.
|
|
17
|
-
*
|
|
18
|
-
* @template T - The type of the input value.
|
|
19
|
-
* @param {T | null} v - The value to check for not being null.
|
|
20
|
-
* @returns {v is Exclude<T, null>} True if the value is not null, false otherwise.
|
|
21
|
-
*
|
|
22
|
-
* @example
|
|
23
|
-
* ```ts
|
|
24
|
-
* [true, false, 0, 1, "", "hello", null, undefined].filter(isNotNull)
|
|
25
|
-
* // [true, false, 0, 1, "", "hello", undefined]
|
|
26
|
-
* ```
|
|
27
|
-
*/
|
|
28
|
-
declare function isNotNull<T>(v: T | null): v is Exclude<T, null>;
|
|
29
|
-
/**
|
|
30
|
-
* Checks if a value is defined.
|
|
31
|
-
*
|
|
32
|
-
* @template T - The type of the input value.
|
|
33
|
-
* @param {T} v - The value to check for being defined.
|
|
34
|
-
* @returns {v is Exclude<T, undefined>} True if the value is defined, false otherwise.
|
|
35
|
-
*
|
|
36
|
-
* @example
|
|
37
|
-
* ```ts
|
|
38
|
-
* [true, false, 0, 1, "", "hello", null, undefined].filter(isDefined)
|
|
39
|
-
* // [true, false, 0, 1, "", "hello", null]
|
|
40
|
-
* ```
|
|
41
|
-
*/
|
|
42
|
-
declare function isNotUndefined<T>(v: T): v is Exclude<T, undefined>;
|
|
43
|
-
/**
|
|
44
|
-
* Checks if a value is truthy, excluding null and undefined.
|
|
45
|
-
*
|
|
46
|
-
* @template T - The type of the input value.
|
|
47
|
-
* @param {T} v - The value to check for truthiness.
|
|
48
|
-
* @returns {v is NonNullable<T>} True if the value is truthy, false otherwise.
|
|
49
|
-
*
|
|
50
|
-
* @example
|
|
51
|
-
* ```ts
|
|
52
|
-
* [true, false, 0, 1, "", "hello", null, undefined].filter(isTruthy)
|
|
53
|
-
* // [true, 1, "hello"]
|
|
54
|
-
* ```
|
|
55
|
-
*/
|
|
56
|
-
declare function isTruthy<T>(v: T): v is NonNullable<T>;
|
|
57
|
-
|
|
58
|
-
export { isNotNull, isNotNullish, isNotUndefined, isTruthy };
|
|
1
|
+
import { isNotNull, isNotNullish, isNotUndefined, isTruthy } from "./guards.d-DXUlpL_S.cjs";
|
|
2
|
+
export { isNotNull, isNotNullish, isNotUndefined, isTruthy };
|
package/dist/guards.d.ts
CHANGED
|
@@ -1,58 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*
|
|
4
|
-
* @template T - The type of the input value.
|
|
5
|
-
* @param {T | null | undefined} v - The value to check for not being null or undefined.
|
|
6
|
-
* @returns {v is NonNullable<T>} - True if the value is not null or undefined, false otherwise.
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* ```ts
|
|
10
|
-
* [true, false, 0, 1, "", "hello", null, undefined].filter(isNotNullish)
|
|
11
|
-
* // [true, false, 0, 1, "", "hello"]
|
|
12
|
-
* ```
|
|
13
|
-
*/
|
|
14
|
-
declare function isNotNullish<T>(v: T | null | undefined): v is NonNullable<T>;
|
|
15
|
-
/**
|
|
16
|
-
* Checks if a value is not null.
|
|
17
|
-
*
|
|
18
|
-
* @template T - The type of the input value.
|
|
19
|
-
* @param {T | null} v - The value to check for not being null.
|
|
20
|
-
* @returns {v is Exclude<T, null>} True if the value is not null, false otherwise.
|
|
21
|
-
*
|
|
22
|
-
* @example
|
|
23
|
-
* ```ts
|
|
24
|
-
* [true, false, 0, 1, "", "hello", null, undefined].filter(isNotNull)
|
|
25
|
-
* // [true, false, 0, 1, "", "hello", undefined]
|
|
26
|
-
* ```
|
|
27
|
-
*/
|
|
28
|
-
declare function isNotNull<T>(v: T | null): v is Exclude<T, null>;
|
|
29
|
-
/**
|
|
30
|
-
* Checks if a value is defined.
|
|
31
|
-
*
|
|
32
|
-
* @template T - The type of the input value.
|
|
33
|
-
* @param {T} v - The value to check for being defined.
|
|
34
|
-
* @returns {v is Exclude<T, undefined>} True if the value is defined, false otherwise.
|
|
35
|
-
*
|
|
36
|
-
* @example
|
|
37
|
-
* ```ts
|
|
38
|
-
* [true, false, 0, 1, "", "hello", null, undefined].filter(isDefined)
|
|
39
|
-
* // [true, false, 0, 1, "", "hello", null]
|
|
40
|
-
* ```
|
|
41
|
-
*/
|
|
42
|
-
declare function isNotUndefined<T>(v: T): v is Exclude<T, undefined>;
|
|
43
|
-
/**
|
|
44
|
-
* Checks if a value is truthy, excluding null and undefined.
|
|
45
|
-
*
|
|
46
|
-
* @template T - The type of the input value.
|
|
47
|
-
* @param {T} v - The value to check for truthiness.
|
|
48
|
-
* @returns {v is NonNullable<T>} True if the value is truthy, false otherwise.
|
|
49
|
-
*
|
|
50
|
-
* @example
|
|
51
|
-
* ```ts
|
|
52
|
-
* [true, false, 0, 1, "", "hello", null, undefined].filter(isTruthy)
|
|
53
|
-
* // [true, 1, "hello"]
|
|
54
|
-
* ```
|
|
55
|
-
*/
|
|
56
|
-
declare function isTruthy<T>(v: T): v is NonNullable<T>;
|
|
57
|
-
|
|
58
|
-
export { isNotNull, isNotNullish, isNotUndefined, isTruthy };
|
|
1
|
+
import { isNotNull$1 as isNotNull, isNotNullish$1 as isNotNullish, isNotUndefined$1 as isNotUndefined, isTruthy$1 as isTruthy } from "./guards.d-n1BzCANy.js";
|
|
2
|
+
export { isNotNull, isNotNullish, isNotUndefined, isTruthy };
|
package/dist/guards.js
ADDED
package/dist/index.cjs
CHANGED
|
@@ -1,58 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
// src/number.ts
|
|
18
|
-
function clamp(value, min, max) {
|
|
19
|
-
return Math.min(Math.max(value, min), max);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
// src/string.ts
|
|
23
|
-
function capitalize(str) {
|
|
24
|
-
if (typeof str !== "string") throw new TypeError("Expected a string");
|
|
25
|
-
if (str.trim().length === 0) return "";
|
|
26
|
-
return str[0].toUpperCase() + str.slice(1).toLowerCase();
|
|
27
|
-
}
|
|
28
|
-
function toCamelCase(str) {
|
|
29
|
-
if (typeof str !== "string") throw new TypeError("Expected a string");
|
|
30
|
-
if (str.trim().length === 0) return "";
|
|
31
|
-
return str.toLowerCase().replace(/[-_](.)/g, (_, c) => c.toUpperCase());
|
|
32
|
-
}
|
|
33
|
-
function toKebabCase(str) {
|
|
34
|
-
if (typeof str !== "string") throw new TypeError("Expected a string");
|
|
35
|
-
if (str.trim().length === 0) return "";
|
|
36
|
-
return str.replace(/([a-z])([A-Z])/g, "$1-$2").replace(/[\s_]+/g, "-").toLowerCase();
|
|
37
|
-
}
|
|
38
|
-
function toPascalCase(str) {
|
|
39
|
-
if (typeof str !== "string") throw new TypeError("Expected a string");
|
|
40
|
-
if (str.trim().length === 0) return "";
|
|
41
|
-
return str.toLowerCase().replace(/[-_](.)/g, (_, c) => c.toUpperCase()).replace(/^[a-z]/, (c) => c.toUpperCase());
|
|
42
|
-
}
|
|
43
|
-
function toSnakeCase(str) {
|
|
44
|
-
if (typeof str !== "string") throw new TypeError("Expected a string");
|
|
45
|
-
if (str.trim().length === 0) return "";
|
|
46
|
-
return str.replace(/([a-z])([A-Z])/g, "$1_$2").toLowerCase();
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
exports.capitalize = capitalize;
|
|
50
|
-
exports.clamp = clamp;
|
|
51
|
-
exports.isNotNull = isNotNull;
|
|
52
|
-
exports.isNotNullish = isNotNullish;
|
|
53
|
-
exports.isNotUndefined = isNotUndefined;
|
|
54
|
-
exports.isTruthy = isTruthy;
|
|
55
|
-
exports.toCamelCase = toCamelCase;
|
|
56
|
-
exports.toKebabCase = toKebabCase;
|
|
57
|
-
exports.toPascalCase = toPascalCase;
|
|
58
|
-
exports.toSnakeCase = toSnakeCase;
|
|
1
|
+
const require_guards = require('./guards-DE5pQVvl.cjs');
|
|
2
|
+
const require_number = require('./number-DRbo8lb6.cjs');
|
|
3
|
+
const require_string = require('./string-CkqQ4Tys.cjs');
|
|
4
|
+
|
|
5
|
+
exports.capitalize = require_string.capitalize
|
|
6
|
+
exports.clamp = require_number.clamp
|
|
7
|
+
exports.dedent = require_string.dedent
|
|
8
|
+
exports.isNotNull = require_guards.isNotNull
|
|
9
|
+
exports.isNotNullish = require_guards.isNotNullish
|
|
10
|
+
exports.isNotUndefined = require_guards.isNotUndefined
|
|
11
|
+
exports.isTruthy = require_guards.isTruthy
|
|
12
|
+
exports.toCamelCase = require_string.toCamelCase
|
|
13
|
+
exports.toKebabCase = require_string.toKebabCase
|
|
14
|
+
exports.toPascalCase = require_string.toPascalCase
|
|
15
|
+
exports.toSnakeCase = require_string.toSnakeCase
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { isNotNull, isNotNullish, isNotUndefined, isTruthy } from "./guards.d-DXUlpL_S.cjs";
|
|
2
|
+
import { clamp } from "./number.d-C1FAMQlq.cjs";
|
|
3
|
+
import { capitalize, dedent, toCamelCase, toKebabCase, toPascalCase, toSnakeCase } from "./string.d-DbrXP95T.cjs";
|
|
4
|
+
import { Arrayable, Awaitable, ElementOf, InferArguments, Nullable, Nullish } from "./types.d-fcYBBT6c.cjs";
|
|
5
|
+
export { Arrayable, Awaitable, ElementOf, InferArguments, Nullable, Nullish, capitalize, clamp, dedent, isNotNull, isNotNullish, isNotUndefined, isTruthy, toCamelCase, toKebabCase, toPascalCase, toSnakeCase };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { isNotNull$1 as isNotNull, isNotNullish$1 as isNotNullish, isNotUndefined$1 as isNotUndefined, isTruthy$1 as isTruthy } from "./guards.d-n1BzCANy.js";
|
|
2
|
+
import { clamp$1 as clamp } from "./number.d-C2Xuq3Is.js";
|
|
3
|
+
import { capitalize$1 as capitalize, dedent$1 as dedent, toCamelCase$1 as toCamelCase, toKebabCase$1 as toKebabCase, toPascalCase$1 as toPascalCase, toSnakeCase$1 as toSnakeCase } from "./string.d-Dv6EVJz4.js";
|
|
4
|
+
import { Arrayable, Awaitable, ElementOf, InferArguments, Nullable, Nullish } from "./types.d-BcKIY6l3.js";
|
|
5
|
+
export { Arrayable, Awaitable, ElementOf, InferArguments, Nullable, Nullish, capitalize, clamp, dedent, isNotNull, isNotNullish, isNotUndefined, isTruthy, toCamelCase, toKebabCase, toPascalCase, toSnakeCase };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { isNotNull, isNotNullish, isNotUndefined, isTruthy } from "./guards-O1HGJraI.js";
|
|
2
|
+
import { clamp } from "./number-Bfr1z0Nr.js";
|
|
3
|
+
import { capitalize, dedent, toCamelCase, toKebabCase, toPascalCase, toSnakeCase } from "./string-C8IOUSBw.js";
|
|
4
|
+
|
|
5
|
+
export { capitalize, clamp, dedent, isNotNull, isNotNullish, isNotUndefined, isTruthy, toCamelCase, toKebabCase, toPascalCase, toSnakeCase };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
//#region src/number.ts
|
|
2
|
+
/**
|
|
3
|
+
* Clamp a value between a min and max value.
|
|
4
|
+
* @param {number} value
|
|
5
|
+
* @param {number} min
|
|
6
|
+
* @param {number} max
|
|
7
|
+
* @returns {number} the clamped value
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* clamp(5, 0, 10)
|
|
12
|
+
* // 5
|
|
13
|
+
*
|
|
14
|
+
* clamp(5, 10, 20)
|
|
15
|
+
* // 10
|
|
16
|
+
*
|
|
17
|
+
* clamp(5, 0, 4)
|
|
18
|
+
* // 4
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
function clamp(value, min, max) {
|
|
22
|
+
return Math.min(Math.max(value, min), max);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
//#endregion
|
|
26
|
+
export { clamp };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
//#region src/number.ts
|
|
4
|
+
/**
|
|
5
|
+
* Clamp a value between a min and max value.
|
|
6
|
+
* @param {number} value
|
|
7
|
+
* @param {number} min
|
|
8
|
+
* @param {number} max
|
|
9
|
+
* @returns {number} the clamped value
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* clamp(5, 0, 10)
|
|
14
|
+
* // 5
|
|
15
|
+
*
|
|
16
|
+
* clamp(5, 10, 20)
|
|
17
|
+
* // 10
|
|
18
|
+
*
|
|
19
|
+
* clamp(5, 0, 4)
|
|
20
|
+
* // 4
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
function clamp(value, min, max) {
|
|
24
|
+
return Math.min(Math.max(value, min), max);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
//#endregion
|
|
28
|
+
Object.defineProperty(exports, 'clamp', {
|
|
29
|
+
enumerable: true,
|
|
30
|
+
get: function () {
|
|
31
|
+
return clamp;
|
|
32
|
+
}
|
|
33
|
+
});
|
package/dist/number.cjs
CHANGED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
//#region src/number.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Clamp a value between a min and max value.
|
|
4
|
+
* @param {number} value
|
|
5
|
+
* @param {number} min
|
|
6
|
+
* @param {number} max
|
|
7
|
+
* @returns {number} the clamped value
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* clamp(5, 0, 10)
|
|
12
|
+
* // 5
|
|
13
|
+
*
|
|
14
|
+
* clamp(5, 10, 20)
|
|
15
|
+
* // 10
|
|
16
|
+
*
|
|
17
|
+
* clamp(5, 0, 4)
|
|
18
|
+
* // 4
|
|
19
|
+
* ```
|
|
20
|
+
*/declare function clamp(value: number, min: number, max: number): number;
|
|
21
|
+
|
|
22
|
+
//#endregion
|
|
23
|
+
export { clamp };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
//#region src/number.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Clamp a value between a min and max value.
|
|
4
|
+
* @param {number} value
|
|
5
|
+
* @param {number} min
|
|
6
|
+
* @param {number} max
|
|
7
|
+
* @returns {number} the clamped value
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* clamp(5, 0, 10)
|
|
12
|
+
* // 5
|
|
13
|
+
*
|
|
14
|
+
* clamp(5, 10, 20)
|
|
15
|
+
* // 10
|
|
16
|
+
*
|
|
17
|
+
* clamp(5, 0, 4)
|
|
18
|
+
* // 4
|
|
19
|
+
* ```
|
|
20
|
+
*/declare function clamp(value: number, min: number, max: number): number;
|
|
21
|
+
|
|
22
|
+
//#endregion
|
|
23
|
+
export { clamp as clamp$1 };
|