@aomex/pretty-json 0.0.20 → 0.0.22

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,113 +1,9 @@
1
1
  # @aomex/pretty-json
2
2
 
3
- ## 0.0.20
3
+ ## 0.0.22
4
4
 
5
5
  ### Patch Changes
6
6
 
7
- - Updated dependencies [[`a8dbaf3`](https://github.com/aomex/aomex/commit/a8dbaf38524f5a5d58337bc617175115742f9e1a), [`ddcec91`](https://github.com/aomex/aomex/commit/ddcec91803b00f35f7c55964d1a2d97c40a22c6e)]:
8
- - @aomex/web@0.0.21
9
- - @aomex/core@0.0.20
10
-
11
- ## 0.0.19
12
-
13
- ### Patch Changes
14
-
15
- - Updated dependencies []:
16
- - @aomex/core@0.0.19
17
- - @aomex/web@0.0.20
18
-
19
- ## 0.0.18
20
-
21
- ### Patch Changes
22
-
23
- - Updated dependencies []:
24
- - @aomex/core@0.0.18
25
- - @aomex/web@0.0.19
26
-
27
- ## 0.0.17
28
-
29
- ### Patch Changes
30
-
31
- - Updated dependencies []:
32
- - @aomex/core@0.0.17
33
- - @aomex/web@0.0.18
34
-
35
- ## 0.0.16
36
-
37
- ### Patch Changes
38
-
39
- - Updated dependencies [[`216aa79`](https://github.com/aomex/aomex/commit/216aa798bcd2d0856f5fe4028235aa54d4b10922)]:
40
- - @aomex/web@0.0.17
41
- - @aomex/core@0.0.16
42
-
43
- ## 0.0.15
44
-
45
- ### Patch Changes
46
-
47
- - Updated dependencies [[`280359e`](https://github.com/aomex/aomex/commit/280359eb90b71720304cfc212374b6dc4c90236d), [`9881653`](https://github.com/aomex/aomex/commit/988165361439738d27bc29bd0ed5a85c608db5ef), [`15ecd1c`](https://github.com/aomex/aomex/commit/15ecd1c75bc21929f79980b32e63ea46e081cc6a)]:
48
- - @aomex/web@0.0.16
49
- - @aomex/core@0.0.15
50
-
51
- ## 0.0.14
52
-
53
- ### Patch Changes
54
-
55
- - Updated dependencies []:
56
- - @aomex/core@0.0.14
57
- - @aomex/web@0.0.15
58
-
59
- ## 0.0.13
60
-
61
- ### Patch Changes
62
-
63
- - Updated dependencies [[`715cf66`](https://github.com/aomex/aomex/commit/715cf660e3b275b338dcf15c25ba9523cf6fb204)]:
64
- - @aomex/web@0.0.14
65
- - @aomex/core@0.0.13
66
-
67
- ## 0.0.12
68
-
69
- ### Patch Changes
70
-
71
- - Updated dependencies [[`6e63df8`](https://github.com/aomex/aomex/commit/6e63df84d1b32e713aba8c52451e289a72b57bae), [`67acf4f`](https://github.com/aomex/aomex/commit/67acf4f42cd86bf1f0a7c647a5ff779c7cd0fa10)]:
72
- - @aomex/web@0.0.13
73
- - @aomex/core@0.0.12
74
-
75
- ## 0.0.11
76
-
77
- ### Patch Changes
78
-
79
- - Updated dependencies [[`f14eb5f`](https://github.com/aomex/aomex/commit/f14eb5fe7bf06e1e2f64d45e3546c96d6079a2f1), [`7d923cf`](https://github.com/aomex/aomex/commit/7d923cf971b6a23d50113ab104c67041c6489053), [`3c5ad4e`](https://github.com/aomex/aomex/commit/3c5ad4e2f34be7da54c8b63f6fd4b88fd1e593c4), [`6154ee5`](https://github.com/aomex/aomex/commit/6154ee5ed500984f969d4c335ac3ad800c739937), [`92273f9`](https://github.com/aomex/aomex/commit/92273f913e38543f34f41ec5941ff43b6e1caaa9), [`a0fd49e`](https://github.com/aomex/aomex/commit/a0fd49ef276c05f312257521c75887458857bbb7)]:
80
- - @aomex/web@0.0.12
81
- - @aomex/core@0.0.11
82
-
83
- ## 0.0.10
84
-
85
- ### Patch Changes
86
-
87
- - Updated dependencies [[`d9dc050`](https://github.com/aomex/aomex/commit/d9dc050897367353588c4bb778cbafb7607406ab), [`41ae605`](https://github.com/aomex/aomex/commit/41ae6054b2e87c4120f3fcee12302bb3d96f1df3)]:
88
- - @aomex/web@0.0.11
89
- - @aomex/core@0.0.10
90
-
91
- ## 0.0.9
92
-
93
- ### Patch Changes
94
-
95
- - Updated dependencies [[`2439286`](https://github.com/aomex/aomex/commit/2439286e69dcc7211ac280b91dbca5de95cc488b)]:
96
- - @aomex/web@0.0.10
97
- - @aomex/core@0.0.9
98
-
99
- ## 0.0.8
100
-
101
- ### Patch Changes
102
-
103
- - Updated dependencies [[`dcf2f4b`](https://github.com/aomex/aomex/commit/dcf2f4b6a13228d4731e4969e6abff9bef8ef0e2), [`d788ce7`](https://github.com/aomex/aomex/commit/d788ce731af885eae3819683813b2a9502742cea), [`c6fe6cb`](https://github.com/aomex/aomex/commit/c6fe6cb2f21acf74bc06db1509deff4aa35c48b3), [`a2727fb`](https://github.com/aomex/aomex/commit/a2727fb7619341dc3b23736e5dc11cee7d65e0bc), [`4253004`](https://github.com/aomex/aomex/commit/42530043854956a42d16be090b89fbac70e2fa17), [`fc7008e`](https://github.com/aomex/aomex/commit/fc7008e889a55e6a0a268bb77cab5be0f0bd9d30), [`d80df1a`](https://github.com/aomex/aomex/commit/d80df1a07eb92214a9c3c7fa15c629ea1ee88c43)]:
104
- - @aomex/web@0.0.9
105
- - @aomex/core@0.0.8
106
-
107
- ## 0.0.6
108
-
109
- ### Patch Changes
110
-
111
- - Updated dependencies [[`bbc8dda`](https://github.com/aomex/aomex/commit/bbc8dda9f0876c3402608133085350cc693def6f), [`ceb2d82`](https://github.com/aomex/aomex/commit/ceb2d8269755dca3f79b755224259b8a99bc65d0)]:
112
- - @aomex/core@0.0.6
113
- - @aomex/web@0.0.7
7
+ - 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)]:
8
+ - @aomex/core@0.0.22
9
+ - @aomex/web@0.0.23
package/dist/index.d.ts CHANGED
@@ -2,16 +2,19 @@ import { WebMiddleware } from '@aomex/web';
2
2
 
3
3
  interface PrettyJsonOptions {
4
4
  /**
5
- * Enable middleware. Defaults `true`
5
+ * 启用中间件。默认值:`true`
6
6
  */
7
7
  enable?: boolean;
8
8
  /**
9
- * force enable with a param in querystring.
9
+ * 在查询字符串中强制启用中间件
10
10
  * - example.com?pretty
11
11
  */
12
12
  param?: string;
13
13
  /**
14
- * Indent every line. Defaults `2`
14
+ * 每行缩进,默认值:`2`
15
+ * ```typescript
16
+ * JSON.stringify({}, null, spaces)
17
+ * ```
15
18
  */
16
19
  spaces?: number;
17
20
  }
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 * 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":[]}
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":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aomex/pretty-json",
3
- "version": "0.0.20",
3
+ "version": "0.0.22",
4
4
  "description": "Format JSON response",
5
5
  "keywords": [
6
6
  "pretty",
@@ -30,15 +30,15 @@
30
30
  "access": "public"
31
31
  },
32
32
  "peerDependencies": {
33
- "@aomex/core": "^0.0.20",
34
- "@aomex/web": "^0.0.21"
33
+ "@aomex/core": "^0.0.22",
34
+ "@aomex/web": "^0.0.23"
35
35
  },
36
36
  "dependencies": {
37
37
  "streaming-json-stringify": "^3.1.0"
38
38
  },
39
39
  "devDependencies": {
40
- "@aomex/core": "^0.0.20",
41
- "@aomex/web": "^0.0.21",
40
+ "@aomex/core": "^0.0.22",
41
+ "@aomex/web": "^0.0.23",
42
42
  "@types/streaming-json-stringify": "^3.1.1"
43
43
  },
44
44
  "scripts": {