@stryke/json 0.3.0 → 0.4.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/dist/storm-json.cjs +4 -4
- package/dist/storm-json.d.ts +3 -3
- package/dist/storm-json.mjs +1 -1
- package/dist/utils/index.cjs +4 -4
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.mjs +1 -1
- package/dist/utils/{stringify-json.cjs → stringify.cjs} +5 -5
- package/dist/utils/{stringify-json.d.ts → stringify.d.ts} +1 -1
- package/dist/utils/stringify.mjs +1 -0
- package/package.json +8 -8
- package/dist/utils/stringify-json.mjs +0 -1
package/dist/storm-json.cjs
CHANGED
|
@@ -10,7 +10,7 @@ var _buffer = require("buffer/");
|
|
|
10
10
|
var _jsoncParser = require("jsonc-parser");
|
|
11
11
|
var _superjson = _interopRequireDefault(require("superjson"));
|
|
12
12
|
var _parseError = require("./utils/parse-error.cjs");
|
|
13
|
-
var
|
|
13
|
+
var _stringify = require("./utils/stringify.cjs");
|
|
14
14
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
15
15
|
class StormJSON extends _superjson.default {
|
|
16
16
|
static #e;
|
|
@@ -26,12 +26,12 @@ class StormJSON extends _superjson.default {
|
|
|
26
26
|
static parse(e) {
|
|
27
27
|
return StormJSON.instance.parse(e);
|
|
28
28
|
}
|
|
29
|
-
static
|
|
29
|
+
static stringify(e, r) {
|
|
30
30
|
const s = StormJSON.instance.customTransformerRegistry.findApplicable(e);
|
|
31
31
|
let t = e;
|
|
32
|
-
return s && (t = s.serialize(t)), (0,
|
|
32
|
+
return s && (t = s.serialize(t)), (0, _stringify.stringify)(t?.json ? t?.json : t, r?.spaces);
|
|
33
33
|
}
|
|
34
|
-
static
|
|
34
|
+
static stringifyBase(e) {
|
|
35
35
|
return StormJSON.instance.stringify(e);
|
|
36
36
|
}
|
|
37
37
|
static parseJson(e, r) {
|
package/dist/storm-json.d.ts
CHANGED
|
@@ -30,18 +30,18 @@ export declare class StormJSON extends SuperJSON {
|
|
|
30
30
|
* Serializes the given data to a JSON string.
|
|
31
31
|
* By default the JSON string is formatted with a 2 space indentation to be easy readable.
|
|
32
32
|
*
|
|
33
|
-
* @param
|
|
33
|
+
* @param value - Object which should be serialized to JSON
|
|
34
34
|
* @param options - JSON serialize options
|
|
35
35
|
* @returns the formatted JSON representation of the object
|
|
36
36
|
*/
|
|
37
|
-
static
|
|
37
|
+
static stringify<T>(value: T, options?: JsonSerializeOptions): string;
|
|
38
38
|
/**
|
|
39
39
|
* Stringify the given value with superjson
|
|
40
40
|
*
|
|
41
41
|
* @param obj - The object to stringify
|
|
42
42
|
* @returns The stringified object
|
|
43
43
|
*/
|
|
44
|
-
static
|
|
44
|
+
static stringifyBase(obj: any): string;
|
|
45
45
|
/**
|
|
46
46
|
* Parses the given JSON string and returns the object the JSON content represents.
|
|
47
47
|
* By default javascript-style comments and trailing commas are allowed.
|
package/dist/storm-json.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{isObject as o}from"@stryke/types/type-checks/is-object";import{isString as l}from"@stryke/types/type-checks/is-string";import{Buffer as a}from"buffer/";import{parse as c}from"jsonc-parser";import u from"superjson";import{formatParseError as p}from"./utils/parse-error";import{
|
|
1
|
+
import{isObject as o}from"@stryke/types/type-checks/is-object";import{isString as l}from"@stryke/types/type-checks/is-string";import{Buffer as a}from"buffer/";import{parse as c}from"jsonc-parser";import u from"superjson";import{formatParseError as p}from"./utils/parse-error";import{stringify as f}from"./utils/stringify";export class StormJSON extends u{static#e;static get instance(){return StormJSON.#e||(StormJSON.#e=new StormJSON),StormJSON.#e}static deserialize(e){return StormJSON.instance.deserialize(e)}static serialize(e){return StormJSON.instance.serialize(e)}static parse(e){return StormJSON.instance.parse(e)}static stringify(e,r){const s=StormJSON.instance.customTransformerRegistry.findApplicable(e);let t=e;return s&&(t=s.serialize(t)),f(t?.json?t?.json:t,r?.spaces)}static stringifyBase(e){return StormJSON.instance.stringify(e)}static parseJson(e,r){try{if(r?.expectComments===!1)return StormJSON.instance.parse(e)}catch{}const s=[],t={allowTrailingComma:!0,...r},n=c(e,s,t);if(s.length>0&&s[0])throw new Error(p(e,s[0]));return n}static register(e,r,s,t){StormJSON.instance.registerCustom({isApplicable:t,serialize:r,deserialize:s},e)}static registerClass(e,r){StormJSON.instance.registerClass(e,{identifier:l(r)?r:r?.identifier||e.name,allowProps:r&&o(r)&&r?.allowProps&&Array.isArray(r.allowProps)?r.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");
|
package/dist/utils/index.cjs
CHANGED
|
@@ -25,14 +25,14 @@ Object.keys(_parseError).forEach(function (key) {
|
|
|
25
25
|
}
|
|
26
26
|
});
|
|
27
27
|
});
|
|
28
|
-
var
|
|
29
|
-
Object.keys(
|
|
28
|
+
var _stringify = require("./stringify.cjs");
|
|
29
|
+
Object.keys(_stringify).forEach(function (key) {
|
|
30
30
|
if (key === "default" || key === "__esModule") return;
|
|
31
|
-
if (key in exports && exports[key] ===
|
|
31
|
+
if (key in exports && exports[key] === _stringify[key]) return;
|
|
32
32
|
Object.defineProperty(exports, key, {
|
|
33
33
|
enumerable: true,
|
|
34
34
|
get: function () {
|
|
35
|
-
return
|
|
35
|
+
return _stringify[key];
|
|
36
36
|
}
|
|
37
37
|
});
|
|
38
38
|
});
|
package/dist/utils/index.d.ts
CHANGED
package/dist/utils/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export*from"./code-frames";export*from"./parse-error";export*from"./stringify
|
|
1
|
+
export*from"./code-frames";export*from"./parse-error";export*from"./stringify";export*from"./strip-comments";
|
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.stringify = void 0;
|
|
7
7
|
var _isNumber = require("@stryke/types/type-checks/is-number");
|
|
8
|
-
const
|
|
8
|
+
const stringify = (r, t = 2) => {
|
|
9
9
|
const n = (0, _isNumber.isNumber)(t) ? " ".repeat(t) : t;
|
|
10
10
|
switch (r) {
|
|
11
11
|
case null:
|
|
@@ -17,7 +17,7 @@ const stringifyJson = (r, t = 2) => {
|
|
|
17
17
|
case !1:
|
|
18
18
|
return "false";
|
|
19
19
|
}
|
|
20
|
-
if (Array.isArray(r)) return `[${n}${r.map(e =>
|
|
20
|
+
if (Array.isArray(r)) return `[${n}${r.map(e => stringify(e, n)).join(`,${n}`)}${n}]`;
|
|
21
21
|
if (r instanceof Uint8Array) return r.toString();
|
|
22
22
|
switch (typeof r) {
|
|
23
23
|
case "number":
|
|
@@ -27,10 +27,10 @@ const stringifyJson = (r, t = 2) => {
|
|
|
27
27
|
case "object":
|
|
28
28
|
{
|
|
29
29
|
const e = Object.keys(r);
|
|
30
|
-
return `{${n}${e.map(s => `${s}${n}
|
|
30
|
+
return `{${n}${e.map(s => `${s}: ${n}${stringify(r[s], n)}`).join(`,${n}`)}${n}}`;
|
|
31
31
|
}
|
|
32
32
|
default:
|
|
33
33
|
return "null";
|
|
34
34
|
}
|
|
35
35
|
};
|
|
36
|
-
exports.
|
|
36
|
+
exports.stringify = stringify;
|
|
@@ -5,4 +5,4 @@
|
|
|
5
5
|
* @param spacing - The spacing to use for the stringification
|
|
6
6
|
* @returns The stringified value
|
|
7
7
|
*/
|
|
8
|
-
export declare const
|
|
8
|
+
export declare const stringify: (value: unknown, spacing?: string | number) => string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{isNumber as i}from"@stryke/types/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"}};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stryke/json",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A package containing JSON parsing/stringify utilities used by Storm Software.",
|
|
6
6
|
"repository": {
|
|
@@ -106,18 +106,18 @@
|
|
|
106
106
|
"default": "./dist/utils/strip-comments.mjs"
|
|
107
107
|
}
|
|
108
108
|
},
|
|
109
|
-
"./utils/stringify
|
|
109
|
+
"./utils/stringify": {
|
|
110
110
|
"import": {
|
|
111
|
-
"types": "./dist/utils/stringify
|
|
112
|
-
"default": "./dist/utils/stringify
|
|
111
|
+
"types": "./dist/utils/stringify.d.ts",
|
|
112
|
+
"default": "./dist/utils/stringify.mjs"
|
|
113
113
|
},
|
|
114
114
|
"require": {
|
|
115
|
-
"types": "./dist/utils/stringify
|
|
116
|
-
"default": "./dist/utils/stringify
|
|
115
|
+
"types": "./dist/utils/stringify.d.ts",
|
|
116
|
+
"default": "./dist/utils/stringify.cjs"
|
|
117
117
|
},
|
|
118
118
|
"default": {
|
|
119
|
-
"types": "./dist/utils/stringify
|
|
120
|
-
"default": "./dist/utils/stringify
|
|
119
|
+
"types": "./dist/utils/stringify.d.ts",
|
|
120
|
+
"default": "./dist/utils/stringify.mjs"
|
|
121
121
|
}
|
|
122
122
|
},
|
|
123
123
|
"./utils/parse-error": {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{isNumber as i}from"@stryke/types/type-checks/is-number";export const stringifyJson=(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=>stringifyJson(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}=${n}${stringifyJson(r[s],n)}`).join(`,${n}`)}${n}}`}default:return"null"}};
|