This commit is contained in:
Nathan Bierema 2020-08-05 09:04:42 -04:00
parent 3f63661b9a
commit f4bb8af1c8
3 changed files with 23 additions and 9 deletions

9
.prettierignore Normal file
View File

@ -0,0 +1,9 @@
*.log
.idea
lib
dist
umd
build
coverage
node_modules
__snapshots__

3
.prettierrc Normal file
View File

@ -0,0 +1,3 @@
{
"singleQuote": true
}

View File

@ -1,23 +1,25 @@
function sortObject(obj, strict) {
if (obj instanceof Array) {
let ary
let ary;
if (strict) {
ary = obj.sort()
ary = obj.sort();
} else {
ary = obj
ary = obj;
}
return ary
return ary;
}
if (obj && typeof obj === 'object') {
const tObj = {}
Object.keys(obj).sort().forEach(key => tObj[key] = sortObject(obj[key]))
return tObj
const tObj = {};
Object.keys(obj)
.sort()
.forEach(key => (tObj[key] = sortObject(obj[key])));
return tObj;
}
return obj
return obj;
}
export default function sortAndSerialize(obj) {
return JSON.stringify(sortObject(obj, true), undefined, 2)
return JSON.stringify(sortObject(obj, true), undefined, 2);
}