@aomex/pretty-json 0.0.3 → 0.0.5
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 +18 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +11 -15
- package/dist/index.js.map +1 -1
- package/package.json +6 -9
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @aomex/pretty-json
|
|
2
2
|
|
|
3
|
+
## 0.0.5
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`922b033`](https://github.com/aomex/aomex/commit/922b033915d39205454ebce15540b43b09ac9e8c) Thanks [@geekact](https://github.com/geekact)! - feat(pretty-json): 禁用美化功能时直接跳过该中间件
|
|
8
|
+
|
|
9
|
+
- Updated dependencies [[`d3a2757`](https://github.com/aomex/aomex/commit/d3a2757b38391ad70a206d95eac09520c64e9b85), [`07c8575`](https://github.com/aomex/aomex/commit/07c857565ede4eca7e88de4e8c5e5f244f9d16cb), [`e80844a`](https://github.com/aomex/aomex/commit/e80844a6808fd0f3b9d613ec3163b06357316cae), [`146b6b5`](https://github.com/aomex/aomex/commit/146b6b5f09d4b9f557c1771686f3585bebf4cfc9), [`56f65c8`](https://github.com/aomex/aomex/commit/56f65c8509b40679272ed58f63e12d98e1818503), [`c6df4de`](https://github.com/aomex/aomex/commit/c6df4de61fc28f452f8a202c9a485e1a061b3eb6), [`79e19c1`](https://github.com/aomex/aomex/commit/79e19c1ae2a35b38580a4d2a27b6dde634345126), [`9adefaa`](https://github.com/aomex/aomex/commit/9adefaa8baaaafb7be610c7a98920c9830d10a3c), [`a8bb601`](https://github.com/aomex/aomex/commit/a8bb601acaf1e1d580511ae886a4ae99bf19f699), [`902597b`](https://github.com/aomex/aomex/commit/902597b2f98fda7e63f7419a5ef62ab2acb7c863), [`e8dee7c`](https://github.com/aomex/aomex/commit/e8dee7c3f064587cd2afb9cb95ab3341f63ccd27)]:
|
|
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
|
+
|
|
3
21
|
## 0.0.3
|
|
4
22
|
|
|
5
23
|
### Patch Changes
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -6,22 +6,18 @@ var prettyJson = (options = {}) => {
|
|
|
6
6
|
const { pretty = true, spaces = 2, param } = options;
|
|
7
7
|
return middleware.web(async (ctx, next) => {
|
|
8
8
|
await next();
|
|
9
|
-
const {
|
|
10
|
-
|
|
9
|
+
const {
|
|
10
|
+
request,
|
|
11
|
+
response,
|
|
12
|
+
response: { body }
|
|
13
|
+
} = ctx;
|
|
14
|
+
const prettify = pretty || param && Object.hasOwn(request.query, param);
|
|
15
|
+
if (!prettify)
|
|
11
16
|
return;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const prettify = pretty || param && ctx.request.query.hasOwnProperty(param);
|
|
17
|
-
if (isStream) {
|
|
18
|
-
ctx.response.contentType = "json";
|
|
19
|
-
const stringify = StreamStringify();
|
|
20
|
-
if (prettify) {
|
|
21
|
-
stringify.space = spaces;
|
|
22
|
-
}
|
|
23
|
-
ctx.send(body.pipe(stringify));
|
|
24
|
-
} else if (prettify) {
|
|
17
|
+
if (body instanceof Readable && body.readableObjectMode) {
|
|
18
|
+
response.contentType = "json";
|
|
19
|
+
ctx.send(body.pipe(StreamStringify({ space: spaces })));
|
|
20
|
+
} else if (response.isJSON(body)) {
|
|
25
21
|
ctx.send(JSON.stringify(body, null, spaces));
|
|
26
22
|
}
|
|
27
23
|
});
|
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 * 是否格式化JSON数据,默认:`true`\n */\n pretty?: boolean;\n\n /**\n * 在查询字符串(querystring)中使用指定参数来触发JSON格式化\n */\n param?: string;\n\n /**\n * JSON
|
|
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 * 是否格式化JSON数据,默认:`true`\n */\n pretty?: boolean;\n\n /**\n * 在查询字符串(querystring)中使用指定参数来触发JSON格式化\n */\n param?: string;\n\n /**\n * JSON每行缩进空格,默认:`2`\n */\n spaces?: number;\n}\n\nexport const prettyJson = (options: PrettyJsonOptions = {}): WebMiddleware => {\n const { pretty = 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 = pretty || (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;AAmBrB,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,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aomex/pretty-json",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"description": "格式化json数据中间件",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pretty",
|
|
@@ -30,19 +30,16 @@
|
|
|
30
30
|
"access": "public"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
|
-
"@aomex/core": "^0.0.
|
|
34
|
-
"@aomex/web": "^0.0.
|
|
33
|
+
"@aomex/core": "^0.0.5",
|
|
34
|
+
"@aomex/web": "^0.0.6"
|
|
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.
|
|
42
|
-
"@types/streaming-json-stringify": "^3.1.1"
|
|
43
|
-
"@types/supertest": "^2.0.12",
|
|
44
|
-
"supertest": "^6.3.3",
|
|
45
|
-
"vitest": "^0.28.5"
|
|
40
|
+
"@aomex/core": "^0.0.5",
|
|
41
|
+
"@aomex/web": "^0.0.6",
|
|
42
|
+
"@types/streaming-json-stringify": "^3.1.1"
|
|
46
43
|
},
|
|
47
44
|
"scripts": {}
|
|
48
45
|
}
|