@spyglassmc/json 0.3.15 → 0.3.17

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.
@@ -1,5 +1,9 @@
1
1
  import * as core from '@spyglassmc/core';
2
2
  import { indentFormatter } from '@spyglassmc/core';
3
+ const file = (node, ctx) => {
4
+ const child = node.children[0];
5
+ return ctx.meta.getFormatter(child.type)(child, ctx);
6
+ };
3
7
  const array = (node, ctx) => {
4
8
  if (node.children.length === 0) {
5
9
  return '[]';
@@ -16,20 +20,27 @@ const object = (node, ctx) => {
16
20
  return '{}';
17
21
  }
18
22
  const fields = node.children.map((child) => {
19
- const key = child.key && core.formatter.string(child.key, ctx);
23
+ const key = child.key && string(child.key, ctx);
20
24
  const value = child.value
21
25
  && ctx.meta.getFormatter(child.value.type)(child.value, indentFormatter(ctx));
22
26
  return `${ctx.indent(1)}${key ?? ''}: ${value ?? ''}`;
23
27
  });
24
28
  return `{\n${fields.join(',\n')}\n${ctx.indent()}}`;
25
29
  };
26
- const number = (node, ctx) => ctx.meta.getFormatter(node.value.type)(node.value, ctx);
30
+ const number = (node, ctx) => {
31
+ return ctx.meta.getFormatter(node.value.type)(node.value, ctx);
32
+ };
33
+ const string = (node, ctx) => {
34
+ // TODO: Use core.formatter.string when it correctly escapes the string
35
+ return JSON.stringify(node.value);
36
+ };
27
37
  export function register(meta) {
38
+ meta.registerFormatter('json:file', file);
28
39
  meta.registerFormatter('json:array', array);
29
40
  meta.registerFormatter('json:boolean', core.formatter.boolean);
30
41
  meta.registerFormatter('json:null', () => 'null');
31
42
  meta.registerFormatter('json:number', number);
32
43
  meta.registerFormatter('json:object', object);
33
- meta.registerFormatter('json:string', core.formatter.string);
44
+ meta.registerFormatter('json:string', string);
34
45
  }
35
46
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spyglassmc/json",
3
- "version": "0.3.15",
3
+ "version": "0.3.17",
4
4
  "type": "module",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -25,8 +25,8 @@
25
25
  "url": "https://github.com/SpyglassMC/Spyglass/issues"
26
26
  },
27
27
  "dependencies": {
28
- "@spyglassmc/core": "0.4.13",
29
- "@spyglassmc/locales": "0.3.8",
30
- "@spyglassmc/mcdoc": "0.3.16"
28
+ "@spyglassmc/core": "0.4.15",
29
+ "@spyglassmc/locales": "0.3.9",
30
+ "@spyglassmc/mcdoc": "0.3.18"
31
31
  }
32
32
  }