Comparing version 1.2.3 to 1.3.0
{ | ||
"name": "quizas", | ||
"version": "1.2.3", | ||
"version": "1.3.0", | ||
"description": "A sort-of monad for reading values from objects", | ||
@@ -5,0 +5,0 @@ "main": "src/quizas", |
@@ -125,2 +125,6 @@ "use strict"; | ||
var value = prop.pluck ? q.pluck.apply(q, prop.pluck) : q.value; | ||
if(isSet(value) && prop.transform){ | ||
value = prop.transform(value); | ||
} | ||
if(isSet(value)){ | ||
@@ -152,3 +156,7 @@ plucked = deepWrite(plucked, prop.target, value); | ||
var value = prop.pluck ? q.pluck.apply(q, prop.pluck) : q.value; | ||
if(value){ | ||
if(isSet(value) && prop.transform){ | ||
value = prop.transform(value); | ||
} | ||
if(isSet(value)){ | ||
extracted = deepWrite(extracted, prop.target, value); | ||
@@ -155,0 +163,0 @@ } |
@@ -118,2 +118,23 @@ 'use strict'; | ||
it('Should be able to transform values whilst extracting', function(){ | ||
var transform = function(date){ | ||
return new Date(date).toString(); | ||
}; | ||
var expected = transform(fixtures.esArticle._source._lastUpdatedDateTime); | ||
var result = quizas(fixtures.esArticle, '_source').extract({source:'_lastUpdatedDateTime', target:'date', transform:transform}); | ||
expect(result).to.have.property('date'); | ||
expect(result.date).to.equal(expected); | ||
}); | ||
it('Should be able to transform values whilst plucking', function(){ | ||
var transform = function(date){ | ||
return new Date(date).toString(); | ||
}; | ||
var expected = fixtures.esResults.hits.hits.map(function(hit){ | ||
return {date:transform(hit._source._lastUpdatedDateTime)}; | ||
}); | ||
var result = quizas(fixtures.esResults, 'hits.hits').pluck({source:'_source._lastUpdatedDateTime', target:'date', transform:transform}) | ||
expect(result).to.deep.equal(expected); | ||
}); | ||
describe('Bugs', function() { | ||
@@ -120,0 +141,0 @@ |
515803
13398