@stryke/json 0.7.3 → 0.8.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.
@@ -3,39 +3,40 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.stringify = void 0;
6
+ exports.stringify = exports.invalidKeyChars = void 0;
7
7
  var _isNumber = require("@stryke/type-checks/is-number");
8
8
  var _isUndefined = require("@stryke/type-checks/is-undefined");
9
- const stringify = (r, e = 2) => {
10
- const n = (0, _isNumber.isNumber)(e) ? " ".repeat(e) : e;
11
- switch (r) {
12
- case null:
13
- return "null";
14
- case void 0:
15
- return '"undefined"';
16
- case !0:
17
- return "true";
18
- case !1:
19
- return "false";
20
- case Number.POSITIVE_INFINITY:
21
- return "infinity";
22
- case Number.NEGATIVE_INFINITY:
23
- return "-infinity";
24
- }
25
- if (Array.isArray(r)) return `[${n}${r.map(i => stringify(i, n)).join(`,${n}`)}${n}]`;
26
- if (r instanceof Uint8Array) return r.toString();
27
- switch (typeof r) {
28
- case "number":
29
- return `${r}`;
30
- case "string":
31
- return JSON.stringify(r);
32
- case "object":
33
- {
34
- const i = Object.keys(r).filter(t => !(0, _isUndefined.isUndefined)(r[t]));
35
- return `{${n}${i.map(t => `${t}: ${n}${stringify(r[t], n)}`).join(`,${n}`)}${n}}`;
36
- }
37
- default:
38
- return "null";
39
- }
40
- };
9
+ const invalidKeyChars = exports.invalidKeyChars = ["@", "/", "#", "$", " ", '"', "'", "`", "{", "}", "[", "]", "(", ")", "<", ">"],
10
+ stringify = (r, e = 2) => {
11
+ const n = (0, _isNumber.isNumber)(e) ? " ".repeat(e) : e;
12
+ switch (r) {
13
+ case null:
14
+ return "null";
15
+ case void 0:
16
+ return '"undefined"';
17
+ case !0:
18
+ return "true";
19
+ case !1:
20
+ return "false";
21
+ case Number.POSITIVE_INFINITY:
22
+ return "infinity";
23
+ case Number.NEGATIVE_INFINITY:
24
+ return "-infinity";
25
+ }
26
+ if (Array.isArray(r)) return `[${n}${r.map(s => stringify(s, n)).join(`,${n}`)}${n}]`;
27
+ if (r instanceof Uint8Array) return r.toString();
28
+ switch (typeof r) {
29
+ case "number":
30
+ return `${r}`;
31
+ case "string":
32
+ return JSON.stringify(r);
33
+ case "object":
34
+ {
35
+ const s = Object.keys(r).filter(t => !(0, _isUndefined.isUndefined)(r[t]));
36
+ return `{${n}${s.map(t => `${invalidKeyChars.some(i => t.includes(i)) ? `"${t}"` : t}: ${n}${stringify(r[t], n)}`).join(`,${n}`)}${n}}`;
37
+ }
38
+ default:
39
+ return "null";
40
+ }
41
+ };
41
42
  exports.stringify = stringify;
@@ -1,3 +1,4 @@
1
+ export declare const invalidKeyChars: readonly ["@", "/", "#", "$", " ", "\"", "'", "`", "{", "}", "[", "]", "(", ")", "<", ">"];
1
2
  /**
2
3
  * Stringify a value to a JSON-like string.
3
4
  *
@@ -1 +1 @@
1
- import{isNumber as s}from"@stryke/type-checks/is-number";import{isUndefined as c}from"@stryke/type-checks/is-undefined";export const stringify=(r,e=2)=>{const n=s(e)?" ".repeat(e):e;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(i=>stringify(i,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 i=Object.keys(r).filter(t=>!c(r[t]));return`{${n}${i.map(t=>`${t}: ${n}${stringify(r[t],n)}`).join(`,${n}`)}${n}}`}default:return"null"}};
1
+ import{isNumber as c}from"@stryke/type-checks/is-number";import{isUndefined as o}from"@stryke/type-checks/is-undefined";export const invalidKeyChars=["@","/","#","$"," ",'"',"'","`","{","}","[","]","(",")","<",">"],stringify=(r,e=2)=>{const n=c(e)?" ".repeat(e):e;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(s=>stringify(s,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 s=Object.keys(r).filter(t=>!o(r[t]));return`{${n}${s.map(t=>`${invalidKeyChars.some(i=>t.includes(i))?`"${t}"`:t}: ${n}${stringify(r[t],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.7.3",
3
+ "version": "0.8.0",
4
4
  "type": "module",
5
5
  "description": "A package containing JSON parsing/stringify utilities used by Storm Software.",
6
6
  "repository": {