Last active
August 29, 2015 14:07
-
-
Save adamterlson/a051f8ebb0e66b45010b to your computer and use it in GitHub Desktop.
Revisions
-
adamterlson revised this gist
Sep 29, 2014 . 1 changed file with 20 additions and 19 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,22 +1,23 @@ function sortProperties(objToSort) { var properties = Object.keys(objToSort).sort(); var result = {}; properties.forEach(function (prop) { if (!objToSort[prop]) { result[prop] = objToSort[prop]; } else if (Array.isArray(objToSort[prop])){ result[prop] = objToSort[prop].map(sortProperties); } else if (typeof objToSort[prop] === 'object') { result[prop] = sortProperties(objToSort[prop]); } else { result[prop] = objToSort[prop]; } }); return result; } ['./jsonFile'].forEach(function (location) { console.log(location, JSON.stringify(sortProperties(require(location)), null, 2)); }); -
adamterlson revised this gist
Sep 29, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ ['./jsonFile'].forEach(function (location) { function sortProperties(objToSort) { var properties = Object.keys(objToSort).sort(); var newObj = {}; -
adamterlson renamed this gist
Sep 29, 2014 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
adamterlson revised this gist
Sep 29, 2014 . 1 changed file with 0 additions and 7 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +0,0 @@ -
adamterlson revised this gist
Sep 29, 2014 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,7 +3,9 @@ var properties = Object.keys(objToSort).sort(); var newObj = {}; properties.forEach(function (prop) { if (!objToSort[prop]) { newObj[prop] = objToSort[prop]; } else if (Array.isArray(objToSort[prop])){ newObj[prop] = objToSort[prop].map(sortProperties); } -
adamterlson created this gist
Sep 29, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,7 @@ { "a": "asdf", "z": 12345, "c": 12134543, "b": 25000, "1": "tokens" } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,20 @@ ['./file'].forEach(function (location) { function sortProperties(objToSort) { var properties = Object.keys(objToSort).sort(); var newObj = {}; properties.forEach(function (prop) { if (!objToSort[prop]) n newObj[prop] = objToSort[prop]; else if (Array.isArray(objToSort[prop])){ newObj[prop] = objToSort[prop].map(sortProperties); } else if (typeof objToSort[prop] === 'object') { newObj[prop] = sortProperties(objToSort[prop]); } else { newObj[prop] = objToSort[prop]; } }); return newObj; } console.log(location, JSON.stringify(sortProperties(require(location)), null, 2)); });