Skip to content

Commit 8c06c57

Browse files
C​⁠‌​⁠⁠‌​​⁠‍‌‌​​‍‌yprien Q​⁠‌​⁠⁠‌​​⁠‍‌‌​​‍‌uiliciblakeembrey
authored andcommitted
Document how to format the result (#29)
1 parent d4a81f4 commit 8c06c57

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,23 @@ stringify(["test", "string"], function(value, indent, stringify) {
8989
//=> '["test","string"]'
9090
```
9191

92+
## Formatting
93+
94+
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):
95+
96+
```javascript
97+
const { CLIEngine } = require("eslint");
98+
const { stringify } = require("javascript-stringify");
99+
100+
const { APP_ROOT_PATH, ESLINTRC_FILE_PATH } = require("./constants");
101+
102+
const ESLINT_CLI = new CLIEngine({ fix: true, cwd: APP_ROOT_PATH, configFile: ESLINTRC_FILE_PATH });
103+
104+
module.exports = (objectToStringify) => {
105+
return ESLINT_CLI.executeOnText(stringify(objectToStringify)).results[0].output;
106+
};
107+
```
108+
92109
## License
93110

94111
MIT

0 commit comments

Comments
 (0)