@stryke/json 0.1.4 → 0.2.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/README.md +14 -16
- package/dist/pointer/parse.cjs +1 -1
- package/dist/pointer/parse.mjs +1 -1
- package/dist/storm-json.cjs +36 -35
- package/dist/storm-json.d.ts +9 -3
- package/dist/storm-json.mjs +1 -1
- 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.cjs → stringify-min.cjs} +9 -8
- package/dist/utils/{stringify.d.ts → stringify-min.d.ts} +1 -1
- package/dist/utils/stringify-min.mjs +1 -0
- package/package.json +9 -9
- package/dist/utils/stringify.mjs +0 -1
package/README.md
CHANGED
|
@@ -22,7 +22,7 @@ This package is part of Storm Software's **🌩️ Stryke** monorepo. Stryke pac
|
|
|
22
22
|
|
|
23
23
|
<h3 align="center">💻 Visit <a href="https://stormsoftware.com" target="_blank">stormsoftware.com</a> to stay up to date with this developer</h3><br />
|
|
24
24
|
|
|
25
|
-
[](https://prettier.io/) [](http://nx.dev/) [](https://nextjs.org/) [](http://commitizen.github.io/cz-cli/)  [](https://fumadocs.vercel.app/) 
|
|
26
26
|
|
|
27
27
|
> [!IMPORTANT] This repository, and the apps, libraries, and tools contained
|
|
28
28
|
> within, is still in it's initial development phase. As a result, bugs and
|
|
@@ -55,21 +55,19 @@ flexibility and customization.
|
|
|
55
55
|
|
|
56
56
|
## Table of Contents
|
|
57
57
|
|
|
58
|
-
- [
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
- [
|
|
62
|
-
- [
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
- [Contributing](#contributing)
|
|
72
|
-
- [Contributors](#contributors)
|
|
58
|
+
- [Installing](#installing)
|
|
59
|
+
- [Reduced Package Size](#reduced-package-size)
|
|
60
|
+
- [Development](#development)
|
|
61
|
+
- [Building](#building)
|
|
62
|
+
- [Running unit tests](#running-unit-tests)
|
|
63
|
+
- [Linting](#linting)
|
|
64
|
+
- [Storm Workspaces](#storm-workspaces)
|
|
65
|
+
- [Roadmap](#roadmap)
|
|
66
|
+
- [Support](#support)
|
|
67
|
+
- [License](#license)
|
|
68
|
+
- [Changelog](#changelog)
|
|
69
|
+
- [Contributing](#contributing)
|
|
70
|
+
- [Contributors](#contributors)
|
|
73
71
|
|
|
74
72
|
<!-- END doctoc -->
|
|
75
73
|
|
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,56 +10,57 @@ 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 _stringifyMin = require("./utils/stringify-min.cjs");
|
|
14
14
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
15
15
|
class StormJSON extends _superjson.default {
|
|
16
|
-
static #
|
|
16
|
+
static #r;
|
|
17
17
|
static get instance() {
|
|
18
|
-
return StormJSON.#
|
|
18
|
+
return StormJSON.#r || (StormJSON.#r = new StormJSON()), StormJSON.#r;
|
|
19
19
|
}
|
|
20
|
-
static deserialize(
|
|
21
|
-
return StormJSON.instance.deserialize(
|
|
20
|
+
static deserialize(r) {
|
|
21
|
+
return StormJSON.instance.deserialize(r);
|
|
22
22
|
}
|
|
23
|
-
static serialize(
|
|
24
|
-
return StormJSON.instance.serialize(
|
|
23
|
+
static serialize(r) {
|
|
24
|
+
return StormJSON.instance.serialize(r);
|
|
25
25
|
}
|
|
26
|
-
static parse(
|
|
27
|
-
return StormJSON.instance.parse(
|
|
26
|
+
static parse(r) {
|
|
27
|
+
return StormJSON.instance.parse(r);
|
|
28
28
|
}
|
|
29
|
-
static
|
|
30
|
-
const
|
|
31
|
-
let s =
|
|
32
|
-
return
|
|
29
|
+
static stringifyMin(r) {
|
|
30
|
+
const e = StormJSON.instance.customTransformerRegistry.findApplicable(r);
|
|
31
|
+
let s = r;
|
|
32
|
+
return e && (s = e.serialize(s)), (0, _stringifyMin.stringifyMin)(s);
|
|
33
33
|
}
|
|
34
|
-
static
|
|
35
|
-
|
|
36
|
-
let t = e;
|
|
37
|
-
return s && (t = s.serialize(t)), (0, _stringify.stringify)(t, r?.spaces ?? 2);
|
|
34
|
+
static stringify(r) {
|
|
35
|
+
return StormJSON.instance.stringify(r);
|
|
38
36
|
}
|
|
39
|
-
static
|
|
37
|
+
static stringifyJson(r) {
|
|
38
|
+
return StormJSON.instance.stringify(r);
|
|
39
|
+
}
|
|
40
|
+
static parseJson(r, e) {
|
|
40
41
|
try {
|
|
41
|
-
if (
|
|
42
|
+
if (e?.expectComments === !1) return StormJSON.instance.parse(r);
|
|
42
43
|
} catch {}
|
|
43
44
|
const s = [],
|
|
44
|
-
|
|
45
|
+
i = {
|
|
45
46
|
allowTrailingComma: !0,
|
|
46
|
-
...
|
|
47
|
+
...e
|
|
47
48
|
},
|
|
48
|
-
|
|
49
|
-
if (s.length > 0 && s[0]) throw new Error((0, _parseError.formatParseError)(
|
|
50
|
-
return
|
|
49
|
+
n = (0, _jsoncParser.parse)(r, s, i);
|
|
50
|
+
if (s.length > 0 && s[0]) throw new Error((0, _parseError.formatParseError)(r, s[0]));
|
|
51
|
+
return n;
|
|
51
52
|
}
|
|
52
|
-
static register(
|
|
53
|
+
static register(r, e, s, i) {
|
|
53
54
|
StormJSON.instance.registerCustom({
|
|
54
|
-
isApplicable:
|
|
55
|
-
serialize:
|
|
55
|
+
isApplicable: i,
|
|
56
|
+
serialize: e,
|
|
56
57
|
deserialize: s
|
|
57
|
-
},
|
|
58
|
+
}, r);
|
|
58
59
|
}
|
|
59
|
-
static registerClass(
|
|
60
|
-
StormJSON.instance.registerClass(
|
|
61
|
-
identifier: (0, _isString.isString)(
|
|
62
|
-
allowProps:
|
|
60
|
+
static registerClass(r, e) {
|
|
61
|
+
StormJSON.instance.registerClass(r, {
|
|
62
|
+
identifier: (0, _isString.isString)(e) ? e : e?.identifier || r.name,
|
|
63
|
+
allowProps: e && (0, _isObject.isObject)(e) && e?.allowProps && Array.isArray(e.allowProps) ? e.allowProps : ["__typename"]
|
|
63
64
|
});
|
|
64
65
|
}
|
|
65
66
|
constructor() {
|
|
@@ -70,7 +71,7 @@ class StormJSON extends _superjson.default {
|
|
|
70
71
|
}
|
|
71
72
|
exports.StormJSON = StormJSON;
|
|
72
73
|
StormJSON.instance.registerCustom({
|
|
73
|
-
isApplicable:
|
|
74
|
-
serialize:
|
|
75
|
-
deserialize:
|
|
74
|
+
isApplicable: t => _buffer.Buffer.isBuffer(t),
|
|
75
|
+
serialize: t => t.toString("base64"),
|
|
76
|
+
deserialize: t => _buffer.Buffer.from(t, "base64")
|
|
76
77
|
}, "Bytes");
|
package/dist/storm-json.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import type { Class, JsonParseOptions, JsonParserResult, JsonValue } from "./types";
|
|
1
2
|
import SuperJSON from "superjson";
|
|
2
|
-
import type { Class, JsonParseOptions, JsonParserResult, JsonSerializeOptions, JsonValue } from "./types";
|
|
3
3
|
/**
|
|
4
4
|
* A static JSON parser class used by Storm Software to serialize and deserialize JSON data
|
|
5
5
|
*
|
|
@@ -30,16 +30,22 @@ export declare class StormJSON extends SuperJSON {
|
|
|
30
30
|
* Stringify the given value with superjson
|
|
31
31
|
*
|
|
32
32
|
*/
|
|
33
|
+
static stringifyMin(obj: any): string;
|
|
34
|
+
/**
|
|
35
|
+
* Stringify the given value with superjson
|
|
36
|
+
*
|
|
37
|
+
* @param obj - The object to stringify
|
|
38
|
+
* @returns The stringified object
|
|
39
|
+
*/
|
|
33
40
|
static stringify(obj: any): string;
|
|
34
41
|
/**
|
|
35
42
|
* Serializes the given data to a JSON string.
|
|
36
43
|
* By default the JSON string is formatted with a 2 space indentation to be easy readable.
|
|
37
44
|
*
|
|
38
45
|
* @param json - Object which should be serialized to JSON
|
|
39
|
-
* @param options - JSON serialize options
|
|
40
46
|
* @returns the formatted JSON representation of the object
|
|
41
47
|
*/
|
|
42
|
-
static stringifyJson(json: any
|
|
48
|
+
static stringifyJson(json: any): string;
|
|
43
49
|
/**
|
|
44
50
|
* Parses the given JSON string and returns the object the JSON content represents.
|
|
45
51
|
* 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 c}from"@stryke/types/type-checks/is-string";import{Buffer as a}from"buffer/";import{parse as l}from"jsonc-parser";import u from"superjson";import{formatParseError as p}from"./utils/parse-error";import{stringifyMin as f}from"./utils/stringify-min";export class StormJSON extends u{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 stringifyMin(r){const e=StormJSON.instance.customTransformerRegistry.findApplicable(r);let s=r;return e&&(s=e.serialize(s)),f(s)}static stringify(r){return StormJSON.instance.stringify(r)}static stringifyJson(r){return StormJSON.instance.stringify(r)}static parseJson(r,e){try{if(e?.expectComments===!1)return StormJSON.instance.parse(r)}catch{}const s=[],i={allowTrailingComma:!0,...e},n=l(r,s,i);if(s.length>0&&s[0])throw new Error(p(r,s[0]));return n}static register(r,e,s,i){StormJSON.instance.registerCustom({isApplicable:i,serialize:e,deserialize:s},r)}static registerClass(r,e){StormJSON.instance.registerClass(r,{identifier:c(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:t=>a.isBuffer(t),serialize:t=>t.toString("base64"),deserialize:t=>a.from(t,"base64")},"Bytes");
|
|
@@ -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 _stringifyMin = require("./stringify-min.cjs");
|
|
29
|
+
Object.keys(_stringifyMin).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] === _stringifyMin[key]) return;
|
|
32
32
|
Object.defineProperty(exports, key, {
|
|
33
33
|
enumerable: true,
|
|
34
34
|
get: function () {
|
|
35
|
-
return
|
|
35
|
+
return _stringifyMin[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-min";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
|
`}
|
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.stringifyMin = void 0;
|
|
7
7
|
var _isNumber = require("@stryke/types/type-checks/is-number");
|
|
8
|
-
const
|
|
9
|
-
const
|
|
8
|
+
const stringifyMin = (r, n = " ") => {
|
|
9
|
+
const t = (0, _isNumber.isNumber)(n) ? " ".repeat(n) : n;
|
|
10
10
|
switch (r) {
|
|
11
11
|
case null:
|
|
12
12
|
return "!n";
|
|
@@ -17,8 +17,8 @@ const stringify = (r, t = " ") => {
|
|
|
17
17
|
case !1:
|
|
18
18
|
return "!f";
|
|
19
19
|
}
|
|
20
|
-
if (Array.isArray(r)) return `[${
|
|
21
|
-
if (r instanceof Uint8Array) return
|
|
20
|
+
if (Array.isArray(r)) return `[${t}${r.map(e => stringifyMin(e, t)).join(`,${t}`)}${t}]`;
|
|
21
|
+
if (r instanceof Uint8Array) return r.toString();
|
|
22
22
|
switch (typeof r) {
|
|
23
23
|
case "number":
|
|
24
24
|
return `${r}`;
|
|
@@ -27,9 +27,10 @@ const stringify = (r, t = " ") => {
|
|
|
27
27
|
case "object":
|
|
28
28
|
{
|
|
29
29
|
const e = Object.keys(r);
|
|
30
|
-
return `{${
|
|
30
|
+
return `{${t}${e.map(s => `${s}${t}=${t}${stringifyMin(r[s], t)}`).join(`,${t}`)}${t}}`;
|
|
31
31
|
}
|
|
32
|
+
default:
|
|
33
|
+
return "?";
|
|
32
34
|
}
|
|
33
|
-
return "?";
|
|
34
35
|
};
|
|
35
|
-
exports.
|
|
36
|
+
exports.stringifyMin = stringifyMin;
|
|
@@ -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 stringifyMin: (value: unknown, spacing?: string | number) => string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{isNumber as i}from"@stryke/types/type-checks/is-number";export const stringifyMin=(r,n=" ")=>{const t=i(n)?" ".repeat(n):n;switch(r){case null:return"!n";case void 0:return"!u";case!0:return"!t";case!1:return"!f"}if(Array.isArray(r))return`[${t}${r.map(e=>stringifyMin(e,t)).join(`,${t}`)}${t}]`;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`{${t}${e.map(s=>`${s}${t}=${t}${stringifyMin(r[s],t)}`).join(`,${t}`)}${t}}`}default:return"?"}};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stryke/json",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
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-min": {
|
|
110
110
|
"import": {
|
|
111
|
-
"types": "./dist/utils/stringify.d.ts",
|
|
112
|
-
"default": "./dist/utils/stringify.mjs"
|
|
111
|
+
"types": "./dist/utils/stringify-min.d.ts",
|
|
112
|
+
"default": "./dist/utils/stringify-min.mjs"
|
|
113
113
|
},
|
|
114
114
|
"require": {
|
|
115
|
-
"types": "./dist/utils/stringify.d.ts",
|
|
116
|
-
"default": "./dist/utils/stringify.cjs"
|
|
115
|
+
"types": "./dist/utils/stringify-min.d.ts",
|
|
116
|
+
"default": "./dist/utils/stringify-min.cjs"
|
|
117
117
|
},
|
|
118
118
|
"default": {
|
|
119
|
-
"types": "./dist/utils/stringify.d.ts",
|
|
120
|
-
"default": "./dist/utils/stringify.mjs"
|
|
119
|
+
"types": "./dist/utils/stringify-min.d.ts",
|
|
120
|
+
"default": "./dist/utils/stringify-min.mjs"
|
|
121
121
|
}
|
|
122
122
|
},
|
|
123
123
|
"./utils/parse-error": {
|
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"?"};
|