POJOs: use non-enum keys as well; normalize key order

This commit is contained in:
Conduitry 2018-03-17 22:21:25 -04:00
parent 056077ee15
commit d4160ef4fd
1 changed files with 4 additions and 2 deletions

View File

@ -7,14 +7,16 @@ let BUFFER = Symbol()
let array
let recurse = obj => {
let temp
if (typeof obj === 'object' && obj !== null) {
switch (Object.getPrototypeOf(obj)) {
case Array.prototype:
array.push(ARRAY, obj.length), obj.forEach(recurse)
return
case Object.prototype:
array.push(OBJECT, Object.keys(obj).length, ...Object.keys(obj))
Object.values(obj).forEach(recurse)
temp = Object.getOwnPropertyNames(obj).sort()
array.push(OBJECT, temp.length, ...temp)
temp.forEach(key => recurse(obj[key]))
return
case RegExp.prototype:
array.push(REGEXP, obj.source, obj.flags)