@oscarpalmer/atoms 0.176.0 → 0.177.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/array/exists.mjs +1 -1
- package/dist/array/filter.d.mts +26 -0
- package/dist/array/find.d.mts +1 -1
- package/dist/array/find.mjs +2 -2
- package/dist/array/first.d.mts +71 -0
- package/dist/array/first.mjs +11 -0
- package/dist/array/index.d.mts +2 -1
- package/dist/array/index.mjs +2 -1
- package/dist/array/last.d.mts +71 -0
- package/dist/array/last.mjs +11 -0
- package/dist/array/select.d.mts +42 -0
- package/dist/array/single.d.mts +34 -0
- package/dist/array/single.mjs +10 -0
- package/dist/index.d.mts +281 -8
- package/dist/index.mjs +120 -22
- package/dist/internal/array/find.d.mts +11 -4
- package/dist/internal/array/find.mjs +19 -11
- package/dist/internal/is.d.mts +9 -1
- package/dist/internal/is.mjs +30 -6
- package/dist/is.d.mts +38 -8
- package/dist/is.mjs +47 -7
- package/package.json +10 -2
- package/plugin/index.js +2 -1
- package/src/array/exists.ts +1 -1
- package/src/array/filter.ts +26 -0
- package/src/array/find.ts +4 -4
- package/src/array/first.ts +113 -0
- package/src/array/index.ts +1 -0
- package/src/array/last.ts +109 -0
- package/src/array/select.ts +84 -0
- package/src/array/single.ts +64 -0
- package/src/index.ts +2 -0
- package/src/internal/array/find.ts +36 -10
- package/src/internal/is.ts +93 -11
- package/src/is.ts +63 -6
package/src/internal/is.ts
CHANGED
|
@@ -49,6 +49,84 @@ export function isKey(value: unknown): value is Key {
|
|
|
49
49
|
return typeof value === 'number' || typeof value === 'string';
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
+
/**
|
|
53
|
+
* Is the value not an array or a plain object?
|
|
54
|
+
* @param value Value to check
|
|
55
|
+
* @returns `true` if the value is not an array or a plain object, otherwise `false`
|
|
56
|
+
*/
|
|
57
|
+
export function isNonArrayOrPlainObject<Value>(
|
|
58
|
+
value: Value,
|
|
59
|
+
): value is Exclude<Value, ArrayOrPlainObject> {
|
|
60
|
+
return !isArrayOrPlainObject(value);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Is the value not a constructor function?
|
|
65
|
+
* @param value Value to check
|
|
66
|
+
* @returns `true` if the value is not a constructor function, otherwise `false`
|
|
67
|
+
*/
|
|
68
|
+
export function isNonConstructor<Value>(value: Value): value is Exclude<Value, Constructor> {
|
|
69
|
+
return !isConstructor(value);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Is the value not an instance of the constructor?
|
|
74
|
+
* @param constructor Class constructor
|
|
75
|
+
* @param value Value to check
|
|
76
|
+
* @returns `true` if the value is not an instance of the constructor, otherwise `false`
|
|
77
|
+
*/
|
|
78
|
+
export function isNonInstanceOf<Instance, Value>(
|
|
79
|
+
constructor: Constructor<Instance>,
|
|
80
|
+
value: Value,
|
|
81
|
+
): value is Exclude<Value, Instance> {
|
|
82
|
+
return !isInstanceOf(constructor, value);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Is the value not a key?
|
|
87
|
+
* @param value Value to check
|
|
88
|
+
* @returns `true` if the value is not a `Key` _(`number` or `string`)_, otherwise `false`
|
|
89
|
+
*/
|
|
90
|
+
export function isNonKey<Value>(value: Value): value is Exclude<Value, Key> {
|
|
91
|
+
return !isKey(value);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Is the value not a number?
|
|
96
|
+
* @param value Value to check
|
|
97
|
+
* @returns `true` if the value is not a `number`, otherwise `false`
|
|
98
|
+
*/
|
|
99
|
+
export function isNonNumber<Value>(value: Value): value is Exclude<Value, number> {
|
|
100
|
+
return !isNumber(value);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Is the value not a plain object?
|
|
105
|
+
* @param value Value to check
|
|
106
|
+
* @returns `true` if the value is not a plain object, otherwise `false`
|
|
107
|
+
*/
|
|
108
|
+
export function isNonPlainObject<Value>(value: Value): value is Exclude<Value, PlainObject> {
|
|
109
|
+
return !isPlainObject(value);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Is the value not a primitive value?
|
|
114
|
+
* @param value Value to check
|
|
115
|
+
* @returns `true` if the value is not a primitive value, otherwise `false`
|
|
116
|
+
*/
|
|
117
|
+
export function isNonPrimitive<Value>(value: Value): value is Exclude<Value, Primitive> {
|
|
118
|
+
return !isPrimitive(value);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Is the value not a typed array?
|
|
123
|
+
* @param value Value to check
|
|
124
|
+
* @returns `true` if the value is not a typed array, otherwise `false`
|
|
125
|
+
*/
|
|
126
|
+
export function isNonTypedArray<Value>(value: Value): value is Exclude<Value, TypedArray> {
|
|
127
|
+
return !isTypedArray(value);
|
|
128
|
+
}
|
|
129
|
+
|
|
52
130
|
/**
|
|
53
131
|
* Is the value a number?
|
|
54
132
|
* @param value Value to check
|
|
@@ -87,7 +165,19 @@ export function isPlainObject(value: unknown): value is PlainObject {
|
|
|
87
165
|
* @returns `true` if the value matches, otherwise `false`
|
|
88
166
|
*/
|
|
89
167
|
export function isPrimitive(value: unknown): value is Primitive {
|
|
90
|
-
|
|
168
|
+
if (value == null) {
|
|
169
|
+
return true;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
const type = typeof value;
|
|
173
|
+
|
|
174
|
+
return (
|
|
175
|
+
type === 'bigint' ||
|
|
176
|
+
type === 'boolean' ||
|
|
177
|
+
type === 'number' ||
|
|
178
|
+
type === 'string' ||
|
|
179
|
+
type === 'symbol'
|
|
180
|
+
);
|
|
91
181
|
}
|
|
92
182
|
|
|
93
183
|
/**
|
|
@@ -96,7 +186,7 @@ export function isPrimitive(value: unknown): value is Primitive {
|
|
|
96
186
|
* @returns `true` if the value is a typed array, otherwise `false`
|
|
97
187
|
*/
|
|
98
188
|
export function isTypedArray(value: unknown): value is TypedArray {
|
|
99
|
-
|
|
189
|
+
(isTypedArray as any).types ??= new Set<unknown>([
|
|
100
190
|
Int8Array,
|
|
101
191
|
Uint8Array,
|
|
102
192
|
Uint8ClampedArray,
|
|
@@ -110,15 +200,7 @@ export function isTypedArray(value: unknown): value is TypedArray {
|
|
|
110
200
|
BigUint64Array,
|
|
111
201
|
]);
|
|
112
202
|
|
|
113
|
-
return
|
|
203
|
+
return (isTypedArray as any).types.has((value as TypedArray)?.constructor);
|
|
114
204
|
}
|
|
115
205
|
|
|
116
206
|
// #endregion
|
|
117
|
-
|
|
118
|
-
// #region Variables
|
|
119
|
-
|
|
120
|
-
const EXPRESSION_PRIMITIVE = /^(bigint|boolean|number|string|symbol)$/;
|
|
121
|
-
|
|
122
|
-
let TYPED_ARRAYS: Set<unknown>;
|
|
123
|
-
|
|
124
|
-
// #endregion
|
package/src/is.ts
CHANGED
|
@@ -30,15 +30,64 @@ export function isEmpty(value: unknown): boolean {
|
|
|
30
30
|
return true;
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
+
/**
|
|
34
|
+
* Is the value not empty, or holding non-empty values?
|
|
35
|
+
* @param value Value to check
|
|
36
|
+
* @returns `true` if the value is not considered empty, otherwise `false`
|
|
37
|
+
*/
|
|
38
|
+
export function isNonEmpty(value: unknown): boolean {
|
|
39
|
+
return !isEmpty(value);
|
|
40
|
+
}
|
|
41
|
+
|
|
33
42
|
/**
|
|
34
43
|
* Is the value not `undefined` or `null`?
|
|
35
44
|
* @param value Value to check
|
|
36
45
|
* @returns `true` if the value is not `undefined` or `null`, otherwise `false`
|
|
37
46
|
*/
|
|
38
|
-
export function isNonNullable(value:
|
|
47
|
+
export function isNonNullable<Value>(value: Value): value is Exclude<Value, undefined | null> {
|
|
39
48
|
return value != null;
|
|
40
49
|
}
|
|
41
50
|
|
|
51
|
+
/**
|
|
52
|
+
* Is the value not `undefined`, `null`, or stringified as an empty _(no whitespace)_ string?
|
|
53
|
+
* @param value Value to check
|
|
54
|
+
* @returns `true` if the value is not `undefined`, `null`, or matches an empty string, otherwise `false`
|
|
55
|
+
*/
|
|
56
|
+
export function isNonNullableOrEmpty<Value>(
|
|
57
|
+
value: Value,
|
|
58
|
+
): value is Exclude<Value, undefined | null | ''> {
|
|
59
|
+
return value != null && getString(value) !== '';
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Is the value not `undefined`, `null`, or stringified as a whitespace-only string?
|
|
64
|
+
* @param value Value to check
|
|
65
|
+
* @returns `true` if the value is not `undefined`, `null`, or matches a whitespace-only string, otherwise `false`
|
|
66
|
+
*/
|
|
67
|
+
export function isNonNullableOrWhitespace<Value>(
|
|
68
|
+
value: Value,
|
|
69
|
+
): value is Exclude<Value, undefined | null | ''> {
|
|
70
|
+
return value != null && !EXPRESSION_WHITESPACE.test(getString(value));
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Is the value not a number or a number-like string?
|
|
75
|
+
* @param value Value to check
|
|
76
|
+
* @returns `true` if the value is not a number or a number-like string, otherwise `false`
|
|
77
|
+
*/
|
|
78
|
+
export function isNonNumerical<Value>(value: Value): value is Exclude<Value, number | `${number}`> {
|
|
79
|
+
return !isNumerical(value);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Is the value not an object _(or function)_?
|
|
84
|
+
* @param value Value to check
|
|
85
|
+
* @returns `true` if the value is not an object, otherwise `false`
|
|
86
|
+
*/
|
|
87
|
+
export function isNonObject<Value>(value: Value): value is Exclude<Value, object> {
|
|
88
|
+
return !isObject(value);
|
|
89
|
+
}
|
|
90
|
+
|
|
42
91
|
/**
|
|
43
92
|
* Is the value `undefined` or `null`?
|
|
44
93
|
* @param value Value to check
|
|
@@ -49,18 +98,18 @@ export function isNullable(value: unknown): value is undefined | null {
|
|
|
49
98
|
}
|
|
50
99
|
|
|
51
100
|
/**
|
|
52
|
-
* Is the value `undefined`, `null`, or an empty _(no whitespace)_ string?
|
|
101
|
+
* Is the value `undefined`, `null`, or stringified as an empty _(no whitespace)_ string?
|
|
53
102
|
* @param value Value to check
|
|
54
|
-
* @returns `true` if the value is nullable or an empty string, otherwise `false`
|
|
103
|
+
* @returns `true` if the value is nullable or matches an empty string, otherwise `false`
|
|
55
104
|
*/
|
|
56
105
|
export function isNullableOrEmpty(value: unknown): value is undefined | null | '' {
|
|
57
106
|
return value == null || getString(value) === '';
|
|
58
107
|
}
|
|
59
108
|
|
|
60
109
|
/**
|
|
61
|
-
* Is the value `undefined`, `null`, or a whitespace-only string?
|
|
110
|
+
* Is the value `undefined`, `null`, or stringified as a whitespace-only string?
|
|
62
111
|
* @param value Value to check
|
|
63
|
-
* @returns `true` if the value is nullable or a whitespace-only string, otherwise `false`
|
|
112
|
+
* @returns `true` if the value is nullable or matches a whitespace-only string, otherwise `false`
|
|
64
113
|
*/
|
|
65
114
|
export function isNullableOrWhitespace(value: unknown): value is undefined | null | '' {
|
|
66
115
|
return value == null || EXPRESSION_WHITESPACE.test(getString(value));
|
|
@@ -69,7 +118,7 @@ export function isNullableOrWhitespace(value: unknown): value is undefined | nul
|
|
|
69
118
|
/**
|
|
70
119
|
* Is the value a number or a number-like string?
|
|
71
120
|
* @param value Value to check
|
|
72
|
-
* @returns `true` if the value is a number or a
|
|
121
|
+
* @returns `true` if the value is a number or a number-like string, otherwise `false`
|
|
73
122
|
*/
|
|
74
123
|
export function isNumerical(value: unknown): value is number | `${number}` {
|
|
75
124
|
return (
|
|
@@ -102,6 +151,14 @@ export {
|
|
|
102
151
|
isConstructor,
|
|
103
152
|
isInstanceOf,
|
|
104
153
|
isKey,
|
|
154
|
+
isNonArrayOrPlainObject,
|
|
155
|
+
isNonConstructor,
|
|
156
|
+
isNonInstanceOf,
|
|
157
|
+
isNonKey,
|
|
158
|
+
isNonNumber,
|
|
159
|
+
isNonPlainObject,
|
|
160
|
+
isNonPrimitive,
|
|
161
|
+
isNonTypedArray,
|
|
105
162
|
isNumber,
|
|
106
163
|
isPlainObject,
|
|
107
164
|
isPrimitive,
|