Skip to content

Commit 7f0ca32

Browse files
toJSON pretty
1 parent 9ed1e8d commit 7f0ca32

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"**/.pnp.*": true
3535
},
3636
"editor.codeActionsOnSave": {
37-
"source.fixAll": true
37+
"source.fixAll": "explicit"
3838
},
3939
"cSpell.words": ["doctoc", "templating"]
4040
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"author": "Transcend Inc.",
33
"name": "@transcend-io/handlebars-utils",
44
"description": "Utility functions for handlebars templating with Transcend - available in node and client side.",
5-
"version": "1.1.0",
5+
"version": "1.2.0",
66
"homepage": "https://github.com/transcend-io/handlebars-utils",
77
"repository": {
88
"type": "git",

src/createHandlebars.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,24 @@ export const DEFAULT_HANDLEBARS_HELPERS = {
117117
}
118118
return v;
119119
}),
120+
/**
121+
* Pretty JSON stringify
122+
*
123+
* @param obj - The object to convert
124+
* @returns The object stringified
125+
*/
126+
toJSONPretty: <T extends ObjByString>(obj: T) =>
127+
JSON.stringify(
128+
obj,
129+
(k, v) => {
130+
// Necessary, else functions don't get written.
131+
if (typeof v === 'function') {
132+
return v.toString();
133+
}
134+
return v;
135+
},
136+
2,
137+
),
120138
/**
121139
* Compares two string to see if they're sorted
122140
*

0 commit comments

Comments
 (0)