12345678910111213141516171819202122 |
- module.exports = function sortObject (obj, keyOrder, dontSortByUnicode) {
- if (!obj) return
- const res = {}
- if (keyOrder) {
- keyOrder.forEach(key => {
- if (obj.hasOwnProperty(key)) {
- res[key] = obj[key]
- delete obj[key]
- }
- })
- }
- const keys = Object.keys(obj)
- !dontSortByUnicode && keys.sort()
- keys.forEach(key => {
- res[key] = obj[key]
- })
- return res
- }
|