@oscarpalmer/atoms 0.96.0 → 0.97.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/is.cjs +14 -1
- package/dist/is.js +14 -1
- package/dist/value/clone.cjs +10 -0
- package/dist/value/clone.js +11 -1
- package/package.json +2 -2
- package/src/is.ts +19 -13
- package/src/value/clone.ts +23 -0
- package/types/index.d.cts +3 -0
- package/types/is.d.cts +3 -0
- package/types/is.d.ts +3 -0
package/dist/is.cjs
CHANGED
|
@@ -52,9 +52,22 @@ function isPrimitive(value) {
|
|
|
52
52
|
return value == null || primitiveExpression.test(typeof value);
|
|
53
53
|
}
|
|
54
54
|
function isTypedArray(value) {
|
|
55
|
-
return value
|
|
55
|
+
return typeArrays.has(value?.constructor);
|
|
56
56
|
}
|
|
57
57
|
const primitiveExpression = /^(bigint|boolean|number|string|symbol)$/;
|
|
58
|
+
const typeArrays = /* @__PURE__ */ new Set([
|
|
59
|
+
Int8Array,
|
|
60
|
+
Uint8Array,
|
|
61
|
+
Uint8ClampedArray,
|
|
62
|
+
Int16Array,
|
|
63
|
+
Uint16Array,
|
|
64
|
+
Int32Array,
|
|
65
|
+
Uint32Array,
|
|
66
|
+
Float32Array,
|
|
67
|
+
Float64Array,
|
|
68
|
+
BigInt64Array,
|
|
69
|
+
BigUint64Array
|
|
70
|
+
]);
|
|
58
71
|
const whiteSpaceExpression = /^\s*$/;
|
|
59
72
|
|
|
60
73
|
exports.isArrayOrPlainObject = isArrayOrPlainObject;
|
package/dist/is.js
CHANGED
|
@@ -48,9 +48,22 @@ function isPrimitive(value) {
|
|
|
48
48
|
return value == null || primitiveExpression.test(typeof value);
|
|
49
49
|
}
|
|
50
50
|
function isTypedArray(value) {
|
|
51
|
-
return value
|
|
51
|
+
return typeArrays.has(value?.constructor);
|
|
52
52
|
}
|
|
53
53
|
const primitiveExpression = /^(bigint|boolean|number|string|symbol)$/;
|
|
54
|
+
const typeArrays = /* @__PURE__ */ new Set([
|
|
55
|
+
Int8Array,
|
|
56
|
+
Uint8Array,
|
|
57
|
+
Uint8ClampedArray,
|
|
58
|
+
Int16Array,
|
|
59
|
+
Uint16Array,
|
|
60
|
+
Int32Array,
|
|
61
|
+
Uint32Array,
|
|
62
|
+
Float32Array,
|
|
63
|
+
Float64Array,
|
|
64
|
+
BigInt64Array,
|
|
65
|
+
BigUint64Array
|
|
66
|
+
]);
|
|
54
67
|
const whiteSpaceExpression = /^\s*$/;
|
|
55
68
|
|
|
56
69
|
export { isArrayOrPlainObject, isEmpty, isKey, isNullable, isNullableOrEmpty, isNullableOrWhitespace, isNumber, isNumerical, isObject, isPlainObject, isPrimitive, isTypedArray };
|
package/dist/value/clone.cjs
CHANGED
|
@@ -82,6 +82,14 @@ function cloneRegularExpression(value, depth, references) {
|
|
|
82
82
|
references.set(value, cloned);
|
|
83
83
|
return cloned;
|
|
84
84
|
}
|
|
85
|
+
function cloneTypedArray(value, depth, references) {
|
|
86
|
+
if (depth >= 100) {
|
|
87
|
+
return value;
|
|
88
|
+
}
|
|
89
|
+
const cloned = new value.constructor(value);
|
|
90
|
+
references.set(value, cloned);
|
|
91
|
+
return cloned;
|
|
92
|
+
}
|
|
85
93
|
function cloneValue(value, depth, references) {
|
|
86
94
|
switch (true) {
|
|
87
95
|
case value == null:
|
|
@@ -113,6 +121,8 @@ function cloneValue(value, depth, references) {
|
|
|
113
121
|
return cloneNode(value, depth, references);
|
|
114
122
|
case is.isArrayOrPlainObject(value):
|
|
115
123
|
return cloneObject(value, depth, references);
|
|
124
|
+
case is.isTypedArray(value):
|
|
125
|
+
return cloneTypedArray(value, depth, references);
|
|
116
126
|
default:
|
|
117
127
|
return tryStructuredClone(value, depth, references);
|
|
118
128
|
}
|
package/dist/value/clone.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isArrayOrPlainObject } from '../is.js';
|
|
1
|
+
import { isTypedArray, isArrayOrPlainObject } from '../is.js';
|
|
2
2
|
|
|
3
3
|
function clone(value) {
|
|
4
4
|
return cloneValue(value, 0, /* @__PURE__ */ new WeakMap());
|
|
@@ -78,6 +78,14 @@ function cloneRegularExpression(value, depth, references) {
|
|
|
78
78
|
references.set(value, cloned);
|
|
79
79
|
return cloned;
|
|
80
80
|
}
|
|
81
|
+
function cloneTypedArray(value, depth, references) {
|
|
82
|
+
if (depth >= 100) {
|
|
83
|
+
return value;
|
|
84
|
+
}
|
|
85
|
+
const cloned = new value.constructor(value);
|
|
86
|
+
references.set(value, cloned);
|
|
87
|
+
return cloned;
|
|
88
|
+
}
|
|
81
89
|
function cloneValue(value, depth, references) {
|
|
82
90
|
switch (true) {
|
|
83
91
|
case value == null:
|
|
@@ -109,6 +117,8 @@ function cloneValue(value, depth, references) {
|
|
|
109
117
|
return cloneNode(value, depth, references);
|
|
110
118
|
case isArrayOrPlainObject(value):
|
|
111
119
|
return cloneObject(value, depth, references);
|
|
120
|
+
case isTypedArray(value):
|
|
121
|
+
return cloneTypedArray(value, depth, references);
|
|
112
122
|
default:
|
|
113
123
|
return tryStructuredClone(value, depth, references);
|
|
114
124
|
}
|
package/package.json
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"@vitest/coverage-istanbul": "^3.1",
|
|
14
14
|
"dts-bundle-generator": "^9.5",
|
|
15
15
|
"glob": "^11",
|
|
16
|
-
"
|
|
16
|
+
"jsdom": "^26.1",
|
|
17
17
|
"typescript": "^5.8",
|
|
18
18
|
"vite": "^6.3",
|
|
19
19
|
"vitest": "^3.1"
|
|
@@ -198,5 +198,5 @@
|
|
|
198
198
|
},
|
|
199
199
|
"type": "module",
|
|
200
200
|
"types": "./types/index.d.cts",
|
|
201
|
-
"version": "0.
|
|
201
|
+
"version": "0.97.0"
|
|
202
202
|
}
|
package/src/is.ts
CHANGED
|
@@ -120,23 +120,29 @@ export function isPrimitive(value: unknown): value is Primitive {
|
|
|
120
120
|
return value == null || primitiveExpression.test(typeof value);
|
|
121
121
|
}
|
|
122
122
|
|
|
123
|
+
/**
|
|
124
|
+
* Is the value a typed array?
|
|
125
|
+
*/
|
|
123
126
|
export function isTypedArray(value: unknown): value is TypedArray {
|
|
124
|
-
return (
|
|
125
|
-
value instanceof Int8Array ||
|
|
126
|
-
value instanceof Uint8Array ||
|
|
127
|
-
value instanceof Uint8ClampedArray ||
|
|
128
|
-
value instanceof Int16Array ||
|
|
129
|
-
value instanceof Uint16Array ||
|
|
130
|
-
value instanceof Int32Array ||
|
|
131
|
-
value instanceof Uint32Array ||
|
|
132
|
-
value instanceof Float32Array ||
|
|
133
|
-
value instanceof Float64Array ||
|
|
134
|
-
value instanceof BigInt64Array ||
|
|
135
|
-
value instanceof BigUint64Array
|
|
136
|
-
);
|
|
127
|
+
return typeArrays.has((value as TypedArray)?.constructor);
|
|
137
128
|
}
|
|
138
129
|
|
|
139
130
|
//
|
|
140
131
|
|
|
141
132
|
const primitiveExpression = /^(bigint|boolean|number|string|symbol)$/;
|
|
133
|
+
|
|
134
|
+
const typeArrays = new Set<unknown>([
|
|
135
|
+
Int8Array,
|
|
136
|
+
Uint8Array,
|
|
137
|
+
Uint8ClampedArray,
|
|
138
|
+
Int16Array,
|
|
139
|
+
Uint16Array,
|
|
140
|
+
Int32Array,
|
|
141
|
+
Uint32Array,
|
|
142
|
+
Float32Array,
|
|
143
|
+
Float64Array,
|
|
144
|
+
BigInt64Array,
|
|
145
|
+
BigUint64Array,
|
|
146
|
+
]);
|
|
147
|
+
|
|
142
148
|
const whiteSpaceExpression = /^\s*$/;
|
package/src/value/clone.ts
CHANGED
|
@@ -140,6 +140,26 @@ function cloneRegularExpression(
|
|
|
140
140
|
return cloned;
|
|
141
141
|
}
|
|
142
142
|
|
|
143
|
+
function cloneTypedArray(
|
|
144
|
+
value: TypedArray,
|
|
145
|
+
depth: number,
|
|
146
|
+
references: WeakMap<WeakKey, unknown>,
|
|
147
|
+
): TypedArray {
|
|
148
|
+
if (depth >= 100) {
|
|
149
|
+
return value;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const cloned = new (
|
|
153
|
+
value.constructor as new (
|
|
154
|
+
...args: unknown[]
|
|
155
|
+
) => TypedArray
|
|
156
|
+
)(value);
|
|
157
|
+
|
|
158
|
+
references.set(value, cloned);
|
|
159
|
+
|
|
160
|
+
return cloned as TypedArray;
|
|
161
|
+
}
|
|
162
|
+
|
|
143
163
|
function cloneValue(
|
|
144
164
|
value: unknown,
|
|
145
165
|
depth: number,
|
|
@@ -189,6 +209,9 @@ function cloneValue(
|
|
|
189
209
|
case isArrayOrPlainObject(value):
|
|
190
210
|
return cloneObject(value, depth, references);
|
|
191
211
|
|
|
212
|
+
case isTypedArray(value):
|
|
213
|
+
return cloneTypedArray(value, depth, references);
|
|
214
|
+
|
|
192
215
|
default:
|
|
193
216
|
return tryStructuredClone(value, depth, references);
|
|
194
217
|
}
|
package/types/index.d.cts
CHANGED
|
@@ -2008,6 +2008,9 @@ export declare function isPlainObject(value: unknown): value is PlainObject;
|
|
|
2008
2008
|
* Is the value a primitive value?
|
|
2009
2009
|
*/
|
|
2010
2010
|
export declare function isPrimitive(value: unknown): value is Primitive;
|
|
2011
|
+
/**
|
|
2012
|
+
* Is the value a typed array?
|
|
2013
|
+
*/
|
|
2011
2014
|
export declare function isTypedArray(value: unknown): value is TypedArray;
|
|
2012
2015
|
/**
|
|
2013
2016
|
* Chunk an array _(into smaller arrays)_, with an optional size _(default and maximum is 5000)_.
|
package/types/is.d.cts
CHANGED
|
@@ -63,6 +63,9 @@ export declare function isPlainObject(value: unknown): value is PlainObject;
|
|
|
63
63
|
* Is the value a primitive value?
|
|
64
64
|
*/
|
|
65
65
|
export declare function isPrimitive(value: unknown): value is Primitive;
|
|
66
|
+
/**
|
|
67
|
+
* Is the value a typed array?
|
|
68
|
+
*/
|
|
66
69
|
export declare function isTypedArray(value: unknown): value is TypedArray;
|
|
67
70
|
|
|
68
71
|
export {};
|
package/types/is.d.ts
CHANGED
|
@@ -43,4 +43,7 @@ export declare function isPlainObject(value: unknown): value is PlainObject;
|
|
|
43
43
|
* Is the value a primitive value?
|
|
44
44
|
*/
|
|
45
45
|
export declare function isPrimitive(value: unknown): value is Primitive;
|
|
46
|
+
/**
|
|
47
|
+
* Is the value a typed array?
|
|
48
|
+
*/
|
|
46
49
|
export declare function isTypedArray(value: unknown): value is TypedArray;
|