@nhtio/encoder 1.20260611.0 → 1.20260624.1

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/type_guards.cjs CHANGED
@@ -1,9 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const type_guards = require("./type_guards-BWmHnIpZ.js");
3
+ const type_guards = require("./type_guards-D1YzZ13G.js");
4
4
  exports.isArray = type_guards.isArray;
5
5
  exports.isBigInt = type_guards.isBigInt;
6
6
  exports.isBigIntTypedArray = type_guards.isBigIntTypedArray;
7
+ exports.isCustomEncodable = type_guards.isCustomEncodable;
7
8
  exports.isError = type_guards.isError;
8
9
  exports.isInstanceOf = type_guards.isInstanceOf;
9
10
  exports.isLucidBinaryValue = type_guards.isLucidBinaryValue;
@@ -1 +1 @@
1
- {"version":3,"file":"type_guards.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"type_guards.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;"}
package/type_guards.d.ts CHANGED
@@ -36,6 +36,17 @@ declare type CountryOrUnknown = Country | 'XX';
36
36
  */
37
37
  declare type CountryTimezone = 'Europe/Andorra' | 'Asia/Dubai' | 'Asia/Kabul' | 'America/Antigua' | 'America/Anguilla' | 'Europe/Tirane' | 'Asia/Yerevan' | 'Africa/Luanda' | 'Antarctica/Casey' | 'America/Argentina/Buenos_Aires' | 'Pacific/Pago_Pago' | 'Europe/Vienna' | 'Australia/Sydney' | 'America/Aruba' | 'Europe/Mariehamn' | 'Asia/Baku' | 'Europe/Sarajevo' | 'America/Barbados' | 'Asia/Dhaka' | 'Europe/Brussels' | 'Africa/Ouagadougou' | 'Europe/Sofia' | 'Asia/Bahrain' | 'Africa/Bujumbura' | 'Africa/Porto-Novo' | 'America/St_Barthelemy' | 'Atlantic/Bermuda' | 'Asia/Brunei' | 'America/La_Paz' | 'America/Kralendijk' | 'America/Sao_Paulo' | 'America/Nassau' | 'Asia/Thimphu' | 'Africa/Gaborone' | 'Europe/Minsk' | 'America/Belize' | 'America/Toronto' | 'Indian/Cocos' | 'Africa/Kinshasa' | 'Africa/Bangui' | 'Africa/Brazzaville' | 'Europe/Zurich' | 'Africa/Abidjan' | 'Pacific/Rarotonga' | 'America/Santiago' | 'Africa/Douala' | 'Asia/Shanghai' | 'America/Bogota' | 'America/Costa_Rica' | 'America/Havana' | 'Atlantic/Cape_Verde' | 'America/Curacao' | 'Indian/Christmas' | 'Asia/Nicosia' | 'Europe/Prague' | 'Europe/Berlin' | 'Africa/Djibouti' | 'Europe/Copenhagen' | 'America/Dominica' | 'America/Santo_Domingo' | 'Africa/Algiers' | 'America/Guayaquil' | 'Europe/Tallinn' | 'Africa/Cairo' | 'Africa/El_Aaiun' | 'Africa/Asmara' | 'Europe/Madrid' | 'Africa/Addis_Ababa' | 'Europe/Helsinki' | 'Pacific/Fiji' | 'Atlantic/Stanley' | 'Pacific/Pohnpei' | 'Atlantic/Faroe' | 'Europe/Paris' | 'Africa/Libreville' | 'Europe/London' | 'America/Grenada' | 'Asia/Tbilisi' | 'America/Cayenne' | 'Europe/Guernsey' | 'Africa/Accra' | 'Europe/Gibraltar' | 'America/Godthab' | 'Africa/Banjul' | 'Africa/Conakry' | 'America/Guadeloupe' | 'Africa/Malabo' | 'Europe/Athens' | 'Atlantic/South_Georgia' | 'America/Guatemala' | 'Pacific/Guam' | 'Africa/Bissau' | 'America/Guyana' | 'Asia/Hong_Kong' | 'America/Tegucigalpa' | 'Europe/Zagreb' | 'America/Port-au-Prince' | 'Europe/Budapest' | 'Asia/Jakarta' | 'Europe/Dublin' | 'Asia/Jerusalem' | 'Europe/Isle_of_Man' | 'Asia/Kolkata' | 'Indian/Chagos' | 'Asia/Baghdad' | 'Asia/Tehran' | 'Atlantic/Reykjavik' | 'Europe/Rome' | 'Europe/Jersey' | 'America/Jamaica' | 'Asia/Amman' | 'Asia/Tokyo' | 'Africa/Nairobi' | 'Asia/Bishkek' | 'Asia/Phnom_Penh' | 'Pacific/Tarawa' | 'Indian/Comoro' | 'America/St_Kitts' | 'Asia/Pyongyang' | 'Asia/Seoul' | 'Asia/Kuwait' | 'America/Cayman' | 'Asia/Almaty' | 'Asia/Vientiane' | 'Asia/Beirut' | 'America/St_Lucia' | 'Europe/Vaduz' | 'Asia/Colombo' | 'Africa/Monrovia' | 'Africa/Maseru' | 'Europe/Vilnius' | 'Europe/Luxembourg' | 'Europe/Riga' | 'Africa/Tripoli' | 'Africa/Casablanca' | 'Europe/Monaco' | 'Europe/Chisinau' | 'Europe/Podgorica' | 'America/Marigot' | 'Indian/Antananarivo' | 'Pacific/Majuro' | 'Europe/Skopje' | 'Africa/Bamako' | 'Asia/Yangon' | 'Asia/Ulaanbaatar' | 'Asia/Macau' | 'Pacific/Saipan' | 'America/Martinique' | 'Africa/Nouakchott' | 'America/Montserrat' | 'Europe/Malta' | 'Indian/Mauritius' | 'Indian/Maldives' | 'Africa/Blantyre' | 'America/Mexico_City' | 'Asia/Kuala_Lumpur' | 'Africa/Maputo' | 'Africa/Windhoek' | 'Pacific/Noumea' | 'Africa/Niamey' | 'Pacific/Norfolk' | 'Africa/Lagos' | 'America/Managua' | 'Europe/Amsterdam' | 'Europe/Oslo' | 'Asia/Kathmandu' | 'Pacific/Nauru' | 'Pacific/Niue' | 'Pacific/Auckland' | 'Asia/Muscat' | 'America/Panama' | 'America/Lima' | 'Pacific/Tahiti' | 'Pacific/Port_Moresby' | 'Asia/Manila' | 'Asia/Karachi' | 'Europe/Warsaw' | 'America/Miquelon' | 'Pacific/Pitcairn' | 'America/Puerto_Rico' | 'Asia/Gaza' | 'Europe/Lisbon' | 'Pacific/Palau' | 'America/Asuncion' | 'Asia/Qatar' | 'Indian/Reunion' | 'Europe/Bucharest' | 'Europe/Belgrade' | 'Europe/Moscow' | 'Africa/Kigali' | 'Asia/Riyadh' | 'Pacific/Guadalcanal' | 'Indian/Mahe' | 'Africa/Khartoum' | 'Europe/Stockholm' | 'Asia/Singapore' | 'Atlantic/St_Helena' | 'Europe/Ljubljana' | 'Arctic/Longyearbyen' | 'Europe/Bratislava' | 'Africa/Freetown' | 'Europe/San_Marino' | 'Africa/Dakar' | 'Africa/Mogadishu' | 'America/Paramaribo' | 'Africa/Juba' | 'Africa/Sao_Tome' | 'America/El_Salvador' | 'America/Lower_Princes' | 'Asia/Damascus' | 'Africa/Mbabane' | 'America/Grand_Turk' | 'Africa/Ndjamena' | 'Indian/Kerguelen' | 'Africa/Lome' | 'Asia/Bangkok' | 'Asia/Dushanbe' | 'Pacific/Fakaofo' | 'Asia/Dili' | 'Asia/Ashgabat' | 'Africa/Tunis' | 'Pacific/Tongatapu' | 'Europe/Istanbul' | 'America/Port_of_Spain' | 'Pacific/Funafuti' | 'Asia/Taipei' | 'Africa/Dar_es_Salaam' | 'Europe/Kiev' | 'Africa/Kampala' | 'Pacific/Wake' | 'America/New_York' | 'America/Montevideo' | 'Asia/Tashkent' | 'Europe/Vatican' | 'America/St_Vincent' | 'America/Caracas' | 'America/Tortola' | 'America/St_Thomas' | 'Asia/Ho_Chi_Minh' | 'Pacific/Efate' | 'Pacific/Wallis' | 'Pacific/Apia' | 'Asia/Aden' | 'Indian/Mayotte' | 'Africa/Johannesburg' | 'Africa/Lusaka' | 'Africa/Harare';
38
38
 
39
+ /**
40
+ * A class that opts in to custom encoding/decoding.
41
+ *
42
+ * Implement `[ENCODE_METHOD]()` on instances to produce an Encodable snapshot,
43
+ * and `static [DECODE_METHOD](data)` to reconstruct the instance.
44
+ * Pass the class to `registerClass()` so the decoder can find it.
45
+ */
46
+ declare interface CustomEncodable {
47
+ [ENCODE_METHOD](): Encodable;
48
+ }
49
+
39
50
  declare type DateInput = DateTime | DateObjectUnits | Date;
40
51
 
41
52
  /**
@@ -1974,6 +1985,32 @@ declare type DurationUnit = keyof DurationLikeObject;
1974
1985
 
1975
1986
  declare type DurationUnits = DurationUnit | DurationUnit[];
1976
1987
 
1988
+ /**
1989
+ * Defines all the types which can be be encoded
1990
+ * @see {@link @nhtio/encoder!EncodablePrimitive | EncodablePrimitive}
1991
+ * @see {@link @nhtio/encoder!EncodableTypedArray | EncodableTypedArray}
1992
+ * @see {@link DateTime | DateTime}
1993
+ * @see {@link Duration | Duration}
1994
+ * @see {@link Interval | Interval}
1995
+ * @see {@link PhoneModel | PhoneModel}
1996
+ */
1997
+ declare type Encodable = EncodablePrimitive | Date | RegExp | ArrayBuffer | DataView | DateTime | Duration | Interval | EncodableTypedArray | Encodable[] | {
1998
+ [key: string]: Encodable;
1999
+ } | Map<Encodable, Encodable> | Set<Encodable> | Error | EvalError | RangeError | ReferenceError | SyntaxError | TypeError | URIError | PhoneModel | Function | ((...args: any[]) => any) | CustomEncodable;
2000
+
2001
+ /**
2002
+ * Defines the union of all encodable primitive types.
2003
+ */
2004
+ declare type EncodablePrimitive = string | number | boolean | bigint | null | undefined;
2005
+
2006
+ /**
2007
+ * Defines a union for all the encodable typed arrays.
2008
+ */
2009
+ declare type EncodableTypedArray = Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array | BigInt64Array | BigUint64Array;
2010
+
2011
+ /** Instance method: serialize the object into an Encodable snapshot */
2012
+ declare const ENCODE_METHOD: unique symbol;
2013
+
1977
2014
  declare type EndOfOptions = _UseLocaleWeekOption;
1978
2015
 
1979
2016
  declare interface ExplainedFormat {
@@ -2382,6 +2419,8 @@ export declare const isBigInt: (value: unknown) => value is bigint;
2382
2419
 
2383
2420
  export declare const isBigIntTypedArray: (value: unknown) => value is BigInt64Array | BigUint64Array;
2384
2421
 
2422
+ export declare const isCustomEncodable: (value: unknown) => value is CustomEncodable;
2423
+
2385
2424
  export declare const isError: (value: unknown) => value is Error;
2386
2425
 
2387
2426
  /**
package/type_guards.mjs CHANGED
@@ -1,23 +1,24 @@
1
- import { a, o, k, n, w, v, g, f, e, d, c, s, x, i, h, l, b, j, m } from "./type_guards-UkDoe__i.mjs";
1
+ import { b, q, m, a, p, y, x, j, g, f, e, d, u, z, i, k, n, c, l, o } from "./type_guards-DMqlMT2e.mjs";
2
2
  export {
3
- a as isArray,
4
- o as isBigInt,
5
- k as isBigIntTypedArray,
6
- n as isError,
7
- w as isInstanceOf,
8
- v as isLucidBinaryValue,
9
- g as isLuxonDateTime,
10
- f as isLuxonDuration,
11
- e as isLuxonInterval,
12
- d as isLuxonSystemZone,
13
- c as isMap,
14
- s as isNegativeZero,
15
- x as isNumber,
3
+ b as isArray,
4
+ q as isBigInt,
5
+ m as isBigIntTypedArray,
6
+ a as isCustomEncodable,
7
+ p as isError,
8
+ y as isInstanceOf,
9
+ x as isLucidBinaryValue,
10
+ j as isLuxonDateTime,
11
+ g as isLuxonDuration,
12
+ f as isLuxonInterval,
13
+ e as isLuxonSystemZone,
14
+ d as isMap,
15
+ u as isNegativeZero,
16
+ z as isNumber,
16
17
  i as isObject,
17
- h as isPhoneObject,
18
- l as isPrimitive,
19
- b as isSet,
20
- j as isTypedArray,
21
- m as isUniterableObject
18
+ k as isPhoneObject,
19
+ n as isPrimitive,
20
+ c as isSet,
21
+ l as isTypedArray,
22
+ o as isUniterableObject
22
23
  };
23
24
  //# sourceMappingURL=type_guards.mjs.map
package/types.d.ts CHANGED
@@ -94,6 +94,17 @@ declare type CountryOrUnknown = Country | 'XX';
94
94
  */
95
95
  declare type CountryTimezone = 'Europe/Andorra' | 'Asia/Dubai' | 'Asia/Kabul' | 'America/Antigua' | 'America/Anguilla' | 'Europe/Tirane' | 'Asia/Yerevan' | 'Africa/Luanda' | 'Antarctica/Casey' | 'America/Argentina/Buenos_Aires' | 'Pacific/Pago_Pago' | 'Europe/Vienna' | 'Australia/Sydney' | 'America/Aruba' | 'Europe/Mariehamn' | 'Asia/Baku' | 'Europe/Sarajevo' | 'America/Barbados' | 'Asia/Dhaka' | 'Europe/Brussels' | 'Africa/Ouagadougou' | 'Europe/Sofia' | 'Asia/Bahrain' | 'Africa/Bujumbura' | 'Africa/Porto-Novo' | 'America/St_Barthelemy' | 'Atlantic/Bermuda' | 'Asia/Brunei' | 'America/La_Paz' | 'America/Kralendijk' | 'America/Sao_Paulo' | 'America/Nassau' | 'Asia/Thimphu' | 'Africa/Gaborone' | 'Europe/Minsk' | 'America/Belize' | 'America/Toronto' | 'Indian/Cocos' | 'Africa/Kinshasa' | 'Africa/Bangui' | 'Africa/Brazzaville' | 'Europe/Zurich' | 'Africa/Abidjan' | 'Pacific/Rarotonga' | 'America/Santiago' | 'Africa/Douala' | 'Asia/Shanghai' | 'America/Bogota' | 'America/Costa_Rica' | 'America/Havana' | 'Atlantic/Cape_Verde' | 'America/Curacao' | 'Indian/Christmas' | 'Asia/Nicosia' | 'Europe/Prague' | 'Europe/Berlin' | 'Africa/Djibouti' | 'Europe/Copenhagen' | 'America/Dominica' | 'America/Santo_Domingo' | 'Africa/Algiers' | 'America/Guayaquil' | 'Europe/Tallinn' | 'Africa/Cairo' | 'Africa/El_Aaiun' | 'Africa/Asmara' | 'Europe/Madrid' | 'Africa/Addis_Ababa' | 'Europe/Helsinki' | 'Pacific/Fiji' | 'Atlantic/Stanley' | 'Pacific/Pohnpei' | 'Atlantic/Faroe' | 'Europe/Paris' | 'Africa/Libreville' | 'Europe/London' | 'America/Grenada' | 'Asia/Tbilisi' | 'America/Cayenne' | 'Europe/Guernsey' | 'Africa/Accra' | 'Europe/Gibraltar' | 'America/Godthab' | 'Africa/Banjul' | 'Africa/Conakry' | 'America/Guadeloupe' | 'Africa/Malabo' | 'Europe/Athens' | 'Atlantic/South_Georgia' | 'America/Guatemala' | 'Pacific/Guam' | 'Africa/Bissau' | 'America/Guyana' | 'Asia/Hong_Kong' | 'America/Tegucigalpa' | 'Europe/Zagreb' | 'America/Port-au-Prince' | 'Europe/Budapest' | 'Asia/Jakarta' | 'Europe/Dublin' | 'Asia/Jerusalem' | 'Europe/Isle_of_Man' | 'Asia/Kolkata' | 'Indian/Chagos' | 'Asia/Baghdad' | 'Asia/Tehran' | 'Atlantic/Reykjavik' | 'Europe/Rome' | 'Europe/Jersey' | 'America/Jamaica' | 'Asia/Amman' | 'Asia/Tokyo' | 'Africa/Nairobi' | 'Asia/Bishkek' | 'Asia/Phnom_Penh' | 'Pacific/Tarawa' | 'Indian/Comoro' | 'America/St_Kitts' | 'Asia/Pyongyang' | 'Asia/Seoul' | 'Asia/Kuwait' | 'America/Cayman' | 'Asia/Almaty' | 'Asia/Vientiane' | 'Asia/Beirut' | 'America/St_Lucia' | 'Europe/Vaduz' | 'Asia/Colombo' | 'Africa/Monrovia' | 'Africa/Maseru' | 'Europe/Vilnius' | 'Europe/Luxembourg' | 'Europe/Riga' | 'Africa/Tripoli' | 'Africa/Casablanca' | 'Europe/Monaco' | 'Europe/Chisinau' | 'Europe/Podgorica' | 'America/Marigot' | 'Indian/Antananarivo' | 'Pacific/Majuro' | 'Europe/Skopje' | 'Africa/Bamako' | 'Asia/Yangon' | 'Asia/Ulaanbaatar' | 'Asia/Macau' | 'Pacific/Saipan' | 'America/Martinique' | 'Africa/Nouakchott' | 'America/Montserrat' | 'Europe/Malta' | 'Indian/Mauritius' | 'Indian/Maldives' | 'Africa/Blantyre' | 'America/Mexico_City' | 'Asia/Kuala_Lumpur' | 'Africa/Maputo' | 'Africa/Windhoek' | 'Pacific/Noumea' | 'Africa/Niamey' | 'Pacific/Norfolk' | 'Africa/Lagos' | 'America/Managua' | 'Europe/Amsterdam' | 'Europe/Oslo' | 'Asia/Kathmandu' | 'Pacific/Nauru' | 'Pacific/Niue' | 'Pacific/Auckland' | 'Asia/Muscat' | 'America/Panama' | 'America/Lima' | 'Pacific/Tahiti' | 'Pacific/Port_Moresby' | 'Asia/Manila' | 'Asia/Karachi' | 'Europe/Warsaw' | 'America/Miquelon' | 'Pacific/Pitcairn' | 'America/Puerto_Rico' | 'Asia/Gaza' | 'Europe/Lisbon' | 'Pacific/Palau' | 'America/Asuncion' | 'Asia/Qatar' | 'Indian/Reunion' | 'Europe/Bucharest' | 'Europe/Belgrade' | 'Europe/Moscow' | 'Africa/Kigali' | 'Asia/Riyadh' | 'Pacific/Guadalcanal' | 'Indian/Mahe' | 'Africa/Khartoum' | 'Europe/Stockholm' | 'Asia/Singapore' | 'Atlantic/St_Helena' | 'Europe/Ljubljana' | 'Arctic/Longyearbyen' | 'Europe/Bratislava' | 'Africa/Freetown' | 'Europe/San_Marino' | 'Africa/Dakar' | 'Africa/Mogadishu' | 'America/Paramaribo' | 'Africa/Juba' | 'Africa/Sao_Tome' | 'America/El_Salvador' | 'America/Lower_Princes' | 'Asia/Damascus' | 'Africa/Mbabane' | 'America/Grand_Turk' | 'Africa/Ndjamena' | 'Indian/Kerguelen' | 'Africa/Lome' | 'Asia/Bangkok' | 'Asia/Dushanbe' | 'Pacific/Fakaofo' | 'Asia/Dili' | 'Asia/Ashgabat' | 'Africa/Tunis' | 'Pacific/Tongatapu' | 'Europe/Istanbul' | 'America/Port_of_Spain' | 'Pacific/Funafuti' | 'Asia/Taipei' | 'Africa/Dar_es_Salaam' | 'Europe/Kiev' | 'Africa/Kampala' | 'Pacific/Wake' | 'America/New_York' | 'America/Montevideo' | 'Asia/Tashkent' | 'Europe/Vatican' | 'America/St_Vincent' | 'America/Caracas' | 'America/Tortola' | 'America/St_Thomas' | 'Asia/Ho_Chi_Minh' | 'Pacific/Efate' | 'Pacific/Wallis' | 'Pacific/Apia' | 'Asia/Aden' | 'Indian/Mayotte' | 'Africa/Johannesburg' | 'Africa/Lusaka' | 'Africa/Harare';
96
96
 
97
+ /**
98
+ * A class that opts in to custom encoding/decoding.
99
+ *
100
+ * Implement `[ENCODE_METHOD]()` on instances to produce an Encodable snapshot,
101
+ * and `static [DECODE_METHOD](data)` to reconstruct the instance.
102
+ * Pass the class to `registerClass()` so the decoder can find it.
103
+ */
104
+ export declare interface CustomEncodable {
105
+ [ENCODE_METHOD](): Encodable;
106
+ }
107
+
97
108
  declare type DateInput = DateTime | DateObjectUnits | Date;
98
109
 
99
110
  /**
@@ -2168,7 +2179,7 @@ export declare class E_UNENCODABLE_VALUE extends BaseException {
2168
2179
  */
2169
2180
  export declare type Encodable = EncodablePrimitive | Date | RegExp | ArrayBuffer | DataView | DateTime | Duration | Interval | EncodableTypedArray | Encodable[] | {
2170
2181
  [key: string]: Encodable;
2171
- } | Map<Encodable, Encodable> | Set<Encodable> | Error | EvalError | RangeError | ReferenceError | SyntaxError | TypeError | URIError | PhoneModel | Function | ((...args: any[]) => any);
2182
+ } | Map<Encodable, Encodable> | Set<Encodable> | Error | EvalError | RangeError | ReferenceError | SyntaxError | TypeError | URIError | PhoneModel | Function | ((...args: any[]) => any) | CustomEncodable;
2172
2183
 
2173
2184
  /**
2174
2185
  * Defines the union of all encodable primitive types.
@@ -2180,6 +2191,9 @@ export declare type EncodablePrimitive = string | number | boolean | bigint | nu
2180
2191
  */
2181
2192
  export declare type EncodableTypedArray = Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array | BigInt64Array | BigUint64Array;
2182
2193
 
2194
+ /** Instance method: serialize the object into an Encodable snapshot */
2195
+ declare const ENCODE_METHOD: unique symbol;
2196
+
2183
2197
  declare type EndOfOptions = _UseLocaleWeekOption;
2184
2198
 
2185
2199
  declare interface ErrorOptions_2 {