@nhtio/encoder 0.1.0-master-1c669c73 → 0.1.0-master-a0341ac6
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-CHEKApsb.mjs → exceptions-D4huZrDN.mjs} +2 -2
- package/{exceptions-CHEKApsb.mjs.map → exceptions-D4huZrDN.mjs.map} +1 -1
- package/{exceptions-DWZQlMyh.js → exceptions-X2-2FICz.js} +2 -2
- package/{exceptions-DWZQlMyh.js.map → exceptions-X2-2FICz.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 +54 -18
- package/index.cjs.map +1 -1
- package/index.mjs +54 -18
- package/index.mjs.map +1 -1
- package/package.json +1 -1
- package/{type_guards-DLvYdK9d.js → type_guards-D1YzZ13G.js} +4 -7
- package/{type_guards-DLvYdK9d.js.map → type_guards-D1YzZ13G.js.map} +1 -1
- package/{type_guards-zVeNM-tg.mjs → type_guards-DMqlMT2e.mjs} +21 -24
- package/{type_guards-zVeNM-tg.mjs.map → type_guards-DMqlMT2e.mjs.map} +1 -1
- package/type_guards.cjs +1 -1
- package/type_guards.mjs +10 -10
package/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { i as isObject, a as isCustomEncodable, E as ENCODE_METHOD, b as isArray, c as isSet, d as isMap, e as isLuxonSystemZone, f as isLuxonInterval, g as isLuxonDuration, h as
|
|
1
|
+
import { i as isObject, a as isCustomEncodable, E as ENCODE_METHOD, b as isArray, c as isSet, d as isMap, e as isLuxonSystemZone, f as isLuxonInterval, I as Interval, D as DateTime, g as isLuxonDuration, h as Duration, j as isLuxonDateTime, k as isPhoneObject, l as isTypedArray, m as isBigIntTypedArray, n as isPrimitive, o as isUniterableObject, p as isError, q as isBigInt, r as isUnsafeInteger, s as isNegativeInfinity, t as isPositiveInfinity, u as isNegativeZero, v as DECODE_METHOD, w as Info, P as Phone } from "./type_guards-DMqlMT2e.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-D4huZrDN.mjs";
|
|
4
4
|
var re = { exports: {} };
|
|
5
5
|
var constants;
|
|
6
6
|
var hasRequiredConstants;
|
|
@@ -2946,6 +2946,13 @@ const serialize = (value, { json, lossy } = {}) => {
|
|
|
2946
2946
|
const stripUndefinedValuesFromObject = (obj) => {
|
|
2947
2947
|
return Object.fromEntries(Object.entries(obj).filter(([_, value]) => value !== void 0));
|
|
2948
2948
|
};
|
|
2949
|
+
const fixedOffsetToZoneName = (fixed) => {
|
|
2950
|
+
const sign = fixed >= 0 ? "+" : "-";
|
|
2951
|
+
const abs = Math.abs(fixed);
|
|
2952
|
+
const hours = Math.floor(abs / 60);
|
|
2953
|
+
const minutes = abs % 60;
|
|
2954
|
+
return minutes === 0 ? `UTC${sign}${hours}` : `UTC${sign}${hours}:${String(minutes).padStart(2, "0")}`;
|
|
2955
|
+
};
|
|
2949
2956
|
const toStructuredData = (value, seen = /* @__PURE__ */ new WeakSet()) => {
|
|
2950
2957
|
switch (true) {
|
|
2951
2958
|
case isNegativeZero(value): {
|
|
@@ -3035,7 +3042,19 @@ const toStructuredData = (value, seen = /* @__PURE__ */ new WeakSet()) => {
|
|
|
3035
3042
|
throw new E_CIRCULAR_REFERENCE();
|
|
3036
3043
|
}
|
|
3037
3044
|
seen.add(value);
|
|
3038
|
-
const dto = value
|
|
3045
|
+
const dto = value instanceof DateTime ? value : typeof value.toMillis === "function" ? value : (() => {
|
|
3046
|
+
const raw = value;
|
|
3047
|
+
const zone = raw._zone && typeof raw._zone.zoneName === "string" ? raw._zone.zoneName : raw._zone && typeof raw._zone.fixed === "number" ? fixedOffsetToZoneName(raw._zone.fixed) : void 0;
|
|
3048
|
+
const locale = raw.loc && typeof raw.loc.locale === "string" ? raw.loc.locale : void 0;
|
|
3049
|
+
const outputCalendar = raw.loc && typeof raw.loc.outputCalendar === "string" ? raw.loc.outputCalendar : void 0;
|
|
3050
|
+
const numberingSystem = raw.loc && typeof raw.loc.numberingSystem === "string" ? raw.loc.numberingSystem : void 0;
|
|
3051
|
+
return DateTime.fromMillis(typeof raw.ts === "number" ? raw.ts : 0, {
|
|
3052
|
+
zone,
|
|
3053
|
+
locale,
|
|
3054
|
+
outputCalendar,
|
|
3055
|
+
numberingSystem
|
|
3056
|
+
});
|
|
3057
|
+
})();
|
|
3039
3058
|
return {
|
|
3040
3059
|
_t: "luxon:DateTime",
|
|
3041
3060
|
_s: toStructuredData(
|
|
@@ -3055,16 +3074,24 @@ const toStructuredData = (value, seen = /* @__PURE__ */ new WeakSet()) => {
|
|
|
3055
3074
|
throw new E_CIRCULAR_REFERENCE();
|
|
3056
3075
|
}
|
|
3057
3076
|
seen.add(value);
|
|
3077
|
+
const dur = value instanceof Duration ? value : typeof value.get === "function" ? value : (() => {
|
|
3078
|
+
const raw = value;
|
|
3079
|
+
const locale = raw.loc && typeof raw.loc.locale === "string" ? raw.loc.locale : void 0;
|
|
3080
|
+
return Duration.fromObject(
|
|
3081
|
+
raw.values && typeof raw.values === "object" ? raw.values : {},
|
|
3082
|
+
{ locale }
|
|
3083
|
+
);
|
|
3084
|
+
})();
|
|
3058
3085
|
const dto = {
|
|
3059
|
-
years:
|
|
3060
|
-
quarters:
|
|
3061
|
-
months:
|
|
3062
|
-
weeks:
|
|
3063
|
-
days:
|
|
3064
|
-
hours:
|
|
3065
|
-
minutes:
|
|
3066
|
-
seconds:
|
|
3067
|
-
milliseconds:
|
|
3086
|
+
years: dur.years,
|
|
3087
|
+
quarters: dur.quarters,
|
|
3088
|
+
months: dur.months,
|
|
3089
|
+
weeks: dur.weeks,
|
|
3090
|
+
days: dur.days,
|
|
3091
|
+
hours: dur.hours,
|
|
3092
|
+
minutes: dur.minutes,
|
|
3093
|
+
seconds: dur.seconds,
|
|
3094
|
+
milliseconds: dur.milliseconds
|
|
3068
3095
|
};
|
|
3069
3096
|
Object.entries(dto).forEach(([key, val]) => {
|
|
3070
3097
|
if (Number.isNaN(val) || val === 0) {
|
|
@@ -3081,8 +3108,17 @@ const toStructuredData = (value, seen = /* @__PURE__ */ new WeakSet()) => {
|
|
|
3081
3108
|
throw new E_CIRCULAR_REFERENCE();
|
|
3082
3109
|
}
|
|
3083
3110
|
seen.add(value);
|
|
3084
|
-
const
|
|
3085
|
-
|
|
3111
|
+
const iv = value instanceof Interval ? value : typeof value.toISO === "function" ? value : (() => {
|
|
3112
|
+
const raw = value;
|
|
3113
|
+
const startMs = raw.s && typeof raw.s.ts === "number" ? raw.s.ts : null;
|
|
3114
|
+
const endMs = raw.e && typeof raw.e.ts === "number" ? raw.e.ts : null;
|
|
3115
|
+
return Interval.fromDateTimes(
|
|
3116
|
+
startMs !== null ? DateTime.fromMillis(startMs) : DateTime.invalid("missing start"),
|
|
3117
|
+
endMs !== null ? DateTime.fromMillis(endMs) : DateTime.invalid("missing end")
|
|
3118
|
+
);
|
|
3119
|
+
})();
|
|
3120
|
+
const start = iv.start ? iv.start.toISO({ extendedZone: true }) : null;
|
|
3121
|
+
const end = iv.end ? iv.end.toISO({ extendedZone: true }) : null;
|
|
3086
3122
|
if (!start || !end) {
|
|
3087
3123
|
throw new E_UNENCODABLE_VALUE(value);
|
|
3088
3124
|
}
|
|
@@ -3322,11 +3358,11 @@ const { parse: $parse, stringify: $stringify } = JSON;
|
|
|
3322
3358
|
const options = { json: true, lossy: true };
|
|
3323
3359
|
const parse = (str) => deserialize($parse(str));
|
|
3324
3360
|
const stringify = (any) => $stringify(serialize(any, options));
|
|
3325
|
-
const version = "0.1.0-master-
|
|
3361
|
+
const version = "0.1.0-master-a0341ac6";
|
|
3326
3362
|
const encode = (what) => {
|
|
3327
3363
|
const structured = toStructuredData(what);
|
|
3328
3364
|
const serialized = serialize(structured, { lossy: true, json: true });
|
|
3329
|
-
const json = stringify({ version: "0.1.0-master-
|
|
3365
|
+
const json = stringify({ version: "0.1.0-master-a0341ac6", serialized });
|
|
3330
3366
|
return utoa(json);
|
|
3331
3367
|
};
|
|
3332
3368
|
const decode = (base64) => {
|
|
@@ -3337,11 +3373,11 @@ const decode = (base64) => {
|
|
|
3337
3373
|
throw new E_NOT_AN_ENCODED_VALUE(base64);
|
|
3338
3374
|
}
|
|
3339
3375
|
const { version: payloadVersion, serialized } = parsed;
|
|
3340
|
-
if (semverExports.valid("0.1.0-master-
|
|
3376
|
+
if (semverExports.valid("0.1.0-master-a0341ac6")) {
|
|
3341
3377
|
if (!semverExports.valid(semverExports.coerce(payloadVersion))) {
|
|
3342
3378
|
throw new E_INVALID_VERSION(payloadVersion);
|
|
3343
3379
|
}
|
|
3344
|
-
if (semverExports.gt(semverExports.coerce(payloadVersion), "0.1.0-master-
|
|
3380
|
+
if (semverExports.gt(semverExports.coerce(payloadVersion), "0.1.0-master-a0341ac6")) {
|
|
3345
3381
|
throw new E_INCOMPATIBLE_VERSION(payloadVersion);
|
|
3346
3382
|
}
|
|
3347
3383
|
}
|