@stryke/json 0.2.0 → 0.3.0
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/pointer/parse.cjs +1 -1
- package/dist/pointer/parse.mjs +1 -1
- package/dist/storm-json.cjs +7 -9
- package/dist/storm-json.d.ts +9 -7
- package/dist/storm-json.mjs +1 -1
- package/dist/types.d.ts +2 -2
- package/dist/utils/code-frames.cjs +18 -18
- package/dist/utils/code-frames.d.ts +4 -4
- package/dist/utils/code-frames.mjs +2 -2
- 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/parse-error.cjs +10 -10
- package/dist/utils/parse-error.mjs +2 -2
- package/dist/utils/stringify-json.cjs +36 -0
- package/dist/utils/{stringify.d.ts → stringify-json.d.ts} +1 -1
- package/dist/utils/stringify-json.mjs +1 -0
- package/package.json +9 -9
- package/dist/utils/stringify.cjs +0 -35
- package/dist/utils/stringify.mjs +0 -1
package/dist/pointer/parse.cjs
CHANGED
|
@@ -25,7 +25,7 @@ function parseJsonPointer(n) {
|
|
|
25
25
|
return n ? n.slice(1).split("/").map(t => unescapePointerSegment(t)) : [];
|
|
26
26
|
}
|
|
27
27
|
function formatJsonPointer(n) {
|
|
28
|
-
return isRoot(n) ? "" :
|
|
28
|
+
return isRoot(n) ? "" : `/${n.map(t => escapePointerSegment(String(t))).join("/")}`;
|
|
29
29
|
}
|
|
30
30
|
const isRoot = n => n.length === 0;
|
|
31
31
|
exports.isRoot = isRoot;
|
package/dist/pointer/parse.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{isNumber as o}from"@stryke/types/type-checks/is-number";const i=/~1/g,s=/~0/g,u=/~/g,c=/\//g;export function escapePointerSegment(n){return!n.includes("/")&&!n.includes("~")?n:n.replace(u,"~0").replace(c,"~1")}export function unescapePointerSegment(n){return n.includes("~")?n.replace(i,"/").replace(s,"~"):n}export function parseJsonPointer(n){return n?n.slice(1).split("/").map(t=>unescapePointerSegment(t)):[]}export function formatJsonPointer(n){return isRoot(n)?""
|
|
1
|
+
import{isNumber as o}from"@stryke/types/type-checks/is-number";const i=/~1/g,s=/~0/g,u=/~/g,c=/\//g;export function escapePointerSegment(n){return!n.includes("/")&&!n.includes("~")?n:n.replace(u,"~0").replace(c,"~1")}export function unescapePointerSegment(n){return n.includes("~")?n.replace(i,"/").replace(s,"~"):n}export function parseJsonPointer(n){return n?n.slice(1).split("/").map(t=>unescapePointerSegment(t)):[]}export function formatJsonPointer(n){return isRoot(n)?"":`/${n.map(t=>escapePointerSegment(String(t))).join("/")}`}export const isRoot=n=>n.length===0;export function parent(n){if(n.length===0)throw new Error("NO_PARENT");return n.slice(0,-1)}export function isValidIndex(n){if(o(n))return!0;const t=Number.parseInt(n,10);return String(t)===n&&t>=0}export const isInteger=n=>{const t=n.length;let r=0,e;for(;r<t;){if(e=n.codePointAt(r),e>=48&&e<=57){r++;continue}return!1}return!0};
|
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 _stringifyJson = require("./utils/stringify-json.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,15 +26,13 @@ class StormJSON extends _superjson.default {
|
|
|
26
26
|
static parse(e) {
|
|
27
27
|
return StormJSON.instance.parse(e);
|
|
28
28
|
}
|
|
29
|
-
static stringify(e) {
|
|
30
|
-
const r = StormJSON.instance.customTransformerRegistry.findApplicable(e);
|
|
31
|
-
let s = e;
|
|
32
|
-
return r && (s = r.serialize(s)), (0, _stringify.stringify)(s);
|
|
33
|
-
}
|
|
34
29
|
static stringifyJson(e, r) {
|
|
35
30
|
const s = StormJSON.instance.customTransformerRegistry.findApplicable(e);
|
|
36
31
|
let t = e;
|
|
37
|
-
return s && (t = s.serialize(t)), (0,
|
|
32
|
+
return s && (t = s.serialize(t)), (0, _stringifyJson.stringifyJson)(t?.json ? t?.json : t, r?.spaces);
|
|
33
|
+
}
|
|
34
|
+
static stringify(e) {
|
|
35
|
+
return StormJSON.instance.stringify(e);
|
|
38
36
|
}
|
|
39
37
|
static parseJson(e, r) {
|
|
40
38
|
try {
|
|
@@ -45,9 +43,9 @@ class StormJSON extends _superjson.default {
|
|
|
45
43
|
allowTrailingComma: !0,
|
|
46
44
|
...r
|
|
47
45
|
},
|
|
48
|
-
|
|
46
|
+
n = (0, _jsoncParser.parse)(e, s, t);
|
|
49
47
|
if (s.length > 0 && s[0]) throw new Error((0, _parseError.formatParseError)(e, s[0]));
|
|
50
|
-
return
|
|
48
|
+
return n;
|
|
51
49
|
}
|
|
52
50
|
static register(e, r, s, t) {
|
|
53
51
|
StormJSON.instance.registerCustom({
|
package/dist/storm-json.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import SuperJSON from "superjson";
|
|
2
1
|
import type { Class, JsonParseOptions, JsonParserResult, JsonSerializeOptions, JsonValue } from "./types";
|
|
2
|
+
import SuperJSON from "superjson";
|
|
3
3
|
/**
|
|
4
4
|
* A static JSON parser class used by Storm Software to serialize and deserialize JSON data
|
|
5
5
|
*
|
|
@@ -26,11 +26,6 @@ export declare class StormJSON extends SuperJSON {
|
|
|
26
26
|
* @returns The parsed data
|
|
27
27
|
*/
|
|
28
28
|
static parse<TData = unknown>(value: string): TData;
|
|
29
|
-
/**
|
|
30
|
-
* Stringify the given value with superjson
|
|
31
|
-
*
|
|
32
|
-
*/
|
|
33
|
-
static stringify(obj: any): string;
|
|
34
29
|
/**
|
|
35
30
|
* Serializes the given data to a JSON string.
|
|
36
31
|
* By default the JSON string is formatted with a 2 space indentation to be easy readable.
|
|
@@ -39,7 +34,14 @@ export declare class StormJSON extends SuperJSON {
|
|
|
39
34
|
* @param options - JSON serialize options
|
|
40
35
|
* @returns the formatted JSON representation of the object
|
|
41
36
|
*/
|
|
42
|
-
static stringifyJson(json:
|
|
37
|
+
static stringifyJson<TJson>(json: TJson, options?: JsonSerializeOptions): string;
|
|
38
|
+
/**
|
|
39
|
+
* Stringify the given value with superjson
|
|
40
|
+
*
|
|
41
|
+
* @param obj - The object to stringify
|
|
42
|
+
* @returns The stringified object
|
|
43
|
+
*/
|
|
44
|
+
static stringify(obj: any): string;
|
|
43
45
|
/**
|
|
44
46
|
* Parses the given JSON string and returns the object the JSON content represents.
|
|
45
47
|
* By default javascript-style comments and trailing commas are allowed.
|
package/dist/storm-json.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{isObject as
|
|
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{stringifyJson as f}from"./utils/stringify-json";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 stringifyJson(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 stringify(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/types.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { ParseOptions } from "jsonc-parser";
|
|
2
2
|
export type PrimitiveJsonValue = string | number | boolean | undefined | null;
|
|
3
|
-
export
|
|
3
|
+
export interface Class {
|
|
4
4
|
new (...args: any[]): any;
|
|
5
|
-
}
|
|
5
|
+
}
|
|
6
6
|
export type JsonValue = PrimitiveJsonValue | JsonArray | JsonObject;
|
|
7
7
|
export type JsonArray = Array<JsonValue>;
|
|
8
8
|
export interface JsonObject {
|
|
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.codeFrameColumns = codeFrameColumns;
|
|
7
|
-
const
|
|
7
|
+
const k = /\r\n|[\n\r\u2028\u2029]/;
|
|
8
8
|
function N(s, l, a = {}) {
|
|
9
9
|
const c = {
|
|
10
10
|
column: 0,
|
|
@@ -19,25 +19,25 @@ function N(s, l, a = {}) {
|
|
|
19
19
|
linesAbove: h = 2,
|
|
20
20
|
linesBelow: f = 3
|
|
21
21
|
} = a || {},
|
|
22
|
-
|
|
22
|
+
i = c.line,
|
|
23
23
|
t = c.column,
|
|
24
24
|
b = m.line,
|
|
25
|
-
|
|
26
|
-
let d = Math.max(
|
|
25
|
+
o = m.column;
|
|
26
|
+
let d = Math.max(i - (h + 1), 0),
|
|
27
27
|
u = Math.min(l.length, b + f);
|
|
28
|
-
|
|
29
|
-
const L = b -
|
|
28
|
+
i === -1 && (d = 0), b === -1 && (u = l.length);
|
|
29
|
+
const L = b - i,
|
|
30
30
|
e = {};
|
|
31
31
|
if (L) for (let n = 0; n <= L; n++) {
|
|
32
|
-
const r = n +
|
|
32
|
+
const r = n + i;
|
|
33
33
|
if (!t) e[r] = !0;else if (n === 0) {
|
|
34
34
|
const g = l[r - 1]?.length ?? 0;
|
|
35
35
|
e[r] = [t, g - t + 1];
|
|
36
|
-
} else if (n === L) e[r] = [0,
|
|
36
|
+
} else if (n === L) e[r] = [0, o];else {
|
|
37
37
|
const g = l[r - n]?.length ?? 0;
|
|
38
38
|
e[r] = [0, g];
|
|
39
39
|
}
|
|
40
|
-
} else t ===
|
|
40
|
+
} else t === o ? e[i] = t ? [t, 0] : !0 : e[i] = [t, o - t];
|
|
41
41
|
return {
|
|
42
42
|
start: d,
|
|
43
43
|
end: u,
|
|
@@ -45,28 +45,28 @@ function N(s, l, a = {}) {
|
|
|
45
45
|
};
|
|
46
46
|
}
|
|
47
47
|
function codeFrameColumns(s, l, a = {}) {
|
|
48
|
-
const c = s.split(
|
|
48
|
+
const c = s.split(k),
|
|
49
49
|
{
|
|
50
50
|
start: m,
|
|
51
51
|
end: h,
|
|
52
52
|
markerLines: f
|
|
53
53
|
} = N(l, c, a),
|
|
54
|
-
|
|
55
|
-
return (a.highlight ? a.highlight(s) : s).split(
|
|
54
|
+
i = String(h).length;
|
|
55
|
+
return (a.highlight ? a.highlight(s) : s).split(k).slice(m, h).map((o, d) => {
|
|
56
56
|
const u = m + 1 + d,
|
|
57
|
-
e = ` ${` ${u}`.slice(-
|
|
57
|
+
e = ` ${` ${u}`.slice(-i)} | `,
|
|
58
58
|
n = !!(f[u] ?? !1);
|
|
59
59
|
if (n) {
|
|
60
60
|
let r = "";
|
|
61
61
|
if (Array.isArray(n)) {
|
|
62
|
-
const g =
|
|
63
|
-
|
|
62
|
+
const g = o.slice(0, Math.max(n[0] - 1, 0)).replace(/[^\t]/g, " "),
|
|
63
|
+
p = n[1] || 1;
|
|
64
64
|
r = [`
|
|
65
|
-
`, e.replace(/\d/g, " "), g, "^".repeat(
|
|
65
|
+
`, e.replace(/\d/g, " "), g, "^".repeat(p)].join("");
|
|
66
66
|
}
|
|
67
|
-
return [">", e,
|
|
67
|
+
return [">", e, o, r].join("");
|
|
68
68
|
}
|
|
69
|
-
return ` ${e}${
|
|
69
|
+
return ` ${e}${o}`;
|
|
70
70
|
}).join(`
|
|
71
71
|
`);
|
|
72
72
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
interface Location {
|
|
2
2
|
column: number;
|
|
3
3
|
line: number;
|
|
4
|
-
}
|
|
5
|
-
|
|
4
|
+
}
|
|
5
|
+
interface NodeLocation {
|
|
6
6
|
end?: Location;
|
|
7
7
|
start?: Location;
|
|
8
|
-
}
|
|
8
|
+
}
|
|
9
9
|
export declare function codeFrameColumns(rawLines: string, loc: NodeLocation, opts?: {
|
|
10
10
|
linesAbove?: number;
|
|
11
11
|
linesBelow?: number;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
const
|
|
2
|
-
`,e.replace(/\d/g," "),g,"^".repeat(
|
|
1
|
+
const k=/\r\n|[\n\r\u2028\u2029]/;function N(s,l,a={}){const c={column:0,line:-1,...s.start},m={...c,...s.end},{linesAbove:h=2,linesBelow:f=3}=a||{},i=c.line,t=c.column,b=m.line,o=m.column;let d=Math.max(i-(h+1),0),u=Math.min(l.length,b+f);i===-1&&(d=0),b===-1&&(u=l.length);const L=b-i,e={};if(L)for(let n=0;n<=L;n++){const r=n+i;if(!t)e[r]=!0;else if(n===0){const g=l[r-1]?.length??0;e[r]=[t,g-t+1]}else if(n===L)e[r]=[0,o];else{const g=l[r-n]?.length??0;e[r]=[0,g]}}else t===o?e[i]=t?[t,0]:!0:e[i]=[t,o-t];return{start:d,end:u,markerLines:e}}export function codeFrameColumns(s,l,a={}){const c=s.split(k),{start:m,end:h,markerLines:f}=N(l,c,a),i=String(h).length;return(a.highlight?a.highlight(s):s).split(k).slice(m,h).map((o,d)=>{const u=m+1+d,e=` ${` ${u}`.slice(-i)} | `,n=!!(f[u]??!1);if(n){let r="";if(Array.isArray(n)){const g=o.slice(0,Math.max(n[0]-1,0)).replace(/[^\t]/g," "),p=n[1]||1;r=[`
|
|
2
|
+
`,e.replace(/\d/g," "),g,"^".repeat(p)].join("")}return[">",e,o,r].join("")}return` ${e}${o}`}).join(`
|
|
3
3
|
`)}
|
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 _stringifyJson = require("./stringify-json.cjs");
|
|
29
|
+
Object.keys(_stringifyJson).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] === _stringifyJson[key]) return;
|
|
32
32
|
Object.defineProperty(exports, key, {
|
|
33
33
|
enumerable: true,
|
|
34
34
|
get: function () {
|
|
35
|
-
return
|
|
35
|
+
return _stringifyJson[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";export*from"./strip-comments";
|
|
1
|
+
export*from"./code-frames";export*from"./parse-error";export*from"./stringify-json";export*from"./strip-comments";
|
|
@@ -7,17 +7,17 @@ exports.formatParseError = formatParseError;
|
|
|
7
7
|
var _jsoncParser = require("jsonc-parser");
|
|
8
8
|
var _linesAndColumns = require("lines-and-columns");
|
|
9
9
|
var _codeFrames = require("./code-frames.cjs");
|
|
10
|
-
function formatParseError(
|
|
10
|
+
function formatParseError(n, t) {
|
|
11
11
|
const {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
o =
|
|
12
|
+
error: m,
|
|
13
|
+
offset: s,
|
|
14
|
+
length: l
|
|
15
|
+
} = t,
|
|
16
|
+
e = new _linesAndColumns.LinesAndColumns(n).locationForIndex(s);
|
|
17
|
+
let r = e?.line ?? 0,
|
|
18
|
+
o = e?.column ?? 0;
|
|
19
19
|
return r++, o++, `${(0, _jsoncParser.printParseErrorCode)(m)} in JSON at ${r}:${o}
|
|
20
|
-
|
|
20
|
+
${(0, _codeFrames.codeFrameColumns)(n, {
|
|
21
21
|
start: {
|
|
22
22
|
line: r,
|
|
23
23
|
column: o
|
|
@@ -26,6 +26,6 @@ function formatParseError(e, t) {
|
|
|
26
26
|
line: r,
|
|
27
27
|
column: o + l
|
|
28
28
|
}
|
|
29
|
-
})
|
|
29
|
+
})}
|
|
30
30
|
`;
|
|
31
31
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{printParseErrorCode as i}from"jsonc-parser";import{LinesAndColumns as a}from"lines-and-columns";import{codeFrameColumns as c}from"./code-frames";export function formatParseError(
|
|
2
|
-
|
|
1
|
+
import{printParseErrorCode as i}from"jsonc-parser";import{LinesAndColumns as a}from"lines-and-columns";import{codeFrameColumns as c}from"./code-frames";export function formatParseError(n,t){const{error:m,offset:s,length:l}=t,e=new a(n).locationForIndex(s);let r=e?.line??0,o=e?.column??0;return r++,o++,`${i(m)} in JSON at ${r}:${o}
|
|
2
|
+
${c(n,{start:{line:r,column:o},end:{line:r,column:o+l}})}
|
|
3
3
|
`}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.stringifyJson = void 0;
|
|
7
|
+
var _isNumber = require("@stryke/types/type-checks/is-number");
|
|
8
|
+
const stringifyJson = (r, t = 2) => {
|
|
9
|
+
const n = (0, _isNumber.isNumber)(t) ? " ".repeat(t) : t;
|
|
10
|
+
switch (r) {
|
|
11
|
+
case null:
|
|
12
|
+
return "null";
|
|
13
|
+
case void 0:
|
|
14
|
+
return "undefined";
|
|
15
|
+
case !0:
|
|
16
|
+
return "true";
|
|
17
|
+
case !1:
|
|
18
|
+
return "false";
|
|
19
|
+
}
|
|
20
|
+
if (Array.isArray(r)) return `[${n}${r.map(e => stringifyJson(e, n)).join(`,${n}`)}${n}]`;
|
|
21
|
+
if (r instanceof Uint8Array) return r.toString();
|
|
22
|
+
switch (typeof r) {
|
|
23
|
+
case "number":
|
|
24
|
+
return `${r}`;
|
|
25
|
+
case "string":
|
|
26
|
+
return JSON.stringify(r);
|
|
27
|
+
case "object":
|
|
28
|
+
{
|
|
29
|
+
const e = Object.keys(r);
|
|
30
|
+
return `{${n}${e.map(s => `${s}${n}=${n}${stringifyJson(r[s], n)}`).join(`,${n}`)}${n}}`;
|
|
31
|
+
}
|
|
32
|
+
default:
|
|
33
|
+
return "null";
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
exports.stringifyJson = stringifyJson;
|
|
@@ -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 stringifyJson: (value: unknown, spacing?: string | number) => string;
|
|
@@ -0,0 +1 @@
|
|
|
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"}};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stryke/json",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A package containing JSON parsing/stringify utilities used by Storm Software.",
|
|
6
6
|
"repository": {
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"jsonc-parser": "3.3.1",
|
|
15
15
|
"lines-and-columns": "2.0.4",
|
|
16
16
|
"superjson": "2.2.2",
|
|
17
|
-
"@stryke/types": ">=0.
|
|
17
|
+
"@stryke/types": ">=0.5.0"
|
|
18
18
|
},
|
|
19
19
|
"publishConfig": { "access": "public" },
|
|
20
20
|
"devDependencies": {},
|
|
@@ -106,18 +106,18 @@
|
|
|
106
106
|
"default": "./dist/utils/strip-comments.mjs"
|
|
107
107
|
}
|
|
108
108
|
},
|
|
109
|
-
"./utils/stringify": {
|
|
109
|
+
"./utils/stringify-json": {
|
|
110
110
|
"import": {
|
|
111
|
-
"types": "./dist/utils/stringify.d.ts",
|
|
112
|
-
"default": "./dist/utils/stringify.mjs"
|
|
111
|
+
"types": "./dist/utils/stringify-json.d.ts",
|
|
112
|
+
"default": "./dist/utils/stringify-json.mjs"
|
|
113
113
|
},
|
|
114
114
|
"require": {
|
|
115
|
-
"types": "./dist/utils/stringify.d.ts",
|
|
116
|
-
"default": "./dist/utils/stringify.cjs"
|
|
115
|
+
"types": "./dist/utils/stringify-json.d.ts",
|
|
116
|
+
"default": "./dist/utils/stringify-json.cjs"
|
|
117
117
|
},
|
|
118
118
|
"default": {
|
|
119
|
-
"types": "./dist/utils/stringify.d.ts",
|
|
120
|
-
"default": "./dist/utils/stringify.mjs"
|
|
119
|
+
"types": "./dist/utils/stringify-json.d.ts",
|
|
120
|
+
"default": "./dist/utils/stringify-json.mjs"
|
|
121
121
|
}
|
|
122
122
|
},
|
|
123
123
|
"./utils/parse-error": {
|
package/dist/utils/stringify.cjs
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.stringify = void 0;
|
|
7
|
-
var _isNumber = require("@stryke/types/type-checks/is-number");
|
|
8
|
-
const stringify = (r, t = " ") => {
|
|
9
|
-
const n = (0, _isNumber.isNumber)(t) ? " ".repeat(t) : t;
|
|
10
|
-
switch (r) {
|
|
11
|
-
case null:
|
|
12
|
-
return "!n";
|
|
13
|
-
case void 0:
|
|
14
|
-
return "!u";
|
|
15
|
-
case !0:
|
|
16
|
-
return "!t";
|
|
17
|
-
case !1:
|
|
18
|
-
return "!f";
|
|
19
|
-
}
|
|
20
|
-
if (Array.isArray(r)) return `[${n}${r.map(e => stringify(e, n)).join("," + n)}${n}]`;
|
|
21
|
-
if (r instanceof Uint8Array) return `${r}`;
|
|
22
|
-
switch (typeof r) {
|
|
23
|
-
case "number":
|
|
24
|
-
return `${r}`;
|
|
25
|
-
case "string":
|
|
26
|
-
return JSON.stringify(r);
|
|
27
|
-
case "object":
|
|
28
|
-
{
|
|
29
|
-
const e = Object.keys(r);
|
|
30
|
-
return `{${n}${e.map(s => `${s}${n}=${n}${stringify(r[s], n)}`).join("," + n)}${n}}`;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
return "?";
|
|
34
|
-
};
|
|
35
|
-
exports.stringify = stringify;
|
package/dist/utils/stringify.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{isNumber as i}from"@stryke/types/type-checks/is-number";export const stringify=(r,t=" ")=>{const n=i(t)?" ".repeat(t):t;switch(r){case null:return"!n";case void 0:return"!u";case!0:return"!t";case!1:return"!f"}if(Array.isArray(r))return`[${n}${r.map(e=>stringify(e,n)).join(","+n)}${n}]`;if(r instanceof Uint8Array)return`${r}`;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}${stringify(r[s],n)}`).join(","+n)}${n}}`}}return"?"};
|