@stryke/json 0.6.0 → 0.6.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.
@@ -9,6 +9,7 @@ var _isString = require("@stryke/type-checks/is-string");
9
9
  var _buffer = require("buffer/");
10
10
  var _jsoncParser = require("jsonc-parser");
11
11
  var _superjson = _interopRequireDefault(require("superjson"));
12
+ var _parse = require("./utils/parse.cjs");
12
13
  var _parseError = require("./utils/parse-error.cjs");
13
14
  var _stringify = require("./utils/stringify.cjs");
14
15
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
@@ -24,12 +25,12 @@ class StormJSON extends _superjson.default {
24
25
  return StormJSON.instance.serialize(r);
25
26
  }
26
27
  static parse(r) {
27
- return StormJSON.instance.parse(r);
28
+ return (0, _parse.parse)(r);
28
29
  }
29
30
  static stringify(r, e) {
30
31
  const s = StormJSON.instance.customTransformerRegistry.findApplicable(r);
31
32
  let t = r;
32
- return s && (t = s.serialize(t)), (0, _stringify.stringify)(t);
33
+ return s && s.isApplicable(r) && (t = s.serialize(t)), (0, _stringify.stringify)(t);
33
34
  }
34
35
  static parseJson(r, e) {
35
36
  try {
@@ -1 +1 @@
1
- import{isObject as o}from"@stryke/type-checks/is-object";import{isString as l}from"@stryke/type-checks/is-string";import{Buffer as a}from"buffer/";import{parse as c}from"jsonc-parser";import p from"superjson";import{formatParseError as u}from"./utils/parse-error";import{stringify as f}from"./utils/stringify";export class StormJSON extends p{static#r;static get instance(){return StormJSON.#r||(StormJSON.#r=new StormJSON),StormJSON.#r}static deserialize(r){return StormJSON.instance.deserialize(r)}static serialize(r){return StormJSON.instance.serialize(r)}static parse(r){return StormJSON.instance.parse(r)}static stringify(r,e){const s=StormJSON.instance.customTransformerRegistry.findApplicable(r);let t=r;return s&&(t=s.serialize(t)),f(t)}static parseJson(r,e){try{if(e?.expectComments===!1)return StormJSON.instance.parse(r)}catch{}const s=[],t={allowTrailingComma:!0,...e},n=c(r,s,t);if(s.length>0&&s[0])throw new Error(u(r,s[0]));return n}static register(r,e,s,t){StormJSON.instance.registerCustom({isApplicable:t,serialize:e,deserialize:s},r)}static registerClass(r,e){StormJSON.instance.registerClass(r,{identifier:l(e)?e:e?.identifier||r.name,allowProps:e&&o(e)&&e?.allowProps&&Array.isArray(e.allowProps)?e.allowProps:["__typename"]})}constructor(){super({dedupe:!0})}}StormJSON.instance.registerCustom({isApplicable:i=>a.isBuffer(i),serialize:i=>i.toString("base64"),deserialize:i=>a.from(i,"base64")},"Bytes");
1
+ import{isObject as o}from"@stryke/type-checks/is-object";import{isString as l}from"@stryke/type-checks/is-string";import{Buffer as a}from"buffer/";import{parse as c}from"jsonc-parser";import p from"superjson";import{parse as u}from"./utils/parse";import{formatParseError as f}from"./utils/parse-error";import{stringify as m}from"./utils/stringify";export class StormJSON extends p{static#r;static get instance(){return StormJSON.#r||(StormJSON.#r=new StormJSON),StormJSON.#r}static deserialize(r){return StormJSON.instance.deserialize(r)}static serialize(r){return StormJSON.instance.serialize(r)}static parse(r){return u(r)}static stringify(r,e){const s=StormJSON.instance.customTransformerRegistry.findApplicable(r);let t=r;return s&&s.isApplicable(r)&&(t=s.serialize(t)),m(t)}static parseJson(r,e){try{if(e?.expectComments===!1)return StormJSON.instance.parse(r)}catch{}const s=[],t={allowTrailingComma:!0,...e},n=c(r,s,t);if(s.length>0&&s[0])throw new Error(f(r,s[0]));return n}static register(r,e,s,t){StormJSON.instance.registerCustom({isApplicable:t,serialize:e,deserialize:s},r)}static registerClass(r,e){StormJSON.instance.registerClass(r,{identifier:l(e)?e:e?.identifier||r.name,allowProps:e&&o(e)&&e?.allowProps&&Array.isArray(e.allowProps)?e.allowProps:["__typename"]})}constructor(){super({dedupe:!0})}}StormJSON.instance.registerCustom({isApplicable:i=>a.isBuffer(i),serialize:i=>i.toString("base64"),deserialize:i=>a.from(i,"base64")},"Bytes");
@@ -11,11 +11,15 @@ const stringify = (r, t = 2) => {
11
11
  case null:
12
12
  return "null";
13
13
  case void 0:
14
- return "undefined";
14
+ return '"undefined"';
15
15
  case !0:
16
16
  return "true";
17
17
  case !1:
18
18
  return "false";
19
+ case Number.POSITIVE_INFINITY:
20
+ return "infinity";
21
+ case Number.NEGATIVE_INFINITY:
22
+ return "-infinity";
19
23
  }
20
24
  if (Array.isArray(r)) return `[${n}${r.map(e => stringify(e, n)).join(`,${n}`)}${n}]`;
21
25
  if (r instanceof Uint8Array) return r.toString();
@@ -1 +1 @@
1
- import{isNumber as i}from"@stryke/type-checks/is-number";export const stringify=(r,t=2)=>{const n=i(t)?" ".repeat(t):t;switch(r){case null:return"null";case void 0:return"undefined";case!0:return"true";case!1:return"false"}if(Array.isArray(r))return`[${n}${r.map(e=>stringify(e,n)).join(`,${n}`)}${n}]`;if(r instanceof Uint8Array)return r.toString();switch(typeof r){case"number":return`${r}`;case"string":return JSON.stringify(r);case"object":{const e=Object.keys(r);return`{${n}${e.map(s=>`${s}: ${n}${stringify(r[s],n)}`).join(`,${n}`)}${n}}`}default:return"null"}};
1
+ import{isNumber as i}from"@stryke/type-checks/is-number";export const stringify=(r,t=2)=>{const n=i(t)?" ".repeat(t):t;switch(r){case null:return"null";case void 0:return'"undefined"';case!0:return"true";case!1:return"false";case Number.POSITIVE_INFINITY:return"infinity";case Number.NEGATIVE_INFINITY:return"-infinity"}if(Array.isArray(r))return`[${n}${r.map(e=>stringify(e,n)).join(`,${n}`)}${n}]`;if(r instanceof Uint8Array)return r.toString();switch(typeof r){case"number":return`${r}`;case"string":return JSON.stringify(r);case"object":{const e=Object.keys(r);return`{${n}${e.map(s=>`${s}: ${n}${stringify(r[s],n)}`).join(`,${n}`)}${n}}`}default:return"null"}};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stryke/json",
3
- "version": "0.6.0",
3
+ "version": "0.6.1",
4
4
  "type": "module",
5
5
  "description": "A package containing JSON parsing/stringify utilities used by Storm Software.",
6
6
  "repository": {