@aomex/pretty-json 0.0.28 → 1.0.1
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/CHANGELOG.md +7 -49
- package/LICENSE +1 -1
- package/dist/index.d.ts +5 -2
- package/dist/index.js +7 -9
- package/dist/index.js.map +1 -1
- package/package.json +8 -10
package/CHANGELOG.md
CHANGED
|
@@ -1,57 +1,15 @@
|
|
|
1
1
|
# @aomex/pretty-json
|
|
2
2
|
|
|
3
|
-
##
|
|
3
|
+
## 1.0.1
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
- Updated dependencies [[`59cd3f9`](https://github.com/aomex/aomex/commit/59cd3f98a0b5648a972d6118ba21501130a9ee7e), [`90ca7d5`](https://github.com/aomex/aomex/commit/90ca7d5fc736b523c4fbf7949f64653428dc413c)]:
|
|
8
|
-
- @aomex/web@0.0.29
|
|
9
|
-
- @aomex/core@0.0.28
|
|
10
|
-
|
|
11
|
-
## 0.0.27
|
|
12
|
-
|
|
13
|
-
### Patch Changes
|
|
14
|
-
|
|
15
|
-
- Updated dependencies [[`00bafbb`](https://github.com/aomex/aomex/commit/00bafbbac2d32205b63a6bf561fb0a69c38a54bb), [`8becf8e`](https://github.com/aomex/aomex/commit/8becf8ee5ef86a5909783d0654e536db7be9bf5b), [`0776719`](https://github.com/aomex/aomex/commit/077671963401f1dafb5b03722899452d45df13fc), [`f996bf7`](https://github.com/aomex/aomex/commit/f996bf7e529e7751a5e858c579feed33f5f02d65)]:
|
|
16
|
-
- @aomex/core@0.0.27
|
|
17
|
-
- @aomex/web@0.0.28
|
|
18
|
-
|
|
19
|
-
## 0.0.26
|
|
20
|
-
|
|
21
|
-
### Patch Changes
|
|
22
|
-
|
|
23
|
-
- Updated dependencies [[`33c3c61`](https://github.com/aomex/aomex/commit/33c3c614be9f66077f7487350b88d2db854f5fc8), [`fbcea3d`](https://github.com/aomex/aomex/commit/fbcea3d68ff033e6861130c645c8e5ad7336193f)]:
|
|
24
|
-
- @aomex/web@0.0.27
|
|
25
|
-
- @aomex/core@0.0.26
|
|
26
|
-
|
|
27
|
-
## 0.0.25
|
|
28
|
-
|
|
29
|
-
### Patch Changes
|
|
30
|
-
|
|
31
|
-
- Updated dependencies [[`5ef2022`](https://github.com/aomex/aomex/commit/5ef202248b4320ff9076fbecb54379055cffb7db), [`8d9e9d8`](https://github.com/aomex/aomex/commit/8d9e9d8ece0bbcc7e1ac685702eacbfdfa145aa9), [`0e6ed2c`](https://github.com/aomex/aomex/commit/0e6ed2c611100dcfaafb6fb41357624ad9f5c67a)]:
|
|
32
|
-
- @aomex/web@0.0.26
|
|
33
|
-
- @aomex/core@0.0.25
|
|
34
|
-
|
|
35
|
-
## 0.0.24
|
|
36
|
-
|
|
37
|
-
### Patch Changes
|
|
38
|
-
|
|
39
|
-
- Updated dependencies [[`2ac62fd`](https://github.com/aomex/aomex/commit/2ac62fd28166a1d9dd60b3c6d5a6508a6f9ee82b), [`4258410`](https://github.com/aomex/aomex/commit/42584107ad9f7e34492ae1053fef83aa2d9d747a), [`4177cba`](https://github.com/aomex/aomex/commit/4177cba7877e38120842bd8d287eaed54e4926ca)]:
|
|
40
|
-
- @aomex/core@0.0.24
|
|
41
|
-
- @aomex/web@0.0.25
|
|
42
|
-
|
|
43
|
-
## 0.0.23
|
|
44
|
-
|
|
45
|
-
### Patch Changes
|
|
5
|
+
## 1.0.0
|
|
46
6
|
|
|
47
|
-
|
|
48
|
-
- @aomex/web@0.0.24
|
|
49
|
-
- @aomex/core@0.0.23
|
|
7
|
+
### Minor Changes
|
|
50
8
|
|
|
51
|
-
|
|
9
|
+
- [`11103a2`](https://github.com/aomex/aomex/commit/11103a2aff4e081754c56b0ff18fa5130ca252e8) Thanks [@geekact](https://github.com/geekact)! - 重新制作
|
|
52
10
|
|
|
53
11
|
### Patch Changes
|
|
54
12
|
|
|
55
|
-
- Updated dependencies [[`
|
|
56
|
-
- @aomex/core@0.0
|
|
57
|
-
- @aomex/web@0.0
|
|
13
|
+
- Updated dependencies [[`11103a2`](https://github.com/aomex/aomex/commit/11103a2aff4e081754c56b0ff18fa5130ca252e8)]:
|
|
14
|
+
- @aomex/core@1.0.0
|
|
15
|
+
- @aomex/web@1.0.0
|
package/LICENSE
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ interface PrettyJsonOptions {
|
|
|
9
9
|
* 在查询字符串中强制启用中间件
|
|
10
10
|
* - example.com?pretty
|
|
11
11
|
*/
|
|
12
|
-
|
|
12
|
+
query?: string;
|
|
13
13
|
/**
|
|
14
14
|
* 每行缩进,默认值:`2`
|
|
15
15
|
* ```typescript
|
|
@@ -18,6 +18,9 @@ interface PrettyJsonOptions {
|
|
|
18
18
|
*/
|
|
19
19
|
spaces?: number;
|
|
20
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* 美化输出的JSON数据
|
|
23
|
+
*/
|
|
21
24
|
declare const prettyJson: (options?: PrettyJsonOptions) => WebMiddleware;
|
|
22
25
|
|
|
23
|
-
export { PrettyJsonOptions, prettyJson };
|
|
26
|
+
export { type PrettyJsonOptions, prettyJson };
|
package/dist/index.js
CHANGED
|
@@ -3,22 +3,20 @@ import { middleware } from "@aomex/core";
|
|
|
3
3
|
import { Readable } from "node:stream";
|
|
4
4
|
import StreamStringify from "streaming-json-stringify";
|
|
5
5
|
var prettyJson = (options = {}) => {
|
|
6
|
-
const { enable = true, spaces = 2,
|
|
6
|
+
const { enable = true, spaces = 2, query } = options;
|
|
7
7
|
return middleware.web(async (ctx, next) => {
|
|
8
8
|
await next();
|
|
9
|
-
const {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
response: { body }
|
|
13
|
-
} = ctx;
|
|
14
|
-
const prettify = enable || param && Object.hasOwn(request.query, param);
|
|
9
|
+
const { request, response } = ctx;
|
|
10
|
+
const { body } = response;
|
|
11
|
+
const prettify = enable || query && Object.hasOwn(request.query, query);
|
|
15
12
|
if (!prettify)
|
|
16
13
|
return;
|
|
17
14
|
if (body instanceof Readable && body.readableObjectMode) {
|
|
18
15
|
response.contentType = "json";
|
|
19
|
-
|
|
16
|
+
response.body = body.pipe(StreamStringify({ space: spaces }));
|
|
20
17
|
} else if (response.isJSON(body)) {
|
|
21
|
-
|
|
18
|
+
response.contentType = "json";
|
|
19
|
+
response.body = JSON.stringify(body, null, spaces);
|
|
22
20
|
}
|
|
23
21
|
});
|
|
24
22
|
};
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { middleware } from '@aomex/core';\nimport type { WebMiddleware } from '@aomex/web';\nimport { Readable } from 'node:stream';\nimport StreamStringify from 'streaming-json-stringify';\n\nexport interface PrettyJsonOptions {\n /**\n * 启用中间件。默认值:`true`\n */\n enable?: boolean;\n
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { middleware } from '@aomex/core';\nimport type { WebMiddleware } from '@aomex/web';\nimport { Readable } from 'node:stream';\nimport StreamStringify from 'streaming-json-stringify';\n\nexport interface PrettyJsonOptions {\n /**\n * 启用中间件。默认值:`true`\n */\n enable?: boolean;\n /**\n * 在查询字符串中强制启用中间件\n * - example.com?pretty\n */\n query?: string;\n /**\n * 每行缩进,默认值:`2`\n * ```typescript\n * JSON.stringify({}, null, spaces)\n * ```\n */\n spaces?: number;\n}\n\n/**\n * 美化输出的JSON数据\n */\nexport const prettyJson = (options: PrettyJsonOptions = {}): WebMiddleware => {\n const { enable = true, spaces = 2, query } = options;\n\n return middleware.web(async (ctx, next) => {\n await next();\n\n const { request, response } = ctx;\n const { body } = response;\n const prettify = enable || (query && Object.hasOwn(request.query, query));\n\n if (!prettify) return;\n\n if (body instanceof Readable && body.readableObjectMode) {\n response.contentType = 'json';\n response.body = body.pipe(StreamStringify({ space: spaces }));\n } else if (response.isJSON(body)) {\n response.contentType = 'json';\n response.body = JSON.stringify(body, null, spaces);\n }\n });\n};\n"],"mappings":";AAAA,SAAS,kBAAkB;AAE3B,SAAS,gBAAgB;AACzB,OAAO,qBAAqB;AAwBrB,IAAM,aAAa,CAAC,UAA6B,CAAC,MAAqB;AAC5E,QAAM,EAAE,SAAS,MAAM,SAAS,GAAG,MAAM,IAAI;AAE7C,SAAO,WAAW,IAAI,OAAO,KAAK,SAAS;AACzC,UAAM,KAAK;AAEX,UAAM,EAAE,SAAS,SAAS,IAAI;AAC9B,UAAM,EAAE,KAAK,IAAI;AACjB,UAAM,WAAW,UAAW,SAAS,OAAO,OAAO,QAAQ,OAAO,KAAK;AAEvE,QAAI,CAAC;AAAU;AAEf,QAAI,gBAAgB,YAAY,KAAK,oBAAoB;AACvD,eAAS,cAAc;AACvB,eAAS,OAAO,KAAK,KAAK,gBAAgB,EAAE,OAAO,OAAO,CAAC,CAAC;AAAA,IAC9D,WAAW,SAAS,OAAO,IAAI,GAAG;AAChC,eAAS,cAAc;AACvB,eAAS,OAAO,KAAK,UAAU,MAAM,MAAM,MAAM;AAAA,IACnD;AAAA,EACF,CAAC;AACH;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aomex/pretty-json",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "格式化JSON数据",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pretty",
|
|
7
7
|
"json"
|
|
@@ -30,18 +30,16 @@
|
|
|
30
30
|
"access": "public"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
|
-
"@aomex/core": "^0.0
|
|
34
|
-
"@aomex/web": "^0.0
|
|
33
|
+
"@aomex/core": "^1.0.0",
|
|
34
|
+
"@aomex/web": "^1.0.0"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"streaming-json-stringify": "^3.1.0"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@
|
|
41
|
-
"@aomex/
|
|
42
|
-
"@
|
|
40
|
+
"@types/streaming-json-stringify": "^3.1.1",
|
|
41
|
+
"@aomex/core": "^1.0.1",
|
|
42
|
+
"@aomex/web": "^1.0.1"
|
|
43
43
|
},
|
|
44
|
-
"scripts": {
|
|
45
|
-
"test": "vitest"
|
|
46
|
-
}
|
|
44
|
+
"scripts": {}
|
|
47
45
|
}
|