@aomex/pretty-json 0.0.5 → 0.0.7

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,37 +1,17 @@
1
1
  # @aomex/pretty-json
2
2
 
3
- ## 0.0.5
3
+ ## 0.0.7
4
4
 
5
5
  ### Patch Changes
6
6
 
7
- - [`922b033`](https://github.com/aomex/aomex/commit/922b033915d39205454ebce15540b43b09ac9e8c) Thanks [@geekact](https://github.com/geekact)! - feat(pretty-json): 禁用美化功能时直接跳过该中间件
7
+ - 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)]:
8
+ - @aomex/web@0.0.8
9
+ - @aomex/core@0.0.7
8
10
 
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
-
21
- ## 0.0.3
11
+ ## 0.0.6
22
12
 
23
13
  ### Patch Changes
24
14
 
25
- - Updated dependencies [[`121253a`](https://github.com/aomex/aomex/commit/121253a6fc203e427bfd25e82d713bec6ac13b38), [`59dc183`](https://github.com/aomex/aomex/commit/59dc183bcec9b7221c18865563b38cba5d82869b), [`8cb74fd`](https://github.com/aomex/aomex/commit/8cb74fdd27626037aa9bc80cb2930e4f0d67f8e6), [`d834392`](https://github.com/aomex/aomex/commit/d834392b1e0f6333d66d11378d9f4ceb813a58a9), [`91feda4`](https://github.com/aomex/aomex/commit/91feda457dfa8bd8dd2c8f38bfaaf4f7f2f7702f)]:
26
- - @aomex/web@0.0.4
27
- - @aomex/core@0.0.3
28
-
29
- ## 0.0.2
30
-
31
- ### Patch Changes
32
-
33
- - [`61a8e1c`](https://github.com/aomex/aomex/commit/61a8e1c42cc707808c4dd4710f43afcb6477e642) Thanks [@geekact](https://github.com/geekact)! - 增加 web 插件 pretty-json
34
-
35
- - Updated dependencies [[`4735157`](https://github.com/aomex/aomex/commit/4735157c52d0abecc41d6c7f416280ebfd6ee696), [`d6ac7b5`](https://github.com/aomex/aomex/commit/d6ac7b5403334b51fa15dbe82dd6b5b6d048f661), [`9254754`](https://github.com/aomex/aomex/commit/9254754d234fc0062eb5d600284ee8453825306c), [`d1ce4e2`](https://github.com/aomex/aomex/commit/d1ce4e2276f93c44e67ea06666d048917fa94e53), [`6056f55`](https://github.com/aomex/aomex/commit/6056f556577865220d6b5be2a4eafad9e4dbf8d4), [`1c67399`](https://github.com/aomex/aomex/commit/1c673992c4b313c2accb4cbc1fc66537a9886c29), [`352642a`](https://github.com/aomex/aomex/commit/352642abf2ccb3fe97e2d83a691d8428ccfc9758)]:
36
- - @aomex/web@0.0.3
37
- - @aomex/core@0.0.2
15
+ - Updated dependencies [[`bbc8dda`](https://github.com/aomex/aomex/commit/bbc8dda9f0876c3402608133085350cc693def6f), [`ceb2d82`](https://github.com/aomex/aomex/commit/ceb2d8269755dca3f79b755224259b8a99bc65d0)]:
16
+ - @aomex/core@0.0.6
17
+ - @aomex/web@0.0.7
package/dist/index.d.ts CHANGED
@@ -2,15 +2,16 @@ import { WebMiddleware } from '@aomex/web';
2
2
 
3
3
  interface PrettyJsonOptions {
4
4
  /**
5
- * 是否格式化JSON数据,默认:`true`
5
+ * Enable middleware. Defaults `true`
6
6
  */
7
- pretty?: boolean;
7
+ enable?: boolean;
8
8
  /**
9
- * 在查询字符串(querystring)中使用指定参数来触发JSON格式化
9
+ * force enable with a param in querystring.
10
+ * - example.com?pretty
10
11
  */
11
12
  param?: string;
12
13
  /**
13
- * JSON每行缩进空格,默认:`2`
14
+ * Indent every line. Defaults `2`
14
15
  */
15
16
  spaces?: number;
16
17
  }
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@ 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 { pretty = true, spaces = 2, param } = options;
6
+ const { enable = true, spaces = 2, param } = options;
7
7
  return middleware.web(async (ctx, next) => {
8
8
  await next();
9
9
  const {
@@ -11,7 +11,7 @@ var prettyJson = (options = {}) => {
11
11
  response,
12
12
  response: { body }
13
13
  } = ctx;
14
- const prettify = pretty || param && Object.hasOwn(request.query, param);
14
+ const prettify = enable || param && Object.hasOwn(request.query, param);
15
15
  if (!prettify)
16
16
  return;
17
17
  if (body instanceof Readable && body.readableObjectMode) {
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每行缩进空格,默认:`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":[]}
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":[]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@aomex/pretty-json",
3
- "version": "0.0.5",
4
- "description": "格式化json数据中间件",
3
+ "version": "0.0.7",
4
+ "description": "Format JSON response",
5
5
  "keywords": [
6
6
  "pretty",
7
7
  "json"
@@ -30,15 +30,15 @@
30
30
  "access": "public"
31
31
  },
32
32
  "peerDependencies": {
33
- "@aomex/core": "^0.0.5",
34
- "@aomex/web": "^0.0.6"
33
+ "@aomex/core": "^0.0.7",
34
+ "@aomex/web": "^0.0.8"
35
35
  },
36
36
  "dependencies": {
37
37
  "streaming-json-stringify": "^3.1.0"
38
38
  },
39
39
  "devDependencies": {
40
- "@aomex/core": "^0.0.5",
41
- "@aomex/web": "^0.0.6",
40
+ "@aomex/core": "^0.0.7",
41
+ "@aomex/web": "^0.0.8",
42
42
  "@types/streaming-json-stringify": "^3.1.1"
43
43
  },
44
44
  "scripts": {}