@spyglassmc/json 0.3.5 → 0.3.7
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/lib/formatter/index.js +2 -1
- package/lib/node/JsonAstNode.d.ts +3 -2
- package/lib/parser/array.js +7 -12
- package/lib/parser/boolean.js +1 -1
- package/lib/parser/number.js +20 -7
- package/lib/parser/object.js +11 -13
- package/lib/parser/string.js +1 -6
- package/package.json +3 -3
package/lib/formatter/index.js
CHANGED
|
@@ -21,11 +21,12 @@ const object = (node, ctx) => {
|
|
|
21
21
|
});
|
|
22
22
|
return `{\n${fields.join(',\n')}\n${ctx.indent()}}`;
|
|
23
23
|
};
|
|
24
|
+
const number = (node, ctx) => ctx.meta.getFormatter(node.value.type)(node.value, ctx);
|
|
24
25
|
export function register(meta) {
|
|
25
26
|
meta.registerFormatter('json:array', array);
|
|
26
27
|
meta.registerFormatter('json:boolean', core.formatter.boolean);
|
|
27
28
|
meta.registerFormatter('json:null', () => 'null');
|
|
28
|
-
meta.registerFormatter('json:number',
|
|
29
|
+
meta.registerFormatter('json:number', number);
|
|
29
30
|
meta.registerFormatter('json:object', object);
|
|
30
31
|
meta.registerFormatter('json:string', core.formatter.string);
|
|
31
32
|
}
|
|
@@ -71,9 +71,10 @@ export declare namespace JsonStringNode {
|
|
|
71
71
|
export interface JsonNumberExpectation extends JsonBaseExpectation {
|
|
72
72
|
readonly type: 'json:number';
|
|
73
73
|
}
|
|
74
|
-
export interface JsonNumberNode extends core.
|
|
74
|
+
export interface JsonNumberNode extends JsonBaseAstNode, core.AstNode {
|
|
75
75
|
readonly type: 'json:number';
|
|
76
|
-
readonly
|
|
76
|
+
readonly children: [core.LongNode | core.FloatNode];
|
|
77
|
+
readonly value: core.LongNode | core.FloatNode;
|
|
77
78
|
}
|
|
78
79
|
export declare namespace JsonNumberNode {
|
|
79
80
|
function is(obj: object): obj is JsonNumberNode;
|
package/lib/parser/array.js
CHANGED
|
@@ -1,15 +1,10 @@
|
|
|
1
1
|
import * as core from '@spyglassmc/core';
|
|
2
2
|
import { entry } from './entry.js';
|
|
3
|
-
export const array = (
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
});
|
|
11
|
-
const ans = parser(src, ctx);
|
|
12
|
-
ans.type = 'json:array';
|
|
13
|
-
return ans;
|
|
14
|
-
};
|
|
3
|
+
export const array = (ctx, src) => core.setType('json:array', core.list({
|
|
4
|
+
start: '[',
|
|
5
|
+
value: entry,
|
|
6
|
+
sep: ',',
|
|
7
|
+
trailingSep: false,
|
|
8
|
+
end: ']',
|
|
9
|
+
}))(ctx, src);
|
|
15
10
|
//# sourceMappingURL=array.js.map
|
package/lib/parser/boolean.js
CHANGED
package/lib/parser/number.js
CHANGED
|
@@ -1,11 +1,24 @@
|
|
|
1
1
|
import * as core from '@spyglassmc/core';
|
|
2
2
|
export const number = (src, ctx) => {
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
3
|
+
const value = core.select([
|
|
4
|
+
{
|
|
5
|
+
regex: /^-?(?:0|[1-9]\d*)(?!\d|[.eE])/,
|
|
6
|
+
parser: core.long({
|
|
7
|
+
pattern: /^-?(?:0|[1-9]\d*)$/,
|
|
8
|
+
}),
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
parser: core.float({
|
|
12
|
+
// Regex form of the chart from https://www.json.org.
|
|
13
|
+
pattern: /^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][-+]?\d+)?$/,
|
|
14
|
+
}),
|
|
15
|
+
},
|
|
16
|
+
])(src, ctx);
|
|
17
|
+
return {
|
|
18
|
+
type: 'json:number',
|
|
19
|
+
children: [value],
|
|
20
|
+
value: value,
|
|
21
|
+
range: value.range,
|
|
22
|
+
};
|
|
10
23
|
};
|
|
11
24
|
//# sourceMappingURL=number.js.map
|
package/lib/parser/object.js
CHANGED
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
import * as core from '@spyglassmc/core';
|
|
2
2
|
import { entry } from './entry.js';
|
|
3
3
|
import { string } from './string.js';
|
|
4
|
-
export const object = (src, ctx) => {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}))(src, ctx);
|
|
16
|
-
};
|
|
4
|
+
export const object = (src, ctx) => core.setType('json:object', core.record({
|
|
5
|
+
start: '{',
|
|
6
|
+
pair: {
|
|
7
|
+
key: string,
|
|
8
|
+
sep: ':',
|
|
9
|
+
value: entry,
|
|
10
|
+
end: ',',
|
|
11
|
+
trailingEnd: false,
|
|
12
|
+
},
|
|
13
|
+
end: '}',
|
|
14
|
+
}))(src, ctx);
|
|
17
15
|
//# sourceMappingURL=object.js.map
|
package/lib/parser/string.js
CHANGED
|
@@ -6,10 +6,5 @@ export const JsonStringOptions = {
|
|
|
6
6
|
},
|
|
7
7
|
quotes: ['"'],
|
|
8
8
|
};
|
|
9
|
-
export const string = (src, ctx) =>
|
|
10
|
-
const parser = core.string(JsonStringOptions);
|
|
11
|
-
const ans = parser(src, ctx);
|
|
12
|
-
ans.type = 'json:string';
|
|
13
|
-
return ans;
|
|
14
|
-
};
|
|
9
|
+
export const string = (src, ctx) => core.setType('json:string', core.string(JsonStringOptions))(src, ctx);
|
|
15
10
|
//# sourceMappingURL=string.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spyglassmc/json",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.7",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"url": "https://github.com/SpyglassMC/Spyglass/issues"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@spyglassmc/core": "0.4.
|
|
29
|
-
"@spyglassmc/locales": "0.3.
|
|
28
|
+
"@spyglassmc/core": "0.4.5",
|
|
29
|
+
"@spyglassmc/locales": "0.3.5"
|
|
30
30
|
}
|
|
31
31
|
}
|