Skip to content

Commit

Permalink
feat(format-json): ability to set indentation (#1807)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kepro committed Dec 1, 2023
1 parent 54875d5 commit 6ee7e63
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
7 changes: 7 additions & 0 deletions packages/format-json/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ export type JsonFormatterOptions = {
* @default "lingui"
*/
style?: "lingui" | "minimal"

/**
* Indentation of output JSON
*
* @default 2
*/
indentation?: number
}
```
Expand Down
12 changes: 11 additions & 1 deletion packages/format-json/src/json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ export type JsonFormatterOptions = {
* @default "lingui"
*/
style?: "lingui" | "minimal"

/**
* Indentation of output JSON
*
* @default 2
*/
indentation?: number
}

type NoOriginsCatalogType = {
Expand Down Expand Up @@ -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) {
Expand Down

1 comment on commit 6ee7e63

@vercel
Copy link

@vercel vercel bot commented on 6ee7e63 Dec 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.