Files
bruno/packages/bruno-lang/v1/src/utils.js
lohit 01360d1522 feat/(#1003): oauth2 support - styling fixes, code cleanup (#1674)
* feat/(#1003):  oauth2 support - styling fixes, code cleanup (#1674)
---------
Co-authored-by: lohit-1 <lohit@usebruno.com>
2024-02-27 21:12:34 +05:30

37 lines
559 B
JavaScript

// safely parse json
const safeParseJson = (json) => {
try {
return JSON.parse(json);
} catch (e) {
return null;
}
};
const indentString = (str) => {
if (!str || !str.length) {
return str || '';
}
return str
.split('\n')
.map((line) => ' ' + line)
.join('\n');
};
const outdentString = (str) => {
if (!str || !str.length) {
return str || '';
}
return str
.split('\n')
.map((line) => line.replace(/^ /, ''))
.join('\n');
};
module.exports = {
safeParseJson,
indentString,
outdentString
};