@aomex/pretty-json 0.0.5 → 0.0.6
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 +4 -32
- package/dist/index.d.ts +5 -4
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,37 +1,9 @@
|
|
|
1
1
|
# @aomex/pretty-json
|
|
2
2
|
|
|
3
|
-
## 0.0.
|
|
3
|
+
## 0.0.6
|
|
4
4
|
|
|
5
5
|
### Patch Changes
|
|
6
6
|
|
|
7
|
-
- [`
|
|
8
|
-
|
|
9
|
-
-
|
|
10
|
-
- @aomex/web@0.0.6
|
|
11
|
-
- @aomex/core@0.0.5
|
|
12
|
-
|
|
13
|
-
## 0.0.4
|
|
14
|
-
|
|
15
|
-
### Patch Changes
|
|
16
|
-
|
|
17
|
-
- Updated dependencies [[`d8debb9`](https://github.com/aomex/aomex/commit/d8debb9b6319d30e48cb77d97103b5559c57789c), [`64c10e1`](https://github.com/aomex/aomex/commit/64c10e17ff92251bb2d9f45e0bddde5cba8a3b20), [`6a57463`](https://github.com/aomex/aomex/commit/6a57463c1107c38a8b8cf5fa00ff3289bf629c0a), [`8857115`](https://github.com/aomex/aomex/commit/88571153b7e84ec6d66d37970c3ef7b4e1924a03), [`68b1365`](https://github.com/aomex/aomex/commit/68b13655922a0714bcdd2101ce659da382d44e8b), [`b51a81a`](https://github.com/aomex/aomex/commit/b51a81a65313073dff5307b310b6656da2ad5186), [`ee021e3`](https://github.com/aomex/aomex/commit/ee021e342814f12777e538c06a19971e1020f201), [`b5aaec5`](https://github.com/aomex/aomex/commit/b5aaec540e3d732868a270a969a94ccd6ff9ac6a), [`fd6ae40`](https://github.com/aomex/aomex/commit/fd6ae40577bd9a62c211d4615483fc5dd58f5865)]:
|
|
18
|
-
- @aomex/web@0.0.5
|
|
19
|
-
- @aomex/core@0.0.4
|
|
20
|
-
|
|
21
|
-
## 0.0.3
|
|
22
|
-
|
|
23
|
-
### Patch Changes
|
|
24
|
-
|
|
25
|
-
- Updated dependencies [[`121253a`](https://github.com/aomex/aomex/commit/121253a6fc203e427bfd25e82d713bec6ac13b38), [`59dc183`](https://github.com/aomex/aomex/commit/59dc183bcec9b7221c18865563b38cba5d82869b), [`8cb74fd`](https://github.com/aomex/aomex/commit/8cb74fdd27626037aa9bc80cb2930e4f0d67f8e6), [`d834392`](https://github.com/aomex/aomex/commit/d834392b1e0f6333d66d11378d9f4ceb813a58a9), [`91feda4`](https://github.com/aomex/aomex/commit/91feda457dfa8bd8dd2c8f38bfaaf4f7f2f7702f)]:
|
|
26
|
-
- @aomex/web@0.0.4
|
|
27
|
-
- @aomex/core@0.0.3
|
|
28
|
-
|
|
29
|
-
## 0.0.2
|
|
30
|
-
|
|
31
|
-
### Patch Changes
|
|
32
|
-
|
|
33
|
-
- [`61a8e1c`](https://github.com/aomex/aomex/commit/61a8e1c42cc707808c4dd4710f43afcb6477e642) Thanks [@geekact](https://github.com/geekact)! - 增加 web 插件 pretty-json
|
|
34
|
-
|
|
35
|
-
- Updated dependencies [[`4735157`](https://github.com/aomex/aomex/commit/4735157c52d0abecc41d6c7f416280ebfd6ee696), [`d6ac7b5`](https://github.com/aomex/aomex/commit/d6ac7b5403334b51fa15dbe82dd6b5b6d048f661), [`9254754`](https://github.com/aomex/aomex/commit/9254754d234fc0062eb5d600284ee8453825306c), [`d1ce4e2`](https://github.com/aomex/aomex/commit/d1ce4e2276f93c44e67ea06666d048917fa94e53), [`6056f55`](https://github.com/aomex/aomex/commit/6056f556577865220d6b5be2a4eafad9e4dbf8d4), [`1c67399`](https://github.com/aomex/aomex/commit/1c673992c4b313c2accb4cbc1fc66537a9886c29), [`352642a`](https://github.com/aomex/aomex/commit/352642abf2ccb3fe97e2d83a691d8428ccfc9758)]:
|
|
36
|
-
- @aomex/web@0.0.3
|
|
37
|
-
- @aomex/core@0.0.2
|
|
7
|
+
- Updated dependencies [[`bbc8dda`](https://github.com/aomex/aomex/commit/bbc8dda9f0876c3402608133085350cc693def6f), [`ceb2d82`](https://github.com/aomex/aomex/commit/ceb2d8269755dca3f79b755224259b8a99bc65d0)]:
|
|
8
|
+
- @aomex/core@0.0.6
|
|
9
|
+
- @aomex/web@0.0.7
|
package/dist/index.d.ts
CHANGED
|
@@ -2,15 +2,16 @@ import { WebMiddleware } from '@aomex/web';
|
|
|
2
2
|
|
|
3
3
|
interface PrettyJsonOptions {
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
5
|
+
* Enable middleware. Defaults `true`
|
|
6
6
|
*/
|
|
7
|
-
|
|
7
|
+
enable?: boolean;
|
|
8
8
|
/**
|
|
9
|
-
*
|
|
9
|
+
* force enable with a param in querystring.
|
|
10
|
+
* - example.com?pretty
|
|
10
11
|
*/
|
|
11
12
|
param?: string;
|
|
12
13
|
/**
|
|
13
|
-
*
|
|
14
|
+
* Indent every line. Defaults `2`
|
|
14
15
|
*/
|
|
15
16
|
spaces?: number;
|
|
16
17
|
}
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@ 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 {
|
|
6
|
+
const { enable = true, spaces = 2, param } = options;
|
|
7
7
|
return middleware.web(async (ctx, next) => {
|
|
8
8
|
await next();
|
|
9
9
|
const {
|
|
@@ -11,7 +11,7 @@ var prettyJson = (options = {}) => {
|
|
|
11
11
|
response,
|
|
12
12
|
response: { body }
|
|
13
13
|
} = ctx;
|
|
14
|
-
const prettify =
|
|
14
|
+
const prettify = enable || param && Object.hasOwn(request.query, param);
|
|
15
15
|
if (!prettify)
|
|
16
16
|
return;
|
|
17
17
|
if (body instanceof Readable && body.readableObjectMode) {
|
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 *
|
|
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 * Enable middleware. Defaults `true`\n */\n enable?: boolean;\n\n /**\n * force enable with a param in querystring.\n * - example.com?pretty\n */\n param?: string;\n\n /**\n * Indent every line. Defaults `2`\n */\n spaces?: number;\n}\n\nexport const prettyJson = (options: PrettyJsonOptions = {}): WebMiddleware => {\n const { enable = true, spaces = 2, param } = options;\n\n return middleware.web(async (ctx, next) => {\n await next();\n const {\n request,\n response,\n response: { body },\n } = ctx;\n const prettify = enable || (param && Object.hasOwn(request.query, param));\n\n if (!prettify) return;\n\n if (body instanceof Readable && body.readableObjectMode) {\n response.contentType = 'json';\n ctx.send(body.pipe(StreamStringify({ space: spaces })));\n } else if (response.isJSON(body)) {\n ctx.send(JSON.stringify(body, null, spaces));\n }\n });\n};\n"],"mappings":";AAAA,SAAS,kBAAkB;AAE3B,SAAS,gBAAgB;AACzB,OAAO,qBAAqB;AAoBrB,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;AACX,UAAM;AAAA,MACJ;AAAA,MACA;AAAA,MACA,UAAU,EAAE,KAAK;AAAA,IACnB,IAAI;AACJ,UAAM,WAAW,UAAW,SAAS,OAAO,OAAO,QAAQ,OAAO,KAAK;AAEvE,QAAI,CAAC;AAAU;AAEf,QAAI,gBAAgB,YAAY,KAAK,oBAAoB;AACvD,eAAS,cAAc;AACvB,UAAI,KAAK,KAAK,KAAK,gBAAgB,EAAE,OAAO,OAAO,CAAC,CAAC,CAAC;AAAA,IACxD,WAAW,SAAS,OAAO,IAAI,GAAG;AAChC,UAAI,KAAK,KAAK,UAAU,MAAM,MAAM,MAAM,CAAC;AAAA,IAC7C;AAAA,EACF,CAAC;AACH;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aomex/pretty-json",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.0.6",
|
|
4
|
+
"description": "Format JSON response",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pretty",
|
|
7
7
|
"json"
|
|
@@ -30,15 +30,15 @@
|
|
|
30
30
|
"access": "public"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
|
-
"@aomex/core": "^0.0.
|
|
34
|
-
"@aomex/web": "^0.0.
|
|
33
|
+
"@aomex/core": "^0.0.6",
|
|
34
|
+
"@aomex/web": "^0.0.7"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"streaming-json-stringify": "^3.1.0"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@aomex/core": "^0.0.
|
|
41
|
-
"@aomex/web": "^0.0.
|
|
40
|
+
"@aomex/core": "^0.0.6",
|
|
41
|
+
"@aomex/web": "^0.0.7",
|
|
42
42
|
"@types/streaming-json-stringify": "^3.1.1"
|
|
43
43
|
},
|
|
44
44
|
"scripts": {}
|