From 607f48277a4f0000af195c25446672d4e306fc7f Mon Sep 17 00:00:00 2001 From: Kengo Watanabe Date: Sat, 18 May 2024 12:54:30 +0900 Subject: [PATCH] Pretty JSON Middleware --- deno_dist/middleware/pretty-json/index.ts | 19 +++++++++++++++++++ src/middleware/pretty-json/index.ts | 19 +++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/deno_dist/middleware/pretty-json/index.ts b/deno_dist/middleware/pretty-json/index.ts index 002631f2d..1faac1768 100644 --- a/deno_dist/middleware/pretty-json/index.ts +++ b/deno_dist/middleware/pretty-json/index.ts @@ -4,6 +4,25 @@ type prettyOptions = { space: number } +/** + * Pretty JSON middleware for Hono. + * + * @see {@link https://hono.dev/middleware/builtin/pretty-json} + * + * @param {prettyOptions} [options] - The options for the pretty JSON middleware. + * @param {number} [options.space=2] - Number of spaces for indentation. + * @returns {MiddlewareHandler} The middleware handler function. + * + * @example + * ```ts + * const app = new Hono() + * + * app.use(prettyJSON()) // With options: prettyJSON({ space: 4 }) + * app.get('/', (c) => { + * return c.json({ message: 'Hono!' }) + * }) + * ``` + */ export const prettyJSON = (options: prettyOptions = { space: 2 }): MiddlewareHandler => { return async function prettyJSON(c, next) { const pretty = c.req.query('pretty') || c.req.query('pretty') === '' ? true : false diff --git a/src/middleware/pretty-json/index.ts b/src/middleware/pretty-json/index.ts index dbf824298..17a54d8f7 100644 --- a/src/middleware/pretty-json/index.ts +++ b/src/middleware/pretty-json/index.ts @@ -4,6 +4,25 @@ type prettyOptions = { space: number } +/** + * Pretty JSON middleware for Hono. + * + * @see {@link https://hono.dev/middleware/builtin/pretty-json} + * + * @param {prettyOptions} [options] - The options for the pretty JSON middleware. + * @param {number} [options.space=2] - Number of spaces for indentation. + * @returns {MiddlewareHandler} The middleware handler function. + * + * @example + * ```ts + * const app = new Hono() + * + * app.use(prettyJSON()) // With options: prettyJSON({ space: 4 }) + * app.get('/', (c) => { + * return c.json({ message: 'Hono!' }) + * }) + * ``` + */ export const prettyJSON = (options: prettyOptions = { space: 2 }): MiddlewareHandler => { return async function prettyJSON(c, next) { const pretty = c.req.query('pretty') || c.req.query('pretty') === '' ? true : false