From 8c06c57b063883d34bb523f4cf68caabb68fc964 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=E2=80=8B=E2=81=A0=E2=80=8C=E2=80=8B=E2=81=A0=E2=81=A0?= =?UTF-8?q?=E2=80=8C=E2=80=8B=EF=BB=BF=E2=80=8B=E2=81=A0=E2=80=8D=E2=80=8C?= =?UTF-8?q?=E2=80=8C=E2=80=8B=E2=80=8B=E2=80=8D=E2=80=8Cyprien=20Q?= =?UTF-8?q?=E2=80=8B=E2=81=A0=E2=80=8C=E2=80=8B=E2=81=A0=E2=81=A0=E2=80=8C?= =?UTF-8?q?=E2=80=8B=EF=BB=BF=E2=80=8B=E2=81=A0=E2=80=8D=E2=80=8C=E2=80=8C?= =?UTF-8?q?=E2=80=8B=E2=80=8B=E2=80=8D=E2=80=8Cuilici?= Date: Thu, 14 Nov 2019 05:01:51 +0100 Subject: [PATCH] Document how to format the result (#29) --- README.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/README.md b/README.md index 89cabbd..07e3513 100644 --- a/README.md +++ b/README.md @@ -89,6 +89,23 @@ stringify(["test", "string"], function(value, indent, stringify) { //=> '["test","string"]' ``` +## Formatting + +You can use your own code formatter on the result of `javascript-stringify`. Here is an example using [eslint](https://www.npmjs.com/package/eslint): + +```javascript +const { CLIEngine } = require("eslint"); +const { stringify } = require("javascript-stringify"); + +const { APP_ROOT_PATH, ESLINTRC_FILE_PATH } = require("./constants"); + +const ESLINT_CLI = new CLIEngine({ fix: true, cwd: APP_ROOT_PATH, configFile: ESLINTRC_FILE_PATH }); + +module.exports = (objectToStringify) => { + return ESLINT_CLI.executeOnText(stringify(objectToStringify)).results[0].output; +}; +``` + ## License MIT