seroval 0.11.1 → 0.11.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/cjs/development/index.cjs +118 -98
- package/dist/cjs/development/index.cjs.map +3 -3
- package/dist/cjs/production/index.cjs +3 -3
- package/dist/esm/development/index.mjs +118 -98
- package/dist/esm/development/index.mjs.map +3 -3
- package/dist/esm/production/index.mjs +3 -3
- package/dist/types/core/shared.d.ts +1 -1
- package/package.json +2 -2
- package/src/core/cross/async.ts +5 -5
- package/src/core/cross/primitives.ts +0 -8
- package/src/core/cross/stream.ts +60 -58
- package/src/core/cross/sync.ts +5 -5
- package/src/core/shared.ts +48 -19
- package/src/core/tree/async.ts +5 -5
- package/src/core/tree/sync.ts +5 -5
package/src/core/shared.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Feature } from './compat';
|
|
1
|
+
import { BIGINT_FLAG, Feature } from './compat';
|
|
2
2
|
import type {
|
|
3
3
|
ErrorValue,
|
|
4
4
|
} from '../types';
|
|
@@ -82,6 +82,7 @@ export function getErrorOptions(
|
|
|
82
82
|
}
|
|
83
83
|
|
|
84
84
|
export function isIterable(
|
|
85
|
+
ctx: BaseParserContext,
|
|
85
86
|
value: unknown,
|
|
86
87
|
): value is Iterable<unknown> {
|
|
87
88
|
if (!value || typeof value !== 'object') {
|
|
@@ -90,25 +91,53 @@ export function isIterable(
|
|
|
90
91
|
if (Array.isArray(value)) {
|
|
91
92
|
return false;
|
|
92
93
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
94
|
+
const currentClass = value.constructor;
|
|
95
|
+
if (ctx.features & Feature.TypedArray) {
|
|
96
|
+
switch (currentClass) {
|
|
97
|
+
case Int8Array:
|
|
98
|
+
case Int16Array:
|
|
99
|
+
case Int32Array:
|
|
100
|
+
case Uint8Array:
|
|
101
|
+
case Uint16Array:
|
|
102
|
+
case Uint32Array:
|
|
103
|
+
case Uint8ClampedArray:
|
|
104
|
+
case Float32Array:
|
|
105
|
+
case Float64Array:
|
|
106
|
+
return false;
|
|
107
|
+
default:
|
|
108
|
+
break;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
// BigInt Typed Arrays
|
|
112
|
+
if ((ctx.features & BIGINT_FLAG) === BIGINT_FLAG) {
|
|
113
|
+
switch (currentClass) {
|
|
114
|
+
case BigInt64Array:
|
|
115
|
+
case BigUint64Array:
|
|
116
|
+
return false;
|
|
117
|
+
default:
|
|
118
|
+
break;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
// ES Collection
|
|
122
|
+
if (ctx.features & Feature.Map && currentClass === Map) {
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
if (ctx.features & Feature.Set && currentClass === Set) {
|
|
126
|
+
return false;
|
|
127
|
+
}
|
|
128
|
+
if (ctx.features & Feature.WebAPI) {
|
|
129
|
+
switch (currentClass) {
|
|
130
|
+
case Headers:
|
|
131
|
+
case File:
|
|
132
|
+
return false;
|
|
133
|
+
default:
|
|
134
|
+
break;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
if (ctx.features & Feature.Symbol) {
|
|
138
|
+
return Symbol.iterator in value;
|
|
110
139
|
}
|
|
111
|
-
return
|
|
140
|
+
return false;
|
|
112
141
|
}
|
|
113
142
|
|
|
114
143
|
type TypedArrayConstructor =
|
package/src/core/tree/async.ts
CHANGED
|
@@ -96,7 +96,7 @@ async function generateNodeList(
|
|
|
96
96
|
for (let i = 0; i < size; i++) {
|
|
97
97
|
if (i in current) {
|
|
98
98
|
item = current[i];
|
|
99
|
-
if (isIterable(item)) {
|
|
99
|
+
if (isIterable(ctx, item)) {
|
|
100
100
|
deferred[i] = item;
|
|
101
101
|
} else {
|
|
102
102
|
nodes[i] = await parseAsync(ctx, item);
|
|
@@ -146,7 +146,7 @@ async function generateMapNode(
|
|
|
146
146
|
let nodeSize = 0;
|
|
147
147
|
for (const [key, value] of current.entries()) {
|
|
148
148
|
// Either key or value might be an iterable
|
|
149
|
-
if (isIterable(key) || isIterable(value)) {
|
|
149
|
+
if (isIterable(ctx, key) || isIterable(ctx, value)) {
|
|
150
150
|
deferredKey[deferredSize] = key;
|
|
151
151
|
deferredValue[deferredSize] = value;
|
|
152
152
|
deferredSize++;
|
|
@@ -188,7 +188,7 @@ async function generateSetNode(
|
|
|
188
188
|
let nodeSize = 0;
|
|
189
189
|
for (const item of current.keys()) {
|
|
190
190
|
// Iterables are lazy, so the evaluation must be deferred
|
|
191
|
-
if (isIterable(item)) {
|
|
191
|
+
if (isIterable(ctx, item)) {
|
|
192
192
|
deferred[deferredSize++] = item;
|
|
193
193
|
} else {
|
|
194
194
|
nodes[nodeSize++] = await parseAsync(ctx, item);
|
|
@@ -231,7 +231,7 @@ async function generateProperties(
|
|
|
231
231
|
for (const key of keys) {
|
|
232
232
|
item = properties[key];
|
|
233
233
|
escaped = serializeString(key);
|
|
234
|
-
if (isIterable(item)) {
|
|
234
|
+
if (isIterable(ctx, item)) {
|
|
235
235
|
deferredKeys[deferredSize] = escaped;
|
|
236
236
|
deferredValues[deferredSize] = item;
|
|
237
237
|
deferredSize++;
|
|
@@ -281,7 +281,7 @@ async function generatePlainProperties(
|
|
|
281
281
|
for (const key of keys) {
|
|
282
282
|
item = properties[key];
|
|
283
283
|
escaped = serializeString(key);
|
|
284
|
-
if (isIterable(item)) {
|
|
284
|
+
if (isIterable(ctx, item)) {
|
|
285
285
|
deferredKeys[deferredSize] = escaped;
|
|
286
286
|
deferredValues[deferredSize] = item;
|
|
287
287
|
deferredSize++;
|
package/src/core/tree/sync.ts
CHANGED
|
@@ -72,7 +72,7 @@ function generateNodeList(ctx: ParserContext, current: unknown[]): SerovalSyncNo
|
|
|
72
72
|
for (let i = 0; i < size; i++) {
|
|
73
73
|
if (i in current) {
|
|
74
74
|
item = current[i];
|
|
75
|
-
if (isIterable(item)) {
|
|
75
|
+
if (isIterable(ctx, item)) {
|
|
76
76
|
deferred[i] = item;
|
|
77
77
|
} else {
|
|
78
78
|
nodes[i] = parseSync(ctx, item);
|
|
@@ -122,7 +122,7 @@ function generateMapNode(
|
|
|
122
122
|
let nodeSize = 0;
|
|
123
123
|
for (const [key, value] of current.entries()) {
|
|
124
124
|
// Either key or value might be an iterable
|
|
125
|
-
if (isIterable(key) || isIterable(value)) {
|
|
125
|
+
if (isIterable(ctx, key) || isIterable(ctx, value)) {
|
|
126
126
|
deferredKey[deferredSize] = key;
|
|
127
127
|
deferredValue[deferredSize] = value;
|
|
128
128
|
deferredSize++;
|
|
@@ -164,7 +164,7 @@ function generateSetNode(
|
|
|
164
164
|
let nodeSize = 0;
|
|
165
165
|
for (const item of current.keys()) {
|
|
166
166
|
// Iterables are lazy, so the evaluation must be deferred
|
|
167
|
-
if (isIterable(item)) {
|
|
167
|
+
if (isIterable(ctx, item)) {
|
|
168
168
|
deferred[deferredSize++] = item;
|
|
169
169
|
} else {
|
|
170
170
|
nodes[nodeSize++] = parseSync(ctx, item);
|
|
@@ -207,7 +207,7 @@ function generateProperties(
|
|
|
207
207
|
for (const key of keys) {
|
|
208
208
|
item = properties[key];
|
|
209
209
|
escaped = serializeString(key);
|
|
210
|
-
if (isIterable(item)) {
|
|
210
|
+
if (isIterable(ctx, item)) {
|
|
211
211
|
deferredKeys[deferredSize] = escaped;
|
|
212
212
|
deferredValues[deferredSize] = item;
|
|
213
213
|
deferredSize++;
|
|
@@ -254,7 +254,7 @@ function generatePlainProperties(
|
|
|
254
254
|
for (const key of keys) {
|
|
255
255
|
item = properties[key];
|
|
256
256
|
escaped = serializeString(key);
|
|
257
|
-
if (isIterable(item)) {
|
|
257
|
+
if (isIterable(ctx, item)) {
|
|
258
258
|
deferredKeys[deferredSize] = escaped;
|
|
259
259
|
deferredValues[deferredSize] = item;
|
|
260
260
|
deferredSize++;
|