@aomex/pretty-json 1.0.4 → 1.2.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 CHANGED
@@ -1,21 +1,19 @@
1
- # @aomex/pretty-json
1
+ # Change Log
2
2
 
3
- ## 1.0.4
3
+ All notable changes to this project will be documented in this file.
4
+ See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
4
5
 
5
- ## 1.0.3
6
+ # [1.2.0](https://github.com/aomex/aomex/compare/v1.1.0...v1.2.0) (2024-06-27)
6
7
 
7
- ## 1.0.2
8
+ **Note:** Version bump only for package @aomex/pretty-json
8
9
 
9
- ## 1.0.1
10
10
 
11
- ## 1.0.0
12
11
 
13
- ### Minor Changes
14
12
 
15
- - [`11103a2`](https://github.com/aomex/aomex/commit/11103a2aff4e081754c56b0ff18fa5130ca252e8) Thanks [@geekact](https://github.com/geekact)! - 重新制作
16
13
 
17
- ### Patch Changes
14
+ # 1.1.0 (2024-06-27)
18
15
 
19
- - Updated dependencies [[`11103a2`](https://github.com/aomex/aomex/commit/11103a2aff4e081754c56b0ff18fa5130ca252e8)]:
20
- - @aomex/core@1.0.0
21
- - @aomex/web@1.0.0
16
+
17
+ ### Features
18
+
19
+ * 初始化 ([3350159](https://github.com/aomex/aomex/commit/3350159454ad230e6d910405f907293b059b1f49))
package/dist/index.d.ts CHANGED
@@ -2,16 +2,16 @@ import { WebMiddleware } from '@aomex/web';
2
2
 
3
3
  interface PrettyJsonOptions {
4
4
  /**
5
- * 启用中间件。默认值:`true`
5
+ * 是否启用中间件。默认值:`true`
6
6
  */
7
7
  enable?: boolean;
8
8
  /**
9
- * 在查询字符串中强制启用中间件
9
+ * 在查询字符串找到指定的key时,强制启用中间件
10
10
  * - example.com?pretty
11
11
  */
12
12
  query?: string;
13
13
  /**
14
- * 每行缩进,默认值:`2`
14
+ * 每行缩进空格数量。默认值:`2`
15
15
  * ```typescript
16
16
  * JSON.stringify({}, null, spaces)
17
17
  * ```
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 /**\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,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":[]}
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 * 在查询字符串找到指定的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": "1.0.4",
3
+ "version": "1.2.0",
4
4
  "description": "格式化JSON数据",
5
5
  "keywords": [
6
6
  "pretty",
@@ -38,8 +38,8 @@
38
38
  },
39
39
  "devDependencies": {
40
40
  "@types/streaming-json-stringify": "^3.1.1",
41
- "@aomex/core": "^1.0.4",
42
- "@aomex/web": "^1.0.4"
41
+ "@aomex/core": "^1.2.0",
42
+ "@aomex/web": "^1.2.0"
43
43
  },
44
44
  "scripts": {}
45
45
  }