From 6ee7e63631387b634f0b3e753dae4417c27b7744 Mon Sep 17 00:00:00 2001 From: Kepro Date: Fri, 1 Dec 2023 08:21:33 +0100 Subject: [PATCH] feat(format-json): ability to set indentation (#1807) --- packages/format-json/README.md | 7 +++++++ packages/format-json/src/json.ts | 12 +++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/packages/format-json/README.md b/packages/format-json/README.md index fe12e98c6..a32c2aabd 100644 --- a/packages/format-json/README.md +++ b/packages/format-json/README.md @@ -52,6 +52,13 @@ export type JsonFormatterOptions = { * @default "lingui" */ style?: "lingui" | "minimal" + + /** + * Indentation of output JSON + * + * @default 2 + */ + indentation?: number } ``` diff --git a/packages/format-json/src/json.ts b/packages/format-json/src/json.ts index 305ab72ce..b9684c45b 100644 --- a/packages/format-json/src/json.ts +++ b/packages/format-json/src/json.ts @@ -28,6 +28,13 @@ export type JsonFormatterOptions = { * @default "lingui" */ style?: "lingui" | "minimal" + + /** + * Indentation of output JSON + * + * @default 2 + */ + indentation?: number } type NoOriginsCatalogType = { @@ -87,7 +94,10 @@ export function formatter( outputCatalog = serializeMinimal(outputCatalog) } - return JSON.stringify(outputCatalog, null, 2) + trailingNewLine + return ( + JSON.stringify(outputCatalog, null, options.indentation ?? 2) + + trailingNewLine + ) }, parse(content) {