You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
15 lines
354 B
15 lines
354 B
const stringifiedRegexp = /^'|".*'|"$/;
|
|
|
|
/**
|
|
* If already stringified - return original content
|
|
* @param {Object|Array} content
|
|
* @return {string}
|
|
*/
|
|
function stringify(content) {
|
|
if (typeof content === 'string' && stringifiedRegexp.test(content)) {
|
|
return content;
|
|
}
|
|
return JSON.stringify(content, null, 2);
|
|
}
|
|
|
|
module.exports = stringify;
|
|
|