@nhtio/encoder 0.1.0-master-1c669c73 → 0.1.0-master-b66a109d
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-DWZQlMyh.js → exceptions-CuUgGvwb.js} +2 -2
- package/{exceptions-DWZQlMyh.js.map → exceptions-CuUgGvwb.js.map} +1 -1
- package/{exceptions-CHEKApsb.mjs → exceptions-hG10RUaJ.mjs} +2 -2
- package/{exceptions-CHEKApsb.mjs.map → exceptions-hG10RUaJ.mjs.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 +57 -18
- package/index.cjs.map +1 -1
- package/index.mjs +57 -18
- package/index.mjs.map +1 -1
- package/package.json +6 -6
- 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-hG10RUaJ.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,27 @@ 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
|
+
const rawValues = raw.values && typeof raw.values === "object" ? raw.values : {};
|
|
3081
|
+
const values = Object.fromEntries(
|
|
3082
|
+
Object.entries(rawValues).filter(
|
|
3083
|
+
([, val]) => typeof val === "number" && Number.isFinite(val)
|
|
3084
|
+
)
|
|
3085
|
+
);
|
|
3086
|
+
return Duration.fromObject(values, { locale });
|
|
3087
|
+
})();
|
|
3058
3088
|
const dto = {
|
|
3059
|
-
years:
|
|
3060
|
-
quarters:
|
|
3061
|
-
months:
|
|
3062
|
-
weeks:
|
|
3063
|
-
days:
|
|
3064
|
-
hours:
|
|
3065
|
-
minutes:
|
|
3066
|
-
seconds:
|
|
3067
|
-
milliseconds:
|
|
3089
|
+
years: dur.years,
|
|
3090
|
+
quarters: dur.quarters,
|
|
3091
|
+
months: dur.months,
|
|
3092
|
+
weeks: dur.weeks,
|
|
3093
|
+
days: dur.days,
|
|
3094
|
+
hours: dur.hours,
|
|
3095
|
+
minutes: dur.minutes,
|
|
3096
|
+
seconds: dur.seconds,
|
|
3097
|
+
milliseconds: dur.milliseconds
|
|
3068
3098
|
};
|
|
3069
3099
|
Object.entries(dto).forEach(([key, val]) => {
|
|
3070
3100
|
if (Number.isNaN(val) || val === 0) {
|
|
@@ -3081,8 +3111,17 @@ const toStructuredData = (value, seen = /* @__PURE__ */ new WeakSet()) => {
|
|
|
3081
3111
|
throw new E_CIRCULAR_REFERENCE();
|
|
3082
3112
|
}
|
|
3083
3113
|
seen.add(value);
|
|
3084
|
-
const
|
|
3085
|
-
|
|
3114
|
+
const iv = value instanceof Interval ? value : typeof value.toISO === "function" ? value : (() => {
|
|
3115
|
+
const raw = value;
|
|
3116
|
+
const startMs = raw.s && typeof raw.s.ts === "number" ? raw.s.ts : null;
|
|
3117
|
+
const endMs = raw.e && typeof raw.e.ts === "number" ? raw.e.ts : null;
|
|
3118
|
+
return Interval.fromDateTimes(
|
|
3119
|
+
startMs !== null ? DateTime.fromMillis(startMs) : DateTime.invalid("missing start"),
|
|
3120
|
+
endMs !== null ? DateTime.fromMillis(endMs) : DateTime.invalid("missing end")
|
|
3121
|
+
);
|
|
3122
|
+
})();
|
|
3123
|
+
const start = iv.start ? iv.start.toISO({ extendedZone: true }) : null;
|
|
3124
|
+
const end = iv.end ? iv.end.toISO({ extendedZone: true }) : null;
|
|
3086
3125
|
if (!start || !end) {
|
|
3087
3126
|
throw new E_UNENCODABLE_VALUE(value);
|
|
3088
3127
|
}
|
|
@@ -3322,11 +3361,11 @@ const { parse: $parse, stringify: $stringify } = JSON;
|
|
|
3322
3361
|
const options = { json: true, lossy: true };
|
|
3323
3362
|
const parse = (str) => deserialize($parse(str));
|
|
3324
3363
|
const stringify = (any) => $stringify(serialize(any, options));
|
|
3325
|
-
const version = "0.1.0-master-
|
|
3364
|
+
const version = "0.1.0-master-b66a109d";
|
|
3326
3365
|
const encode = (what) => {
|
|
3327
3366
|
const structured = toStructuredData(what);
|
|
3328
3367
|
const serialized = serialize(structured, { lossy: true, json: true });
|
|
3329
|
-
const json = stringify({ version: "0.1.0-master-
|
|
3368
|
+
const json = stringify({ version: "0.1.0-master-b66a109d", serialized });
|
|
3330
3369
|
return utoa(json);
|
|
3331
3370
|
};
|
|
3332
3371
|
const decode = (base64) => {
|
|
@@ -3337,11 +3376,11 @@ const decode = (base64) => {
|
|
|
3337
3376
|
throw new E_NOT_AN_ENCODED_VALUE(base64);
|
|
3338
3377
|
}
|
|
3339
3378
|
const { version: payloadVersion, serialized } = parsed;
|
|
3340
|
-
if (semverExports.valid("0.1.0-master-
|
|
3379
|
+
if (semverExports.valid("0.1.0-master-b66a109d")) {
|
|
3341
3380
|
if (!semverExports.valid(semverExports.coerce(payloadVersion))) {
|
|
3342
3381
|
throw new E_INVALID_VERSION(payloadVersion);
|
|
3343
3382
|
}
|
|
3344
|
-
if (semverExports.gt(semverExports.coerce(payloadVersion), "0.1.0-master-
|
|
3383
|
+
if (semverExports.gt(semverExports.coerce(payloadVersion), "0.1.0-master-b66a109d")) {
|
|
3345
3384
|
throw new E_INCOMPATIBLE_VERSION(payloadVersion);
|
|
3346
3385
|
}
|
|
3347
3386
|
}
|