@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 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
- [![Version](https://img.shields.io/badge/version-0.0.1-1fb2a6.svg?style=for-the-badge&color=1fb2a6)](https://prettier.io/)&nbsp;[![Nx](https://img.shields.io/badge/Nx-17.0.2-lightgrey?style=for-the-badge&logo=nx&logoWidth=20&&color=1fb2a6)](http://nx.dev/)&nbsp;[![NextJs](https://img.shields.io/badge/Next.js-14.0.2-lightgrey?style=for-the-badge&logo=nextdotjs&logoWidth=20&color=1fb2a6)](https://nextjs.org/)&nbsp;[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg?style=for-the-badge&logo=commitlint&color=1fb2a6)](http://commitizen.github.io/cz-cli/)&nbsp;![Semantic-Release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=for-the-badge&color=1fb2a6)&nbsp;[![documented with Fumadocs](https://img.shields.io/badge/documented_with-fumadocs-success.svg?style=for-the-badge&logo=readthedocs&color=1fb2a6)](https://fumadocs.vercel.app/)&nbsp;![GitHub Workflow Status (with event)](https://img.shields.io/github/actions/workflow/status/storm-software/stryke/cr.yml?style=for-the-badge&logo=github-actions&color=1fb2a6)
25
+ [![Version](https://img.shields.io/badge/version-0.1.4-1fb2a6.svg?style=for-the-badge&color=1fb2a6)](https://prettier.io/)&nbsp;[![Nx](https://img.shields.io/badge/Nx-17.0.2-lightgrey?style=for-the-badge&logo=nx&logoWidth=20&&color=1fb2a6)](http://nx.dev/)&nbsp;[![NextJs](https://img.shields.io/badge/Next.js-14.0.2-lightgrey?style=for-the-badge&logo=nextdotjs&logoWidth=20&color=1fb2a6)](https://nextjs.org/)&nbsp;[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg?style=for-the-badge&logo=commitlint&color=1fb2a6)](http://commitizen.github.io/cz-cli/)&nbsp;![Semantic-Release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=for-the-badge&color=1fb2a6)&nbsp;[![documented with Fumadocs](https://img.shields.io/badge/documented_with-fumadocs-success.svg?style=for-the-badge&logo=readthedocs&color=1fb2a6)](https://fumadocs.vercel.app/)&nbsp;![GitHub Workflow Status (with event)](https://img.shields.io/github/actions/workflow/status/storm-software/stryke/cr.yml?style=for-the-badge&logo=github-actions&color=1fb2a6)
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
- - [Stryke - JSON Utility](#stryke---json-utility)
59
- - [Table of Contents](#table-of-contents)
60
- - [Installing](#installing)
61
- - [Reduced Package Size](#reduced-package-size)
62
- - [Development](#development)
63
- - [Building](#building)
64
- - [Running unit tests](#running-unit-tests)
65
- - [Linting](#linting)
66
- - [Storm Workspaces](#storm-workspaces)
67
- - [Roadmap](#roadmap)
68
- - [Support](#support)
69
- - [License](#license)
70
- - [Changelog](#changelog)
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
 
@@ -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) ? "" : "/" + n.map(t => escapePointerSegment(String(t))).join("/");
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;
@@ -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)?"":"/"+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};
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};
@@ -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 _stringify = require("./utils/stringify.cjs");
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 #e;
16
+ static #r;
17
17
  static get instance() {
18
- return StormJSON.#e || (StormJSON.#e = new StormJSON()), StormJSON.#e;
18
+ return StormJSON.#r || (StormJSON.#r = new StormJSON()), StormJSON.#r;
19
19
  }
20
- static deserialize(e) {
21
- return StormJSON.instance.deserialize(e);
20
+ static deserialize(r) {
21
+ return StormJSON.instance.deserialize(r);
22
22
  }
23
- static serialize(e) {
24
- return StormJSON.instance.serialize(e);
23
+ static serialize(r) {
24
+ return StormJSON.instance.serialize(r);
25
25
  }
26
- static parse(e) {
27
- return StormJSON.instance.parse(e);
26
+ static parse(r) {
27
+ return StormJSON.instance.parse(r);
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);
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 stringifyJson(e, r) {
35
- const s = StormJSON.instance.customTransformerRegistry.findApplicable(e);
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 parseJson(e, r) {
37
+ static stringifyJson(r) {
38
+ return StormJSON.instance.stringify(r);
39
+ }
40
+ static parseJson(r, e) {
40
41
  try {
41
- if (r?.expectComments === !1) return StormJSON.instance.parse(e);
42
+ if (e?.expectComments === !1) return StormJSON.instance.parse(r);
42
43
  } catch {}
43
44
  const s = [],
44
- t = {
45
+ i = {
45
46
  allowTrailingComma: !0,
46
- ...r
47
+ ...e
47
48
  },
48
- o = (0, _jsoncParser.parse)(e, s, t);
49
- if (s.length > 0 && s[0]) throw new Error((0, _parseError.formatParseError)(e, s[0]));
50
- return o;
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(e, r, s, t) {
53
+ static register(r, e, s, i) {
53
54
  StormJSON.instance.registerCustom({
54
- isApplicable: t,
55
- serialize: r,
55
+ isApplicable: i,
56
+ serialize: e,
56
57
  deserialize: s
57
- }, e);
58
+ }, r);
58
59
  }
59
- static registerClass(e, r) {
60
- StormJSON.instance.registerClass(e, {
61
- identifier: (0, _isString.isString)(r) ? r : r?.identifier || e.name,
62
- allowProps: r && (0, _isObject.isObject)(r) && r?.allowProps && Array.isArray(r.allowProps) ? r.allowProps : ["__typename"]
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: i => _buffer.Buffer.isBuffer(i),
74
- serialize: i => i.toString("base64"),
75
- deserialize: i => _buffer.Buffer.from(i, "base64")
74
+ isApplicable: t => _buffer.Buffer.isBuffer(t),
75
+ serialize: t => t.toString("base64"),
76
+ deserialize: t => _buffer.Buffer.from(t, "base64")
76
77
  }, "Bytes");
@@ -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, options?: JsonSerializeOptions): string;
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.
@@ -1 +1 @@
1
- import{isObject as l}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 u}from"jsonc-parser";import p from"superjson";import{formatParseError as f}from"./utils/parse-error";import{stringify as n}from"./utils/stringify";export class StormJSON extends p{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){const r=StormJSON.instance.customTransformerRegistry.findApplicable(e);let s=e;return r&&(s=r.serialize(s)),n(s)}static stringifyJson(e,r){const s=StormJSON.instance.customTransformerRegistry.findApplicable(e);let t=e;return s&&(t=s.serialize(t)),n(t,r?.spaces??2)}static parseJson(e,r){try{if(r?.expectComments===!1)return StormJSON.instance.parse(e)}catch{}const s=[],t={allowTrailingComma:!0,...r},o=u(e,s,t);if(s.length>0&&s[0])throw new Error(f(e,s[0]));return o}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:c(r)?r:r?.identifier||e.name,allowProps:r&&l(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");
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 p = /\r\n|[\n\r\u2028\u2029]/;
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
- o = c.line,
22
+ i = c.line,
23
23
  t = c.column,
24
24
  b = m.line,
25
- i = m.column;
26
- let d = Math.max(o - (h + 1), 0),
25
+ o = m.column;
26
+ let d = Math.max(i - (h + 1), 0),
27
27
  u = Math.min(l.length, b + f);
28
- o === -1 && (d = 0), b === -1 && (u = l.length);
29
- const L = b - o,
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 + o;
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, i];else {
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 === i ? e[o] = t ? [t, 0] : !0 : e[o] = [t, i - 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(p),
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
- o = String(h).length;
55
- return (a.highlight ? a.highlight(s) : s).split(p).slice(m, h).map((i, d) => {
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(-o)} | `,
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 = i.slice(0, Math.max(n[0] - 1, 0)).replace(/[^\t]/g, " "),
63
- k = n[1] || 1;
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(k)].join("");
65
+ `, e.replace(/\d/g, " "), g, "^".repeat(p)].join("");
66
66
  }
67
- return [">", e, i, r].join("");
67
+ return [">", e, o, r].join("");
68
68
  }
69
- return ` ${e}${i}`;
69
+ return ` ${e}${o}`;
70
70
  }).join(`
71
71
  `);
72
72
  }
@@ -1,11 +1,11 @@
1
- type Location = {
1
+ interface Location {
2
2
  column: number;
3
3
  line: number;
4
- };
5
- type NodeLocation = {
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 p=/\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||{},o=c.line,t=c.column,b=m.line,i=m.column;let d=Math.max(o-(h+1),0),u=Math.min(l.length,b+f);o===-1&&(d=0),b===-1&&(u=l.length);const L=b-o,e={};if(L)for(let n=0;n<=L;n++){const r=n+o;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,i];else{const g=l[r-n]?.length??0;e[r]=[0,g]}}else t===i?e[o]=t?[t,0]:!0:e[o]=[t,i-t];return{start:d,end:u,markerLines:e}}export function codeFrameColumns(s,l,a={}){const c=s.split(p),{start:m,end:h,markerLines:f}=N(l,c,a),o=String(h).length;return(a.highlight?a.highlight(s):s).split(p).slice(m,h).map((i,d)=>{const u=m+1+d,e=` ${` ${u}`.slice(-o)} | `,n=!!(f[u]??!1);if(n){let r="";if(Array.isArray(n)){const g=i.slice(0,Math.max(n[0]-1,0)).replace(/[^\t]/g," "),k=n[1]||1;r=[`
2
- `,e.replace(/\d/g," "),g,"^".repeat(k)].join("")}return[">",e,i,r].join("")}return` ${e}${i}`}).join(`
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
  `)}
@@ -25,14 +25,14 @@ Object.keys(_parseError).forEach(function (key) {
25
25
  }
26
26
  });
27
27
  });
28
- var _stringify = require("./stringify.cjs");
29
- Object.keys(_stringify).forEach(function (key) {
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] === _stringify[key]) return;
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 _stringify[key];
35
+ return _stringifyMin[key];
36
36
  }
37
37
  });
38
38
  });
@@ -1,4 +1,4 @@
1
1
  export * from "./code-frames";
2
2
  export * from "./parse-error";
3
- export * from "./stringify";
3
+ export * from "./stringify-min";
4
4
  export * from "./strip-comments";
@@ -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(e, t) {
10
+ function formatParseError(n, t) {
11
11
  const {
12
- error: m,
13
- offset: s,
14
- length: l
15
- } = t;
16
- let n = new _linesAndColumns.LinesAndColumns(e).locationForIndex(s),
17
- r = n?.line ?? 0,
18
- o = n?.column ?? 0;
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
- ` + (0, _codeFrames.codeFrameColumns)(e, {
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(e,t){const{error:m,offset:s,length:l}=t;let n=new a(e).locationForIndex(s),r=n?.line??0,o=n?.column??0;return r++,o++,`${i(m)} in JSON at ${r}:${o}
2
- `+c(e,{start:{line:r,column:o},end:{line:r,column:o+l}})+`
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.stringify = void 0;
6
+ exports.stringifyMin = void 0;
7
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;
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 `[${n}${r.map(e => stringify(e, n)).join("," + n)}${n}]`;
21
- if (r instanceof Uint8Array) return `${r}`;
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 `{${n}${e.map(s => `${s}${n}=${n}${stringify(r[s], n)}`).join("," + n)}${n}}`;
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.stringify = stringify;
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 stringify: (value: unknown, spacing?: string | number) => string;
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.4",
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.2.1"
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": {
@@ -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"?"};