@spyglassmc/json 0.3.2 → 0.3.3

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.
@@ -4,5 +4,5 @@ export interface JsonCheckerContext extends CheckerContext {
4
4
  context: string;
5
5
  depth?: number;
6
6
  }
7
- export declare type JsonChecker = (node: JsonNode, ctx: JsonCheckerContext) => void;
7
+ export type JsonChecker = (node: JsonNode, ctx: JsonCheckerContext) => void;
8
8
  //# sourceMappingURL=JsonChecker.d.ts.map
@@ -1,7 +1,7 @@
1
1
  import type { JsonNode } from '../../node/index.js';
2
2
  import type { JsonChecker, JsonCheckerContext } from '../JsonChecker.js';
3
3
  export declare function listOf(checker: JsonChecker): JsonChecker;
4
- declare type UniqueListOptions = {
4
+ type UniqueListOptions = {
5
5
  items?: (node: JsonNode) => [string | undefined, JsonNode];
6
6
  report?: (node: JsonNode, ctx: JsonCheckerContext) => unknown;
7
7
  };
@@ -1,19 +1,19 @@
1
1
  import type { PairNode } from '@spyglassmc/core';
2
2
  import type { JsonNode, JsonStringNode } from '../../node/index.js';
3
3
  import type { JsonChecker, JsonCheckerContext } from '../JsonChecker.js';
4
- declare type JsonValue = string | number | boolean | null | JsonValue[] | {
4
+ type JsonValue = string | number | boolean | null | JsonValue[] | {
5
5
  [key: string]: JsonValue;
6
6
  };
7
- declare type ComplexProperty = {
7
+ type ComplexProperty = {
8
8
  checker: JsonChecker;
9
9
  opt?: boolean;
10
10
  def?: JsonValue;
11
11
  deprecated?: boolean;
12
12
  context?: string;
13
13
  };
14
- declare type CheckerProperty = JsonChecker | ComplexProperty;
15
- declare type CheckerRecord = Record<string, CheckerProperty | undefined>;
16
- declare type ObjectCheckerOptions = {
14
+ type CheckerProperty = JsonChecker | ComplexProperty;
15
+ type CheckerRecord = Record<string, CheckerProperty | undefined>;
16
+ type ObjectCheckerOptions = {
17
17
  allowUnknownProperties?: boolean;
18
18
  };
19
19
  export declare function object(): JsonChecker;
@@ -13,7 +13,8 @@ export function object(keys, values, options = {}) {
13
13
  const fields = keys
14
14
  .map((key) => [key, values(key, ctx)])
15
15
  .filter(([_, v]) => v !== undefined);
16
- node.expectation[0].fields = fields.map(([key, prop]) => {
16
+ node.expectation[0].fields = fields
17
+ .map(([key, prop]) => {
17
18
  return {
18
19
  key,
19
20
  value: expectation(isComplex(prop) ? prop.checker : prop, ctx),
@@ -77,9 +78,10 @@ export function object(keys, values, options = {}) {
77
78
  const typedoc = propNode.expectation
78
79
  ?.map((e) => e.typedoc)
79
80
  .join(' | ');
80
- prop.key.hover = `\`\`\`typescript\n${context}.${key}: ${typedoc}\n\`\`\`${doc || defaultValue !== undefined ? '\n******\n ' : ''}${doc}${defaultValue !== undefined
81
- ? `\n\`@default\` ${JSON.stringify(defaultValue)}`
82
- : ''}`;
81
+ prop.key.hover =
82
+ `\`\`\`typescript\n${context}.${key}: ${typedoc}\n\`\`\`${doc || defaultValue !== undefined ? '\n******\n ' : ''}${doc}${defaultValue !== undefined
83
+ ? `\n\`@default\` ${JSON.stringify(defaultValue)}`
84
+ : ''}`;
83
85
  });
84
86
  }
85
87
  else if (typeof keys === 'function' && values) {
@@ -172,7 +174,8 @@ export function extractNested(wrap, value, children) {
172
174
  const wrapper = children?.find((p) => p.key?.value === wrap);
173
175
  if (wrapper?.value?.type !== 'json:object')
174
176
  return undefined;
175
- const node = wrapper.children?.find((p) => p.key?.value === value);
177
+ const node = wrapper.children?.find((p) => p.key?.value ===
178
+ value);
176
179
  return node?.type === 'json:string' ? node.value : undefined;
177
180
  }
178
181
  export function extractStringArray(value, children) {
@@ -3,7 +3,7 @@ import type { JsonExpectation, JsonNode } from '../../node/index.js';
3
3
  import type { JsonChecker, JsonCheckerContext } from '../JsonChecker.js';
4
4
  export declare function ref(checker: () => JsonChecker): JsonChecker;
5
5
  export declare function as(context: string, checker: JsonChecker): JsonChecker;
6
- export declare type AttemptResult = {
6
+ export type AttemptResult = {
7
7
  totalErrorSpan: number;
8
8
  maxSeverity: ErrorSeverity;
9
9
  expectation?: JsonExpectation[];
@@ -41,7 +41,8 @@ export function any(checkers = []) {
41
41
  }
42
42
  const attempts = checkers
43
43
  .map((checker) => attempt(checker, node, ctx))
44
- .sort((a, b) => a.maxSeverity - b.maxSeverity || a.totalErrorSpan - b.totalErrorSpan);
44
+ .sort((a, b) => a.maxSeverity - b.maxSeverity ||
45
+ a.totalErrorSpan - b.totalErrorSpan);
45
46
  const sameTypeAttempts = attempts.filter((a) => a.expectation?.map((e) => e.type).includes(node.type));
46
47
  const allExpectations = attempts
47
48
  .filter((a) => a.expectation)
@@ -1,7 +1,7 @@
1
1
  import type { DeepReadonly, ItemNode, PairNode } from '@spyglassmc/core';
2
2
  import * as core from '@spyglassmc/core';
3
- export declare type JsonNode = JsonObjectNode | JsonArrayNode | JsonStringNode | JsonNumberNode | JsonBooleanNode | JsonNullNode;
4
- export declare type JsonRelatedNode = JsonNode | JsonPairNode | JsonItemNode;
3
+ export type JsonNode = JsonObjectNode | JsonArrayNode | JsonStringNode | JsonNumberNode | JsonBooleanNode | JsonNullNode;
4
+ export type JsonRelatedNode = JsonNode | JsonPairNode | JsonItemNode;
5
5
  export declare namespace JsonNode {
6
6
  function is(node: core.AstNode): node is JsonNode;
7
7
  function isRelated(node: core.AstNode): node is JsonRelatedNode;
@@ -9,7 +9,7 @@ export declare namespace JsonNode {
9
9
  interface JsonBaseAstNode {
10
10
  expectation?: JsonExpectation[];
11
11
  }
12
- export declare type JsonExpectation = JsonObjectExpectation | JsonArrayExpectation | JsonStringExpectation | JsonNumberExpectation | JsonBooleanExpectation;
12
+ export type JsonExpectation = JsonObjectExpectation | JsonArrayExpectation | JsonStringExpectation | JsonNumberExpectation | JsonBooleanExpectation;
13
13
  export declare namespace JsonExpectation {
14
14
  function isArray(e: DeepReadonly<JsonExpectation>): e is DeepReadonly<JsonArrayExpectation>;
15
15
  function isObject(e: DeepReadonly<JsonExpectation>): e is DeepReadonly<JsonObjectExpectation>;
@@ -35,7 +35,7 @@ export declare namespace JsonObjectNode {
35
35
  function is(obj: object | undefined): obj is JsonObjectNode;
36
36
  function mock(range: core.RangeLike): JsonObjectNode;
37
37
  }
38
- export declare type JsonPairNode = PairNode<JsonStringNode, JsonNode>;
38
+ export type JsonPairNode = PairNode<JsonStringNode, JsonNode>;
39
39
  export declare namespace JsonPairNode {
40
40
  function is(obj: object): obj is JsonPairNode;
41
41
  }
@@ -50,7 +50,7 @@ export declare namespace JsonArrayNode {
50
50
  function is(obj: object | undefined): obj is JsonArrayNode;
51
51
  function mock(range: core.RangeLike): JsonArrayNode;
52
52
  }
53
- export declare type JsonItemNode = ItemNode<JsonNode>;
53
+ export type JsonItemNode = ItemNode<JsonNode>;
54
54
  export declare namespace JsonItemNode {
55
55
  function is(obj: object): obj is JsonItemNode;
56
56
  }
@@ -27,7 +27,10 @@ export function json(dumpErrors = false) {
27
27
  parser: boolean,
28
28
  },
29
29
  { predicate: (src) => src.tryPeek('null'), parser: null_ },
30
- { predicate: (src) => LegalNumberStart.has(src.peek()), parser: number },
30
+ {
31
+ predicate: (src) => LegalNumberStart.has(src.peek()),
32
+ parser: number,
33
+ },
31
34
  { predicate: (src) => src.tryPeek('{'), parser: object },
32
35
  { parser: string },
33
36
  ])(src, ctx);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spyglassmc/json",
3
- "version": "0.3.2",
3
+ "version": "0.3.3",
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.1",
29
- "@spyglassmc/locales": "0.3.1"
28
+ "@spyglassmc/core": "0.4.2",
29
+ "@spyglassmc/locales": "0.3.2"
30
30
  }
31
31
  }