@kitql/helper
Advanced tools
Comparing version 0.1.5 to 0.1.6
export { Log, logMagneta, logCyan, logGreen, logRed, logYellow } from './Log'; | ||
export { queryStringApprend } from './queryStringApprend'; | ||
export { stry } from './stry'; |
34
index.js
@@ -62,2 +62,35 @@ 'use strict'; | ||
function sortObject(object) { | ||
var sortedObj = {}; | ||
var keys = Object.keys(object); | ||
keys.sort(function (key1, key2) { | ||
(key1 = key1.toLowerCase()), (key2 = key2.toLowerCase()); | ||
if (key1 < key2) | ||
return -1; | ||
if (key1 > key2) | ||
return 1; | ||
return 0; | ||
}); | ||
for (var index in keys) { | ||
var key = keys[index]; | ||
if (typeof object[key] == 'object' && !(object[key] instanceof Array) && object[key]) { | ||
sortedObj[key] = sortObject(object[key]); | ||
} | ||
else { | ||
sortedObj[key] = object[key]; | ||
} | ||
} | ||
return sortedObj; | ||
} | ||
function stry(obj, space = 2) { | ||
if (obj === null) { | ||
return null; | ||
} | ||
else if (obj === undefined) { | ||
return undefined; | ||
} | ||
const ordered = sortObject(obj); | ||
return JSON.stringify(ordered, null, space); | ||
} | ||
exports.Log = Log; | ||
@@ -70,1 +103,2 @@ exports.logCyan = logCyan; | ||
exports.queryStringApprend = queryStringApprend; | ||
exports.stry = stry; |
{ | ||
"name": "@kitql/helper", | ||
"version": "0.1.5", | ||
"version": "0.1.6", | ||
"repository": { | ||
@@ -5,0 +5,0 @@ "type": "git", |
Sorry, the diff of this file is not supported yet
6752
8
212