@nhtio/encoder 0.1.0-master-3b237666 → 0.1.0-master-f44af99f
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/{exceptions-CkrSQ6oY.mjs → exceptions-C8bYu-xi.mjs} +2 -2
- package/{exceptions-CkrSQ6oY.mjs.map → exceptions-C8bYu-xi.mjs.map} +1 -1
- package/{exceptions-DYhBvDYC.js → exceptions-DiuSuXH-.js} +2 -2
- package/{exceptions-DYhBvDYC.js.map → exceptions-DiuSuXH-.js.map} +1 -1
- package/exceptions.cjs +1 -1
- package/exceptions.mjs +1 -1
- package/function_serializer.cjs +1 -1
- package/function_serializer.mjs +1 -1
- package/index.cjs +52 -25
- package/index.cjs.map +1 -1
- package/index.mjs +52 -25
- package/index.mjs.map +1 -1
- package/package.json +1 -1
- package/{type_guards-Nh3b7rEF.js → type_guards-BWmHnIpZ.js} +23 -5
- package/{type_guards-Nh3b7rEF.js.map → type_guards-BWmHnIpZ.js.map} +1 -1
- package/{type_guards-BbzVmysZ.mjs → type_guards-UkDoe__i.mjs} +29 -11
- package/{type_guards-BbzVmysZ.mjs.map → type_guards-UkDoe__i.mjs.map} +1 -1
- package/type_guards.cjs +1 -1
- package/type_guards.mjs +5 -5
package/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { i as isObject, a as isArray, b as isSet, c as isMap, d as isLuxonSystemZone, e as isLuxonInterval, f as isLuxonDuration, g as isLuxonDateTime, D as DateTime, h as isPhoneObject, j as isTypedArray, k as isBigIntTypedArray, l as isPrimitive, m as isUniterableObject, n as isError, o as isBigInt, p as isNegativeZero, I as Info,
|
|
1
|
+
import { i as isObject, a as isArray, b as isSet, c as isMap, d as isLuxonSystemZone, e as isLuxonInterval, f as isLuxonDuration, g as isLuxonDateTime, D as DateTime, h as isPhoneObject, j as isTypedArray, k as isBigIntTypedArray, l as isPrimitive, m as isUniterableObject, n as isError, o as isBigInt, p as isUnsafeInteger, q as isNegativeInfinity, r as isPositiveInfinity, s as isNegativeZero, I as Info, t as Interval, u as Duration, P as Phone } from "./type_guards-UkDoe__i.mjs";
|
|
2
2
|
import { FunctionSerializer } from "./function_serializer.mjs";
|
|
3
|
-
import { E as E_UNENCODABLE_VALUE, a as E_CIRCULAR_REFERENCE, b as E_ENCODING_FAILED, B as BaseException, c as E_UNDECODABLE_VALUE, d as E_NOT_AN_ENCODED_VALUE, e as E_INVALID_VERSION, f as E_INCOMPATIBLE_VERSION } from "./exceptions-
|
|
3
|
+
import { E as E_UNENCODABLE_VALUE, a as E_CIRCULAR_REFERENCE, b as E_ENCODING_FAILED, B as BaseException, c as E_UNDECODABLE_VALUE, d as E_NOT_AN_ENCODED_VALUE, e as E_INVALID_VERSION, f as E_INCOMPATIBLE_VERSION } from "./exceptions-C8bYu-xi.mjs";
|
|
4
4
|
var re = { exports: {} };
|
|
5
5
|
var constants;
|
|
6
6
|
var hasRequiredConstants;
|
|
@@ -2944,6 +2944,30 @@ const toStructuredData = (value, seen = /* @__PURE__ */ new WeakSet()) => {
|
|
|
2944
2944
|
_s: ""
|
|
2945
2945
|
};
|
|
2946
2946
|
}
|
|
2947
|
+
case isPositiveInfinity(value): {
|
|
2948
|
+
return {
|
|
2949
|
+
_t: "js:∞",
|
|
2950
|
+
_s: ""
|
|
2951
|
+
};
|
|
2952
|
+
}
|
|
2953
|
+
case isNegativeInfinity(value): {
|
|
2954
|
+
return {
|
|
2955
|
+
_t: "js:-∞",
|
|
2956
|
+
_s: ""
|
|
2957
|
+
};
|
|
2958
|
+
}
|
|
2959
|
+
case isUnsafeInteger(value): {
|
|
2960
|
+
return {
|
|
2961
|
+
_t: "js:unsafeInteger",
|
|
2962
|
+
_s: value.toString()
|
|
2963
|
+
};
|
|
2964
|
+
}
|
|
2965
|
+
case Number.isNaN(value): {
|
|
2966
|
+
return {
|
|
2967
|
+
_t: "js:NaN",
|
|
2968
|
+
_s: ""
|
|
2969
|
+
};
|
|
2970
|
+
}
|
|
2947
2971
|
case isBigInt(value): {
|
|
2948
2972
|
return {
|
|
2949
2973
|
_t: "js:bigint",
|
|
@@ -2965,24 +2989,15 @@ const toStructuredData = (value, seen = /* @__PURE__ */ new WeakSet()) => {
|
|
|
2965
2989
|
throw new E_ENCODING_FAILED(value, e);
|
|
2966
2990
|
}
|
|
2967
2991
|
}
|
|
2968
|
-
case isBigIntTypedArray(value):
|
|
2969
|
-
try {
|
|
2970
|
-
return {
|
|
2971
|
-
_t: `js:bigintTypedArray`,
|
|
2972
|
-
_s: toStructuredData(serialize(value, { lossy: true, json: true }), seen)
|
|
2973
|
-
};
|
|
2974
|
-
} catch (e) {
|
|
2975
|
-
if (e instanceof BaseException) {
|
|
2976
|
-
throw e;
|
|
2977
|
-
}
|
|
2978
|
-
throw new E_ENCODING_FAILED(value, e);
|
|
2979
|
-
}
|
|
2980
|
-
}
|
|
2992
|
+
case isBigIntTypedArray(value):
|
|
2981
2993
|
case isTypedArray(value): {
|
|
2982
2994
|
try {
|
|
2983
2995
|
return {
|
|
2984
|
-
_t: `js:
|
|
2985
|
-
_s:
|
|
2996
|
+
_t: `js:typedArray`,
|
|
2997
|
+
_s: toStructuredData({
|
|
2998
|
+
ctor: value.constructor.name,
|
|
2999
|
+
values: Array.from(value).map((v) => toStructuredData(v))
|
|
3000
|
+
})
|
|
2986
3001
|
};
|
|
2987
3002
|
} catch (e) {
|
|
2988
3003
|
if (e instanceof BaseException) {
|
|
@@ -3118,7 +3133,7 @@ const toStructuredData = (value, seen = /* @__PURE__ */ new WeakSet()) => {
|
|
|
3118
3133
|
seen.add(value);
|
|
3119
3134
|
return {
|
|
3120
3135
|
_t: "js:Array",
|
|
3121
|
-
_s:
|
|
3136
|
+
_s: utoa(JSON.stringify(value.map((item) => toStructuredData(item, seen))))
|
|
3122
3137
|
};
|
|
3123
3138
|
}
|
|
3124
3139
|
case isObject(value): {
|
|
@@ -3178,15 +3193,27 @@ const fromStructuredData = (data) => {
|
|
|
3178
3193
|
});
|
|
3179
3194
|
return set;
|
|
3180
3195
|
}
|
|
3196
|
+
case "js:NaN": {
|
|
3197
|
+
return Number.NaN;
|
|
3198
|
+
}
|
|
3199
|
+
case "js:unsafeInteger": {
|
|
3200
|
+
return Number(data._s);
|
|
3201
|
+
}
|
|
3202
|
+
case "js:-∞": {
|
|
3203
|
+
return Number.NEGATIVE_INFINITY;
|
|
3204
|
+
}
|
|
3205
|
+
case "js:∞": {
|
|
3206
|
+
return Number.POSITIVE_INFINITY;
|
|
3207
|
+
}
|
|
3181
3208
|
case "js:negativeZero": {
|
|
3182
3209
|
return -0;
|
|
3183
3210
|
}
|
|
3184
3211
|
case "js:bigint": {
|
|
3185
3212
|
return BigInt(data._s);
|
|
3186
3213
|
}
|
|
3187
|
-
case "js:
|
|
3188
|
-
const
|
|
3189
|
-
return
|
|
3214
|
+
case "js:typedArray": {
|
|
3215
|
+
const { ctor, values } = fromStructuredData(data._s);
|
|
3216
|
+
return new globalThis[ctor](values.map(fromStructuredData));
|
|
3190
3217
|
}
|
|
3191
3218
|
case "js:native": {
|
|
3192
3219
|
return deserialize(data._s);
|
|
@@ -3240,11 +3267,11 @@ const { parse: $parse, stringify: $stringify } = JSON;
|
|
|
3240
3267
|
const options = { json: true, lossy: true };
|
|
3241
3268
|
const parse = (str) => deserialize($parse(str));
|
|
3242
3269
|
const stringify = (any) => $stringify(serialize(any, options));
|
|
3243
|
-
const version = "0.1.0-master-
|
|
3270
|
+
const version = "0.1.0-master-f44af99f";
|
|
3244
3271
|
const encode = (what) => {
|
|
3245
3272
|
const structured = toStructuredData(what);
|
|
3246
3273
|
const serialized = serialize(structured, { lossy: true, json: true });
|
|
3247
|
-
const json = stringify({ version: "0.1.0-master-
|
|
3274
|
+
const json = stringify({ version: "0.1.0-master-f44af99f", serialized });
|
|
3248
3275
|
return utoa(json);
|
|
3249
3276
|
};
|
|
3250
3277
|
const decode = (base64) => {
|
|
@@ -3255,11 +3282,11 @@ const decode = (base64) => {
|
|
|
3255
3282
|
throw new E_NOT_AN_ENCODED_VALUE(base64);
|
|
3256
3283
|
}
|
|
3257
3284
|
const { version: payloadVersion, serialized } = parsed;
|
|
3258
|
-
if (semverExports.valid("0.1.0-master-
|
|
3285
|
+
if (semverExports.valid("0.1.0-master-f44af99f")) {
|
|
3259
3286
|
if (!semverExports.valid(semverExports.coerce(payloadVersion))) {
|
|
3260
3287
|
throw new E_INVALID_VERSION(payloadVersion);
|
|
3261
3288
|
}
|
|
3262
|
-
if (semverExports.gt(semverExports.coerce(payloadVersion), "0.1.0-master-
|
|
3289
|
+
if (semverExports.gt(semverExports.coerce(payloadVersion), "0.1.0-master-f44af99f")) {
|
|
3263
3290
|
throw new E_INCOMPATIBLE_VERSION(payloadVersion);
|
|
3264
3291
|
}
|
|
3265
3292
|
}
|