@aomex/pretty-json 3.8.0 → 3.9.0
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 +16 -0
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,22 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [3.9.0](https://github.com/aomex/aomex/compare/v3.8.1...v3.9.0) (2024-10-30)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @aomex/pretty-json
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## [3.8.1](https://github.com/aomex/aomex/compare/v3.8.0...v3.8.1) (2024-10-26)
|
|
15
|
+
|
|
16
|
+
**Note:** Version bump only for package @aomex/pretty-json
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
6
22
|
# [3.8.0](https://github.com/aomex/aomex/compare/v3.7.2...v3.8.0) (2024-10-26)
|
|
7
23
|
|
|
8
24
|
**Note:** Version bump only for package @aomex/pretty-json
|
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { middleware } from '@aomex/
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { middleware } from '@aomex/common';\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 * 在查询字符串找到指定的key时,强制启用中间件\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,SAAU;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,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aomex/pretty-json",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.9.0",
|
|
4
4
|
"description": "格式化JSON数据",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pretty",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"node": "^20.13.0 || ^22"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
|
-
"@aomex/
|
|
36
|
+
"@aomex/common": "^3.0.0",
|
|
37
37
|
"@aomex/web": "^3.0.0"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
@@ -41,8 +41,8 @@
|
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@types/streaming-json-stringify": "^3.1.1",
|
|
44
|
-
"@aomex/
|
|
45
|
-
"@aomex/web": "^3.
|
|
44
|
+
"@aomex/common": "^3.9.0",
|
|
45
|
+
"@aomex/web": "^3.9.0"
|
|
46
46
|
},
|
|
47
47
|
"scripts": {}
|
|
48
48
|
}
|