dottie
Advanced tools
Comparing version 0.2.1 to 0.2.2
@@ -92,4 +92,13 @@ (function(undefined) { | ||
// Transform unnested object with .-seperated keys into a nested object. | ||
Dottie.transform = function(object) { | ||
var pieces, piecesLength, current, transformed = {}, piece; | ||
Dottie.transform = function(object, options) { | ||
if (Array.isArray(object)) { | ||
return object.map(Dottie.transform); | ||
} | ||
var pieces, | ||
piecesLength, | ||
piece, | ||
current, | ||
transformed = {}; | ||
for (var key in object) { | ||
@@ -96,0 +105,0 @@ if (key.indexOf('.') !== -1) { |
{ | ||
"name": "dottie", | ||
"version": "0.2.1", | ||
"version": "0.2.2", | ||
"devDependencies": { | ||
@@ -5,0 +5,0 @@ "expect.js": "~0.2.0", |
@@ -103,2 +103,21 @@ var expect = require("expect.js"), | ||
}); | ||
it("supports arrays", function () { | ||
var values = [ | ||
{ | ||
'customer.name': 'John Doe', | ||
'customer.age': 15, | ||
'client': 'Lolcat' | ||
}, | ||
{ | ||
'client.name': 'John Doe', | ||
'client.age': 15, | ||
'customer': 'Lolcat' | ||
} | ||
]; | ||
var transformed = dottie.transform(values); | ||
expect(transformed[0].customer.name).to.equal('John Doe'); | ||
expect(transformed[1].client.name).to.equal('John Doe'); | ||
}); | ||
}); |
13106
357