@isdk/json-repair 0.1.2 → 0.1.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.
- package/.prettierignore +8 -0
- package/CHANGELOG.md +16 -0
- package/README.cn.md +126 -14
- package/README.md +152 -14
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +207 -20
- package/dist/index.d.ts +207 -20
- package/dist/index.js +1 -1
- package/docs/README.md +152 -14
- package/docs/_media/README.cn.md +126 -14
- package/docs/classes/RepairParser.md +5 -5
- package/docs/classes/SchemaWalker.md +126 -6
- package/docs/functions/jsonRepair.md +1 -1
- package/docs/interfaces/RepairOptions.md +52 -19
- package/docs/type-aliases/JSONPath.md +1 -1
- package/eslint.config.mjs +60 -26
- package/package.json +13 -9
- package/setupVitest.mjs +1 -1
- package/tsconfig.json +9 -8
- package/tsconfig.release.json +21 -0
- package/tsup.config.ts +13 -9
- package/typedoc.config.cjs +3 -1
- package/vite.config.mjs +13 -8
- package/tsconfig.spec.json +0 -19
|
@@ -6,18 +6,38 @@
|
|
|
6
6
|
|
|
7
7
|
# Class: SchemaWalker
|
|
8
8
|
|
|
9
|
-
Defined in: [walker/schema-walker.ts:
|
|
9
|
+
Defined in: [walker/schema-walker.ts:9](https://github.com/isdk/json-repair.js/blob/bd999430e5a6ec831a040451c76463ff7791a09a/src/walker/schema-walker.ts#L9)
|
|
10
10
|
|
|
11
11
|
Navigates through a JSON Schema based on a JSON Path.
|
|
12
12
|
Handles $ref resolution and provides type information for specific paths.
|
|
13
13
|
|
|
14
14
|
## Methods
|
|
15
15
|
|
|
16
|
+
### declaredPropertyNames()
|
|
17
|
+
|
|
18
|
+
> **declaredPropertyNames**(`path`): `string`[]
|
|
19
|
+
|
|
20
|
+
Defined in: [walker/schema-walker.ts:130](https://github.com/isdk/json-repair.js/blob/bd999430e5a6ec831a040451c76463ff7791a09a/src/walker/schema-walker.ts#L130)
|
|
21
|
+
|
|
22
|
+
The property names the Schema declares at `path` (empty when the level is free-form).
|
|
23
|
+
|
|
24
|
+
#### Parameters
|
|
25
|
+
|
|
26
|
+
##### path
|
|
27
|
+
|
|
28
|
+
[`JSONPath`](../type-aliases/JSONPath.md)
|
|
29
|
+
|
|
30
|
+
#### Returns
|
|
31
|
+
|
|
32
|
+
`string`[]
|
|
33
|
+
|
|
34
|
+
***
|
|
35
|
+
|
|
16
36
|
### getExpectedTypes()
|
|
17
37
|
|
|
18
38
|
> **getExpectedTypes**(`path`, `key`): `string`[]
|
|
19
39
|
|
|
20
|
-
Defined in: [walker/schema-walker.ts:
|
|
40
|
+
Defined in: [walker/schema-walker.ts:176](https://github.com/isdk/json-repair.js/blob/bd999430e5a6ec831a040451c76463ff7791a09a/src/walker/schema-walker.ts#L176)
|
|
21
41
|
|
|
22
42
|
Gets the expected types for a specific property at a given path.
|
|
23
43
|
|
|
@@ -47,7 +67,7 @@ An array of expected type strings (e.g., ["string", "number"]).
|
|
|
47
67
|
|
|
48
68
|
> **getSchemaForPath**(`path`): `any`
|
|
49
69
|
|
|
50
|
-
Defined in: [walker/schema-walker.ts:
|
|
70
|
+
Defined in: [walker/schema-walker.ts:48](https://github.com/isdk/json-repair.js/blob/bd999430e5a6ec831a040451c76463ff7791a09a/src/walker/schema-walker.ts#L48)
|
|
51
71
|
|
|
52
72
|
Retrieves the sub-schema for a given JSON path.
|
|
53
73
|
|
|
@@ -67,11 +87,64 @@ The sub-schema at the specified path, or undefined if not found.
|
|
|
67
87
|
|
|
68
88
|
***
|
|
69
89
|
|
|
90
|
+
### hasDeclaredProperties()
|
|
91
|
+
|
|
92
|
+
> **hasDeclaredProperties**(`path`): `boolean`
|
|
93
|
+
|
|
94
|
+
Defined in: [walker/schema-walker.ts:164](https://github.com/isdk/json-repair.js/blob/bd999430e5a6ec831a040451c76463ff7791a09a/src/walker/schema-walker.ts#L164)
|
|
95
|
+
|
|
96
|
+
Whether the Schema at the given path declares any property names at all.
|
|
97
|
+
Used to decide whether key matching can be strict or has to stay lenient.
|
|
98
|
+
|
|
99
|
+
#### Parameters
|
|
100
|
+
|
|
101
|
+
##### path
|
|
102
|
+
|
|
103
|
+
[`JSONPath`](../type-aliases/JSONPath.md)
|
|
104
|
+
|
|
105
|
+
The current parent path.
|
|
106
|
+
|
|
107
|
+
#### Returns
|
|
108
|
+
|
|
109
|
+
`boolean`
|
|
110
|
+
|
|
111
|
+
***
|
|
112
|
+
|
|
113
|
+
### isDeclaredProperty()
|
|
114
|
+
|
|
115
|
+
> **isDeclaredProperty**(`path`, `key`): `boolean`
|
|
116
|
+
|
|
117
|
+
Defined in: [walker/schema-walker.ts:150](https://github.com/isdk/json-repair.js/blob/bd999430e5a6ec831a040451c76463ff7791a09a/src/walker/schema-walker.ts#L150)
|
|
118
|
+
|
|
119
|
+
Whether a property name is explicitly declared in the Schema at the given path.
|
|
120
|
+
|
|
121
|
+
#### Parameters
|
|
122
|
+
|
|
123
|
+
##### path
|
|
124
|
+
|
|
125
|
+
[`JSONPath`](../type-aliases/JSONPath.md)
|
|
126
|
+
|
|
127
|
+
The current parent path.
|
|
128
|
+
|
|
129
|
+
##### key
|
|
130
|
+
|
|
131
|
+
`string`
|
|
132
|
+
|
|
133
|
+
The property key to check.
|
|
134
|
+
|
|
135
|
+
#### Returns
|
|
136
|
+
|
|
137
|
+
`boolean`
|
|
138
|
+
|
|
139
|
+
True only when `key` appears in the Schema `properties` of that path.
|
|
140
|
+
|
|
141
|
+
***
|
|
142
|
+
|
|
70
143
|
### isValidProperty()
|
|
71
144
|
|
|
72
145
|
> **isValidProperty**(`path`, `key`): `boolean`
|
|
73
146
|
|
|
74
|
-
Defined in: [walker/schema-walker.ts:
|
|
147
|
+
Defined in: [walker/schema-walker.ts:75](https://github.com/isdk/json-repair.js/blob/bd999430e5a6ec831a040451c76463ff7791a09a/src/walker/schema-walker.ts#L75)
|
|
75
148
|
|
|
76
149
|
Determines if a property key is valid for the given path according to the Schema.
|
|
77
150
|
|
|
@@ -97,15 +170,56 @@ True if the property is defined in the Schema or allowed by additionalProperties
|
|
|
97
170
|
|
|
98
171
|
***
|
|
99
172
|
|
|
173
|
+
### matchProperty()
|
|
174
|
+
|
|
175
|
+
> **matchProperty**(`path`, `key`): `string` \| `null`
|
|
176
|
+
|
|
177
|
+
Defined in: [walker/schema-walker.ts:108](https://github.com/isdk/json-repair.js/blob/bd999430e5a6ec831a040451c76463ff7791a09a/src/walker/schema-walker.ts#L108)
|
|
178
|
+
|
|
179
|
+
Resolves an incoming property name to the name declared by the Schema at `path`.
|
|
180
|
+
|
|
181
|
+
Without `keyMatching` this only accepts an exact declaration. With `keyMatching: true`
|
|
182
|
+
the comparison ignores case and the separators used by the two common naming styles
|
|
183
|
+
(`user_name` / `userName` / `USER NAME`). A function matcher decides itself and may
|
|
184
|
+
return a name the Schema does not declare.
|
|
185
|
+
|
|
186
|
+
Besides renaming, the result is what makes a key a breakpoint for greedy string capture:
|
|
187
|
+
the parser calls this while deciding whether an upcoming `key:` ends the value in front of it.
|
|
188
|
+
|
|
189
|
+
#### Parameters
|
|
190
|
+
|
|
191
|
+
##### path
|
|
192
|
+
|
|
193
|
+
[`JSONPath`](../type-aliases/JSONPath.md)
|
|
194
|
+
|
|
195
|
+
The current parent path.
|
|
196
|
+
|
|
197
|
+
##### key
|
|
198
|
+
|
|
199
|
+
`string`
|
|
200
|
+
|
|
201
|
+
The property key found in the broken document.
|
|
202
|
+
|
|
203
|
+
#### Returns
|
|
204
|
+
|
|
205
|
+
`string` \| `null`
|
|
206
|
+
|
|
207
|
+
The canonical Schema property name, or `null` when nothing matches.
|
|
208
|
+
|
|
209
|
+
***
|
|
210
|
+
|
|
100
211
|
### create()
|
|
101
212
|
|
|
102
|
-
> `static` **create**(`schema`): `Promise`\<`SchemaWalker`\>
|
|
213
|
+
> `static` **create**(`schema`, `options?`): `Promise`\<`SchemaWalker`\>
|
|
103
214
|
|
|
104
|
-
Defined in: [walker/schema-walker.ts:
|
|
215
|
+
Defined in: [walker/schema-walker.ts:30](https://github.com/isdk/json-repair.js/blob/bd999430e5a6ec831a040451c76463ff7791a09a/src/walker/schema-walker.ts#L30)
|
|
105
216
|
|
|
106
217
|
Static factory method to create a SchemaWalker instance.
|
|
107
218
|
Asynchronously dereferences the provided JSON Schema.
|
|
108
219
|
|
|
220
|
+
The Schema is dereferenced on a deep copy: `$RefParser.dereference()` replaces every
|
|
221
|
+
`$ref` in place, which would otherwise rewrite the object the caller passed in.
|
|
222
|
+
|
|
109
223
|
#### Parameters
|
|
110
224
|
|
|
111
225
|
##### schema
|
|
@@ -114,6 +228,12 @@ Asynchronously dereferences the provided JSON Schema.
|
|
|
114
228
|
|
|
115
229
|
The JSON Schema object to walk.
|
|
116
230
|
|
|
231
|
+
##### options?
|
|
232
|
+
|
|
233
|
+
[`RepairOptions`](../interfaces/RepairOptions.md) = `{}`
|
|
234
|
+
|
|
235
|
+
Repair options that concern the Schema itself (`keyMatching`).
|
|
236
|
+
|
|
117
237
|
#### Returns
|
|
118
238
|
|
|
119
239
|
`Promise`\<`SchemaWalker`\>
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
> **jsonRepair**(`input`, `schema?`, `options?`): `Promise`\<`any`\>
|
|
10
10
|
|
|
11
|
-
Defined in: [repair.ts:21](https://github.com/isdk/json-repair.js/blob/
|
|
11
|
+
Defined in: [repair.ts:21](https://github.com/isdk/json-repair.js/blob/bd999430e5a6ec831a040451c76463ff7791a09a/src/repair.ts#L21)
|
|
12
12
|
|
|
13
13
|
Repairs and parses a JSON string generated by an LLM, guided by a JSON Schema.
|
|
14
14
|
This is the main entry point for the library.
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
# Interface: RepairOptions
|
|
8
8
|
|
|
9
|
-
Defined in: [types.ts:4](https://github.com/isdk/json-repair.js/blob/
|
|
9
|
+
Defined in: [types.ts:4](https://github.com/isdk/json-repair.js/blob/bd999430e5a6ec831a040451c76463ff7791a09a/src/types.ts#L4)
|
|
10
10
|
|
|
11
11
|
Options for the JSON repair process.
|
|
12
12
|
|
|
@@ -14,50 +14,83 @@ Options for the JSON repair process.
|
|
|
14
14
|
|
|
15
15
|
### additionalProperties?
|
|
16
16
|
|
|
17
|
-
> `optional` **additionalProperties
|
|
17
|
+
> `optional` **additionalProperties?**: `"keep"` \| `"remove"`
|
|
18
18
|
|
|
19
|
-
Defined in: [types.ts:
|
|
19
|
+
Defined in: [types.ts:70](https://github.com/isdk/json-repair.js/blob/bd999430e5a6ec831a040451c76463ff7791a09a/src/types.ts#L70)
|
|
20
20
|
|
|
21
21
|
Defines how to handle properties not defined in the Schema.
|
|
22
22
|
|
|
23
23
|
- `'keep'` (default): Keeps these extra properties in the output.
|
|
24
|
-
- `'remove'`:
|
|
24
|
+
- `'remove'`: Drops them. Only applies at a level whose Schema declares `properties`;
|
|
25
|
+
a free-form level has no "extra" keys and is left untouched.
|
|
26
|
+
|
|
27
|
+
This option is independent from the JSON Schema keyword `additionalProperties: false`,
|
|
28
|
+
which is respected on its own when validating incoming keys.
|
|
25
29
|
|
|
26
30
|
***
|
|
27
31
|
|
|
28
32
|
### coerceTypes?
|
|
29
33
|
|
|
30
|
-
> `optional` **coerceTypes
|
|
34
|
+
> `optional` **coerceTypes?**: `boolean`
|
|
35
|
+
|
|
36
|
+
Defined in: [types.ts:58](https://github.com/isdk/json-repair.js/blob/bd999430e5a6ec831a040451c76463ff7791a09a/src/types.ts#L58)
|
|
37
|
+
|
|
38
|
+
Whether to coerce values to the type the Schema declares. Enabled by default.
|
|
31
39
|
|
|
32
|
-
|
|
40
|
+
- `true` (default): `"Approx. 1,200.50 USD"` becomes `1200.5`, `"yes"` becomes `true`,
|
|
41
|
+
`"Processing!"` becomes the enum entry it fuzzy matches, `12` becomes `"12"` when the
|
|
42
|
+
Schema says `type: 'string'`.
|
|
43
|
+
- `false`: values are returned exactly as they were parsed.
|
|
33
44
|
|
|
34
|
-
|
|
45
|
+
Coercion needs the Schema of the property the value belongs to; a level that declares
|
|
46
|
+
no types is left alone.
|
|
35
47
|
|
|
36
|
-
|
|
48
|
+
Coercing to a declared `string` reuses the text the document wrote, not the number it
|
|
49
|
+
parsed to, so a leading zero survives: `{ id: 01234 }` becomes `"01234"`.
|
|
50
|
+
`null` and structures (`{}` / `[]`) are never stringified - `"null"` and
|
|
51
|
+
`"[object Object]"` are not what a `type: 'string'` declaration asks for.
|
|
37
52
|
|
|
38
53
|
***
|
|
39
54
|
|
|
40
55
|
### keyMatching?
|
|
41
56
|
|
|
42
|
-
> `optional` **keyMatching
|
|
57
|
+
> `optional` **keyMatching?**: `boolean` \| ((`key`, `properties`) => `string` \| `undefined`)
|
|
43
58
|
|
|
44
|
-
Defined in: [types.ts:
|
|
59
|
+
Defined in: [types.ts:21](https://github.com/isdk/json-repair.js/blob/bd999430e5a6ec831a040451c76463ff7791a09a/src/types.ts#L21)
|
|
45
60
|
|
|
46
|
-
Fuzzy matching
|
|
61
|
+
Fuzzy matching of property keys against the Schema's declared `properties`.
|
|
47
62
|
|
|
48
|
-
- `false` (default):
|
|
49
|
-
- `true`:
|
|
50
|
-
|
|
63
|
+
- `false` (default): Only an exactly declared key counts as a match.
|
|
64
|
+
- `true`: Case-insensitive and separator-insensitive matching, so `user_name`,
|
|
65
|
+
`userName`, `USER-NAME` and `user name` all resolve to the declared key.
|
|
66
|
+
- `(key: string, properties: string[]) => string | undefined`: Custom mapping logic;
|
|
67
|
+
it receives the incoming key and the declared names, and returns the name to use
|
|
68
|
+
(or `undefined` to fall back to the incoming key).
|
|
69
|
+
|
|
70
|
+
A match renames the key to the Schema's name in the output and makes nested Schema
|
|
71
|
+
lookups (and therefore type coercion) work for it.
|
|
72
|
+
It also decides where greedy capture stops: with `true` a separator or case variant of a
|
|
73
|
+
declared key (`user_name:` for `userName`) ends the value in front of it.
|
|
74
|
+
When you reuse a `SchemaWalker`, pass this option to `SchemaWalker.create()`.
|
|
51
75
|
|
|
52
76
|
***
|
|
53
77
|
|
|
54
78
|
### stringCaptureStrategy?
|
|
55
79
|
|
|
56
|
-
> `optional` **stringCaptureStrategy
|
|
80
|
+
> `optional` **stringCaptureStrategy?**: `"conservative"` \| `"aggressive"`
|
|
81
|
+
|
|
82
|
+
Defined in: [types.ts:40](https://github.com/isdk/json-repair.js/blob/bd999430e5a6ec831a040451c76463ff7791a09a/src/types.ts#L40)
|
|
57
83
|
|
|
58
|
-
|
|
84
|
+
Strategy for greedy string capture when the strict JSON path failed for a value.
|
|
59
85
|
|
|
60
|
-
|
|
86
|
+
- `'aggressive'` (default): When the Schema declares property names for the current
|
|
87
|
+
level, the captured value only ends at one of those declared keys. Text that merely
|
|
88
|
+
looks like `"some words":` stays inside the value.
|
|
89
|
+
- `'conservative'`: Any text matching the `"key":` / `key:` pattern ends the value,
|
|
90
|
+
which keeps the structure of the document at the cost of cutting values short.
|
|
61
91
|
|
|
62
|
-
-
|
|
63
|
-
|
|
92
|
+
A whitespace-containing key the Schema declares is a breakpoint in both strategies even
|
|
93
|
+
when the document left it unquoted (`{ Capital: Berlin, Official language: Italian }`),
|
|
94
|
+
because it can only be recognised from the declaration.
|
|
95
|
+
Neither strategy affects values that were parsed by the strict JSON path; the
|
|
96
|
+
boundary rules described in the README apply to those unchanged.
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
> **JSONPath** = (`string` \| `number`)[]
|
|
10
10
|
|
|
11
|
-
Defined in: [types.ts:
|
|
11
|
+
Defined in: [types.ts:77](https://github.com/isdk/json-repair.js/blob/bd999430e5a6ec831a040451c76463ff7791a09a/src/types.ts#L77)
|
|
12
12
|
|
|
13
13
|
Represents the current path in a JSON structure.
|
|
14
14
|
A list of strings (keys) and numbers (indices).
|
package/eslint.config.mjs
CHANGED
|
@@ -1,31 +1,65 @@
|
|
|
1
|
-
import
|
|
2
|
-
import tsdoc from
|
|
3
|
-
import path from "node:path";
|
|
4
|
-
import { fileURLToPath } from "node:url";
|
|
5
|
-
import js from "@eslint/js";
|
|
6
|
-
import { FlatCompat } from "@eslint/eslintrc";
|
|
1
|
+
import antfu from '@antfu/eslint-config'
|
|
2
|
+
import tsdoc from 'eslint-plugin-tsdoc'
|
|
7
3
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
4
|
+
/**
|
|
5
|
+
* ESLint 只负责「正确性」,代码风格交给 prettier(见 package.json 的 format 脚本与 .prettierrc)。
|
|
6
|
+
*
|
|
7
|
+
* 这里沿用 ../ai-tool 的做法:用 @antfu 的配置作为底座,但整体关闭风格类与教条类插件层,
|
|
8
|
+
* 只保留指向真实 bug 的核心规则。想重新启用某一层,把对应的 `false` 改成 `true` 即可。
|
|
9
|
+
*/
|
|
10
|
+
const config = await antfu(
|
|
11
|
+
{
|
|
12
|
+
gitignore: true,
|
|
13
|
+
ignores: ['web/**', 'docs/**', 'dist/**', '.cache/**'],
|
|
15
14
|
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
// 风格类规则全部交给 prettier
|
|
16
|
+
stylistic: false,
|
|
17
|
+
// 以下插件层噪音太大,先整体关闭
|
|
18
|
+
regexp: false,
|
|
19
|
+
unicorn: false,
|
|
20
|
+
test: false,
|
|
21
|
+
imports: false,
|
|
22
|
+
jsonc: false,
|
|
23
|
+
yaml: false,
|
|
24
|
+
toml: false,
|
|
25
|
+
markdown: false,
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
plugins: { tsdoc },
|
|
29
|
+
rules: {
|
|
30
|
+
'tsdoc/syntax': 'off',
|
|
31
|
+
'antfu/no-top-level-await': 'off', // 测试文件里 top-level await 是正常写法
|
|
18
32
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
33
|
+
// 偏好类:不产生真实 bug,也不制造 diff
|
|
34
|
+
'prefer-const': 'off',
|
|
35
|
+
'prefer-template': 'off',
|
|
36
|
+
'object-shorthand': 'off',
|
|
37
|
+
'no-cond-assign': 'off', // 沿用旧配置:`while ((m = re.exec(s)))` 是惯用写法
|
|
38
|
+
'no-lone-blocks': 'off', // `case 'x': { … }; break;` 的花括号是刻意的
|
|
39
|
+
'unused-imports/no-unused-vars': 'off', // 未使用的函数参数多是签名占位
|
|
22
40
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
41
|
+
// TS 风格类
|
|
42
|
+
'ts/consistent-type-imports': 'off',
|
|
43
|
+
'ts/consistent-type-definitions': 'off',
|
|
44
|
+
'ts/no-use-before-define': 'off',
|
|
45
|
+
'ts/ban-ts-comment': 'off',
|
|
46
|
+
'ts/no-unused-expressions': 'off',
|
|
47
|
+
'ts/no-explicit-any': 'off', // 动态入参/出参本来就无静态类型(见 README 的 any 说明)
|
|
30
48
|
},
|
|
31
|
-
}
|
|
49
|
+
}
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
// ESLint 9 的 rules 通配符(如 `perfectionist/*`)只在 global config 生效,这里手动关掉整组噪音规则
|
|
53
|
+
const NOISE_GROUPS = ['perfectionist/', 'jsdoc/', 'node/', 'import/']
|
|
54
|
+
for (const item of config) {
|
|
55
|
+
if (!item.rules) {
|
|
56
|
+
continue
|
|
57
|
+
}
|
|
58
|
+
for (const name of Object.keys(item.rules)) {
|
|
59
|
+
if (NOISE_GROUPS.some((group) => name.startsWith(group))) {
|
|
60
|
+
item.rules[name] = 'off'
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export default config
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@isdk/json-repair",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "A powerful, schema-guided JSON repair library for fixing broken JSON generated by LLMs, featuring semantic coercion and fuzzy matching.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"json",
|
|
@@ -18,7 +18,10 @@
|
|
|
18
18
|
],
|
|
19
19
|
"author": "Riceball LEE <snowyu.lee@gmail.com>",
|
|
20
20
|
"homepage": "https://github.com/isdk/json-repair.js",
|
|
21
|
-
"repository":
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "https://github.com/isdk/json-repair.js"
|
|
24
|
+
},
|
|
22
25
|
"bugs": "https://github.com/@isdk/json-repair.js/issues",
|
|
23
26
|
"license": "MIT",
|
|
24
27
|
"main": "dist/index.js",
|
|
@@ -32,6 +35,7 @@
|
|
|
32
35
|
"lodash-es": "^4.17.23"
|
|
33
36
|
},
|
|
34
37
|
"devDependencies": {
|
|
38
|
+
"@antfu/eslint-config": "^4.19.0",
|
|
35
39
|
"@types/json-schema": "^7.0.15",
|
|
36
40
|
"@types/lodash-es": "^4.17.12",
|
|
37
41
|
"@types/node": "^25.1.0",
|
|
@@ -42,8 +46,8 @@
|
|
|
42
46
|
"terser": "^5.46.0",
|
|
43
47
|
"tsup": "^8.5.1",
|
|
44
48
|
"tsx": "^4.21.0",
|
|
45
|
-
"typedoc": "^0.28.
|
|
46
|
-
"typedoc-plugin-markdown": "^4.
|
|
49
|
+
"typedoc": "^0.28.20",
|
|
50
|
+
"typedoc-plugin-markdown": "^4.13.1",
|
|
47
51
|
"typescript": "~5.7.3",
|
|
48
52
|
"vite": "^7.3.1",
|
|
49
53
|
"vite-tsconfig-paths": "^6.0.5",
|
|
@@ -55,14 +59,14 @@
|
|
|
55
59
|
"clean": "rm -fr web docs dist",
|
|
56
60
|
"doc": "typedoc --plugin none --out web",
|
|
57
61
|
"doc:md": "typedoc --plugin typedoc-plugin-markdown --out docs",
|
|
58
|
-
"format": "
|
|
59
|
-
"format:
|
|
60
|
-
"format:fix": "pnpm run format:base --write",
|
|
62
|
+
"format": "prettier --check \"**/*.{md,json,jsonc,yaml,yml,ts,mjs,cjs}\"",
|
|
63
|
+
"format:fix": "prettier --write \"**/*.{md,json,jsonc,yaml,yml,ts,mjs,cjs}\"",
|
|
61
64
|
"lint": "eslint .",
|
|
62
65
|
"lint:fix": "pnpm run lint --fix",
|
|
63
|
-
"style": "pnpm run format
|
|
64
|
-
"style:fix": "pnpm run format:fix &&
|
|
66
|
+
"style": "pnpm run format && pnpm run lint",
|
|
67
|
+
"style:fix": "pnpm run format:fix && pnpm run lint:fix",
|
|
65
68
|
"test": "vitest run",
|
|
69
|
+
"typecheck": "tsc -p tsconfig.json",
|
|
66
70
|
"release": "pnpm run clean && pnpm run build && git add -f docs && git ci -m 'docs: update API docs' && pnpm dlx commit-and-tag-version -s",
|
|
67
71
|
"release.alpha": "pnpm run release -- --prerelease alpha"
|
|
68
72
|
}
|
package/setupVitest.mjs
CHANGED
package/tsconfig.json
CHANGED
|
@@ -4,16 +4,17 @@
|
|
|
4
4
|
"module": "NodeNext",
|
|
5
5
|
"moduleResolution": "NodeNext",
|
|
6
6
|
"declaration": true,
|
|
7
|
-
"outDir": "./dist",
|
|
8
7
|
"strict": true,
|
|
9
8
|
"esModuleInterop": true,
|
|
10
9
|
"skipLibCheck": true,
|
|
11
|
-
"forceConsistentCasingInFileNames": true
|
|
10
|
+
"forceConsistentCasingInFileNames": true,
|
|
11
|
+
|
|
12
|
+
// 这份 tsconfig 只给编辑器 / 类型检查用(构建走 tsup + tsconfig.release.json),
|
|
13
|
+
// 所以这里 noEmit,并且不要把 outDir 之类的产物配置放进来。
|
|
14
|
+
"noEmit": true
|
|
12
15
|
},
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
],
|
|
18
|
-
"include": ["src/**/*"]
|
|
16
|
+
// 开发/编辑器视角:测试文件也要在 program 里,否则 VS Code 会把它们
|
|
17
|
+
// 当成 invisible file 放进 inferred project,这份配置对它们无效。
|
|
18
|
+
"include": ["src/**/*", "test/**/*"],
|
|
19
|
+
"exclude": ["node_modules", "dist", "web", "docs"]
|
|
19
20
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
// 发包专用:tsup --dts / typedoc 用这份配置,排除测试文件。
|
|
3
|
+
// 编辑器与类型检查请用根目录的 tsconfig.json。
|
|
4
|
+
"extends": "./tsconfig.json",
|
|
5
|
+
"compilerOptions": {
|
|
6
|
+
// tsup --dts / typedoc 需要真正产出 .d.ts
|
|
7
|
+
"noEmit": false,
|
|
8
|
+
"declaration": true,
|
|
9
|
+
"outDir": "./dist"
|
|
10
|
+
},
|
|
11
|
+
"exclude": [
|
|
12
|
+
"node_modules",
|
|
13
|
+
"dist",
|
|
14
|
+
"web",
|
|
15
|
+
"docs",
|
|
16
|
+
"**/*.test.ts",
|
|
17
|
+
"**/*.spec.ts",
|
|
18
|
+
"**/*.test.js",
|
|
19
|
+
"**/*.spec.js"
|
|
20
|
+
]
|
|
21
|
+
}
|
package/tsup.config.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { defineConfig } from 'tsup'
|
|
2
2
|
|
|
3
3
|
export default defineConfig({
|
|
4
|
+
// 发包用 release 配置(排除测试文件);
|
|
5
|
+
// 根目录 tsconfig.json 是编辑器/类型检查用的(含测试文件)。
|
|
6
|
+
tsconfig: 'tsconfig.release.json',
|
|
4
7
|
entry: ['src/index.ts'],
|
|
5
8
|
format: ['cjs', 'esm'],
|
|
6
9
|
// Inject cjs and esm shims:https://tsup.egoist.dev/#inject-cjs-and-esm-shims
|
|
@@ -15,20 +18,21 @@ export default defineConfig({
|
|
|
15
18
|
// drop_debugger: true,
|
|
16
19
|
// },
|
|
17
20
|
// https://terser.org/docs/options/#mangle-options
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
+
mangle: {
|
|
22
|
+
properties: {
|
|
23
|
+
regex: /^_[$]/,
|
|
21
24
|
// "undeclared": true, // Mangle those names when they are accessed as properties of known top level variables but their declarations are never found in input code.
|
|
22
25
|
},
|
|
23
|
-
|
|
24
|
-
|
|
26
|
+
toplevel: true,
|
|
27
|
+
reserved: [
|
|
25
28
|
// # expected names in web-extension content
|
|
26
|
-
|
|
29
|
+
'WeakSet',
|
|
30
|
+
'Set',
|
|
27
31
|
// # expected names in 3rd-party extensions' contents
|
|
28
|
-
|
|
32
|
+
'requestIdleCallback',
|
|
29
33
|
// # content global names:
|
|
30
|
-
|
|
34
|
+
'browser',
|
|
31
35
|
],
|
|
32
|
-
}
|
|
36
|
+
},
|
|
33
37
|
},
|
|
34
38
|
})
|
package/typedoc.config.cjs
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
/** @type {import('typedoc').TypeDocOptions} */
|
|
2
2
|
module.exports = {
|
|
3
3
|
entryPoints: ['./src/index.ts'],
|
|
4
|
+
// 文档同样走 release 配置,避免把测试文件算进 program
|
|
5
|
+
tsconfig: './tsconfig.release.json',
|
|
4
6
|
externalSymbolLinkMappings: {
|
|
5
|
-
|
|
7
|
+
'events-ex': { EventEmitter: '#' },
|
|
6
8
|
},
|
|
7
9
|
}
|
package/vite.config.mjs
CHANGED
|
@@ -1,16 +1,21 @@
|
|
|
1
1
|
import { defineConfig } from 'vite'
|
|
2
|
-
import tsconfigPaths from 'vite-tsconfig-paths'
|
|
2
|
+
import tsconfigPaths from 'vite-tsconfig-paths'
|
|
3
3
|
|
|
4
4
|
export default defineConfig({
|
|
5
|
-
plugins: [
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
plugins: [
|
|
6
|
+
tsconfigPaths({
|
|
7
|
+
projects: ['./tsconfig.json'],
|
|
8
|
+
}),
|
|
9
|
+
],
|
|
8
10
|
test: {
|
|
9
|
-
include: [
|
|
11
|
+
include: [
|
|
12
|
+
'src/**/*.spec.ts',
|
|
13
|
+
'src/**/*.test.ts',
|
|
14
|
+
'test/*.spec.ts',
|
|
15
|
+
'test/*.test.ts',
|
|
16
|
+
],
|
|
10
17
|
testTimeout: 80000,
|
|
11
18
|
globals: true,
|
|
12
|
-
|
|
13
|
-
"./setupVitest.mjs"
|
|
14
|
-
],
|
|
19
|
+
setupFiles: ['./setupVitest.mjs'],
|
|
15
20
|
},
|
|
16
21
|
})
|
package/tsconfig.spec.json
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"types": ["jest", "node"],
|
|
4
|
-
"target": "es2020",
|
|
5
|
-
"module": "esnext",
|
|
6
|
-
"moduleResolution": "node",
|
|
7
|
-
"strict": true,
|
|
8
|
-
"typeRoots": ["./node_modules/@types", "./types"],
|
|
9
|
-
"esModuleInterop": true,
|
|
10
|
-
"skipLibCheck": true,
|
|
11
|
-
"noUnusedLocals": true,
|
|
12
|
-
"noImplicitAny": true,
|
|
13
|
-
"resolveJsonModule": true
|
|
14
|
-
},
|
|
15
|
-
"exclude": [
|
|
16
|
-
"node_modules",
|
|
17
|
-
"**/*.spec.ts"
|
|
18
|
-
]
|
|
19
|
-
}
|