@jsonup/core 0.0.1 → 0.0.2

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/index.d.mts CHANGED
@@ -10,9 +10,9 @@ type JsonPrimitive = string | number | boolean | null | Decimal;
10
10
  */
11
11
  type JsonValue = JsonPrimitive | JsonObject | JsonArray;
12
12
  /**
13
- * 表示 JSON 输入的基本数据类型的联合类型,包含 string、number、bigint、boolean、null 和 Decimal
13
+ * 表示 JSON 输入的基本数据类型的联合类型,包含 string、number、bigint、boolean、null、DecimalDate
14
14
  */
15
- type JsonInputPrimitive = string | number | bigint | boolean | null | Decimal;
15
+ type JsonInputPrimitive = string | number | bigint | boolean | null | Decimal | Date;
16
16
  /**
17
17
  * 表示任意合法的 JSON 输入值类型,可以是基本类型、对象或数组
18
18
  */
package/dist/index.mjs CHANGED
@@ -39,6 +39,8 @@ function toJsonRoot(input) {
39
39
  function toJsonValue(value) {
40
40
  if (value === null || typeof value === "string" || typeof value === "number" || typeof value === "boolean") return value;
41
41
  if (typeof value === "bigint") return new Decimal(value.toString());
42
+ if (value instanceof Date) return Number.isNaN(value.getTime()) ? null : value.toISOString();
43
+ if (value !== null && typeof value === "object" && typeof value.toJSON === "function") return toJsonValue(value.toJSON());
42
44
  if (Decimal.isDecimal(value)) return value;
43
45
  if (Array.isArray(value)) return value.map((item) => toJsonValue(item));
44
46
  if (isPlainObject(value)) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@jsonup/core",
3
3
  "type": "module",
4
- "version": "0.0.1",
4
+ "version": "0.0.2",
5
5
  "description": "The core JSON parser, state manager, and document builder for the jsonup ecosystem.",
6
6
  "author": {
7
7
  "name": "Michael Cocova",