mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-11 14:36:25 +00:00
feat: add stringToPrettyJSON handlebars function (#12643)
This commit is contained in:
parent
ab5abd7553
commit
c80c7f3d0c
4 changed files with 28 additions and 0 deletions
|
@ -20,3 +20,13 @@ Some are configuration options passed through, while others are generated as par
|
|||
## Other available fields
|
||||
|
||||
<!-- Insert runtime fields here -->
|
||||
|
||||
## Additional Handlebars helpers
|
||||
|
||||
### stringToPrettyJSON
|
||||
|
||||
If you want to print pretty JSON with Handlebars you can use the built-in function `stringToPrettyJSON` like this:
|
||||
|
||||
`{{{stringToPrettyJSON myvar}}}`
|
||||
|
||||
In the example above `myvar` is a variable/field, that contains valid JSON.
|
||||
|
|
|
@ -1,3 +1,11 @@
|
|||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`util/template/index filters out disallowed fields 1`] = `"github token = \\"\\""`;
|
||||
|
||||
exports[`util/template/index string to pretty JSON 1`] = `
|
||||
"{
|
||||
\\"some\\": {
|
||||
\\"fancy\\": \\"json\\"
|
||||
}
|
||||
}"
|
||||
`;
|
||||
|
|
|
@ -18,4 +18,10 @@ describe('util/template/index', () => {
|
|||
expect(output).toContain('github');
|
||||
expect(output).not.toContain('123test');
|
||||
});
|
||||
it('string to pretty JSON ', () => {
|
||||
const userTemplate =
|
||||
'{{{ stringToPrettyJSON \'{"some":{"fancy":"json"}}\'}}}';
|
||||
const output = template.compile(userTemplate, undefined);
|
||||
expect(output).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -6,6 +6,10 @@ import { clone } from '../clone';
|
|||
|
||||
handlebars.registerHelper('encodeURIComponent', encodeURIComponent);
|
||||
|
||||
handlebars.registerHelper('stringToPrettyJSON', (input: string): string =>
|
||||
JSON.stringify(JSON.parse(input), null, 2)
|
||||
);
|
||||
|
||||
// istanbul ignore next
|
||||
handlebars.registerHelper(
|
||||
'replace',
|
||||
|
|
Loading…
Reference in a new issue