node-json-transform
Advanced tools
Comparing version 1.0.5 to 1.0.6
@@ -56,3 +56,8 @@ // DataTransform | ||
data = _.map(data, function(item){ | ||
var fn = eval(method.run); | ||
var fn; | ||
if( 'string' === typeof method.run ) { | ||
fn = eval( method.run ); | ||
} else { | ||
fn = method.run; | ||
} | ||
item[method.on] = fn(item[method.on]); | ||
@@ -59,0 +64,0 @@ return item; |
{ | ||
"name": "node-json-transform", | ||
"version": "1.0.5", | ||
"version": "1.0.6", | ||
"description": "A node module for transforming and performing operations on JSON.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -54,3 +54,6 @@ # node-data-transform | ||
operate: [ | ||
{run: "Date.parse", on: "date"} | ||
{ | ||
run: "Date.parse", on: "date", | ||
run: function(val) { return val + " more info"}, on: "info" | ||
} | ||
] | ||
@@ -79,3 +82,3 @@ }; | ||
link: "http://goo.cm", | ||
info: "mike", | ||
info: "mike more info", | ||
clearMe: "", | ||
@@ -90,5 +93,6 @@ fieldGroup: ['title1', { link : "http://goo.cm" }] | ||
1.0.5 Accepted pull request from jaymedavis. You can now pass an array directly and leave 'list' undefined. | ||
1.0.4 Added the ability to group fields into arrays | ||
1.0.3 Added the ability to clear and set field by passing an empty string in the map. | ||
1.0.6 Accepted pull request form ooskapenaar. You can now use custom functions as operators. | ||
1.0.5 Accepted pull request from jaymedavis. You can now pass an array directly and leave 'list' undefined. | ||
1.0.4 Added the ability to group fields into arrays | ||
1.0.3 Added the ability to clear and set field by passing an empty string in the map. | ||
@@ -95,0 +99,0 @@ ## Credits |
@@ -36,2 +36,9 @@ var DataTransform = require('../index.js').DataTransform, | ||
on: "date" | ||
},{ | ||
run: function customFn( item ){ | ||
if( 'string' === typeof item ) | ||
return item.toUpperCase(); | ||
return item.toString().toUpperCase(); | ||
}, | ||
on: "name" | ||
}] | ||
@@ -44,5 +51,5 @@ }; | ||
var dataTransform = DataTransform(data, map); | ||
var dataTransform = DataTransform(_.clone(data), map); | ||
expect(dataTransform.getValue(data, "posts.0.title")).toEqual("title1"); | ||
expect(dataTransform.getValue(data, "posts.0.description")).toEqual("description1"); | ||
@@ -53,6 +60,6 @@ }); | ||
var dataTransform = DataTransform(data, map); | ||
var dataTransform = DataTransform(_.clone(data), map); | ||
expect(dataTransform.transform()).toEqual([{ | ||
name: "title1", | ||
name: "TITLE1", | ||
info: "description1", | ||
@@ -74,6 +81,6 @@ text: "This is a blog.", | ||
var dataTransform = DataTransform(data, newMap); | ||
var dataTransform = DataTransform(_.clone(data), newMap); | ||
expect(dataTransform.transform()).toEqual([{ | ||
name: "title1", | ||
name: "TITLE1", | ||
info: "description1", | ||
@@ -96,6 +103,6 @@ text: "This is a blog.", | ||
var dataTransform = DataTransform(data, newMap); | ||
var dataTransform = DataTransform(_.clone(data), newMap); | ||
expect(dataTransform.transform()).toEqual([{ | ||
name: "title1", | ||
name: "TITLE1", | ||
text: "This is a blog.", | ||
@@ -120,3 +127,3 @@ date: 1383544800000, | ||
var dataTransform = DataTransform(data, newMap); | ||
var dataTransform = DataTransform(_.clone(data), newMap); | ||
@@ -161,3 +168,3 @@ expect(dataTransform.transform()).toEqual([{ | ||
var dataTransform = DataTransform(data, newMap); | ||
var dataTransform = DataTransform(_.clone(data), newMap); | ||
@@ -176,2 +183,24 @@ expect(dataTransform.transform()).toEqual([{ | ||
it("should allow you to use custom functions as operators", function(){ | ||
var newMap = _.clone(map); | ||
newMap.operate = [{ | ||
run: function (val){ | ||
return val + " more info"; | ||
}, | ||
on: "info" | ||
}]; | ||
var dataTransform = DataTransform(data, newMap); | ||
var result = dataTransform.transform(); | ||
expect(result).toEqual([{ | ||
name: 'title1', | ||
info: 'mike more info', | ||
text: 'This is a blog.', | ||
date: '11/4/2013', | ||
link: 'http://goo.cm' | ||
}]); | ||
}) | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9456
233
122