@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 CHANGED
@@ -1,57 +1,15 @@
1
1
  # @aomex/pretty-json
2
2
 
3
- ## 0.0.28
3
+ ## 1.0.1
4
4
 
5
- ### Patch Changes
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
- - Updated dependencies [[`6621e4f`](https://github.com/aomex/aomex/commit/6621e4ff0f3509beeb332a0571a7db9c7d6ca99a), [`7b09277`](https://github.com/aomex/aomex/commit/7b09277136910966f500c8132303c7ddee84340c), [`46c5b72`](https://github.com/aomex/aomex/commit/46c5b72785011fa181767f4c8ea0d0f5008b21ae), [`9c78999`](https://github.com/aomex/aomex/commit/9c78999ebcb2962f30344acfbf6de0733d6fdd41), [`f4b012d`](https://github.com/aomex/aomex/commit/f4b012d98cddb2918479ea05df6c266dd914e53a)]:
48
- - @aomex/web@0.0.24
49
- - @aomex/core@0.0.23
7
+ ### Minor Changes
50
8
 
51
- ## 0.0.22
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 [[`6f7d706`](https://github.com/aomex/aomex/commit/6f7d7066c23711abdd149eb1c9a293ab8c4284a4), [`e21007a`](https://github.com/aomex/aomex/commit/e21007a82cb8eac73e1f696340bbe986d57dc159), [`e7bf93c`](https://github.com/aomex/aomex/commit/e7bf93cee6896c61d0bf3eb0921151dc6c1bc107), [`e21007a`](https://github.com/aomex/aomex/commit/e21007a82cb8eac73e1f696340bbe986d57dc159), [`818e840`](https://github.com/aomex/aomex/commit/818e840d36c7456a863fc071968b246c123c17f5), [`fb6c72d`](https://github.com/aomex/aomex/commit/fb6c72dbb266be4db92a542afe93dfa5d8c7cd41)]:
56
- - @aomex/core@0.0.22
57
- - @aomex/web@0.0.23
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
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2023 geekact
3
+ Copyright (c) 2023-2024 geekact
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/dist/index.d.ts CHANGED
@@ -9,7 +9,7 @@ interface PrettyJsonOptions {
9
9
  * 在查询字符串中强制启用中间件
10
10
  * - example.com?pretty
11
11
  */
12
- param?: string;
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, param } = options;
6
+ const { enable = true, spaces = 2, query } = options;
7
7
  return middleware.web(async (ctx, next) => {
8
8
  await next();
9
- const {
10
- request,
11
- response,
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
- ctx.send(body.pipe(StreamStringify({ space: spaces })));
16
+ response.body = body.pipe(StreamStringify({ space: spaces }));
20
17
  } else if (response.isJSON(body)) {
21
- ctx.send(JSON.stringify(body, null, spaces));
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\n /**\n * 在查询字符串中强制启用中间件\n * - example.com?pretty\n */\n param?: string;\n\n /**\n * 每行缩进,默认值:`2`\n * ```typescript\n * JSON.stringify({}, null, spaces)\n * ```\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;AAuBrB,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":[]}
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": "0.0.28",
4
- "description": "Format JSON response",
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.28",
34
- "@aomex/web": "^0.0.29"
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
- "@aomex/core": "^0.0.28",
41
- "@aomex/web": "^0.0.29",
42
- "@types/streaming-json-stringify": "^3.1.1"
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
  }