Skip to content

Commit

Permalink
sort the keys before save
Browse files Browse the repository at this point in the history
  • Loading branch information
christofferok committed May 20, 2017
1 parent 271a5a5 commit dccacc9
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lang.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,15 @@ function getLangs(dir){
}

function writeLangFile(file, json){

let sortedObject = {};
Object.keys(json)
.sort()
.forEach(function(v, i) {
sortedObject[v] = json[v];
});
return new Promise((resolve, reject) => {
fs.writeFile(file, JSON.stringify(json, null, " "), function(err) {
fs.writeFile(file, JSON.stringify(sortedObject, null, " "), function(err) {
if(err) reject(err);
else resolve(file);
});
Expand Down

0 comments on commit dccacc9

Please sign in to comment.