Merge pull request #180 from aeosynth/instanceof

instanceof Array
This commit is contained in:
Mayhem 2012-02-05 04:58:51 -08:00
commit 6742f09a4f
2 changed files with 12 additions and 16 deletions

View File

@ -186,17 +186,15 @@
(flatten = function(parent, obj) { (flatten = function(parent, obj) {
var key, val, _results; var key, val, _results;
if (typeof obj === 'object') { if (obj instanceof Array) {
if (obj.length) { return conf[parent] = obj[0];
return conf[parent] = obj[0]; } else if (typeof obj === 'object') {
} else { _results = [];
_results = []; for (key in obj) {
for (key in obj) { val = obj[key];
val = obj[key]; _results.push(flatten(key, val));
_results.push(flatten(key, val));
}
return _results;
} }
return _results;
} else { } else {
return conf[parent] = obj; return conf[parent] = obj;
} }

View File

@ -112,12 +112,10 @@ log = console.log.bind? console
# flatten the config # flatten the config
conf = {} conf = {}
(flatten = (parent, obj) -> (flatten = (parent, obj) ->
if typeof obj is 'object' if obj instanceof Array
# array conf[parent] = obj[0]
if obj.length else if typeof obj is 'object'
conf[parent] = obj[0] for key, val of obj
# object
else for key, val of obj
flatten key, val flatten key, val
else # string or number else # string or number
conf[parent] = obj conf[parent] = obj