Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

node-json-transform

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-json-transform - npm Package Compare versions

Comparing version 1.0.9 to 1.0.10

34

index.js
// DataTransform
var _ = require('underscore');
var _ = require('lodash');

@@ -49,3 +49,4 @@ exports.DataTransform = function(data, map){

if(value) {
var normalized = _.map(this.getList(), _.bind(this.iterator, this));
var list = this.getList();
var normalized = map.item ? _.map(list, _.bind(this.iterator, this)) : list;
normalized = this.operate(normalized);

@@ -60,14 +61,16 @@ normalized = this.each(normalized);

_.each(map.operate, function(method){
data = _.map(data, function(item){
var fn;
if( 'string' === typeof method.run ) {
fn = eval( method.run );
} else {
fn = method.run;
}
item[method.on] = fn(item[method.on]);
return item;
if(map.operate) {
_.each(map.operate, function(method){
data = _.map(data, function(item){
var fn;
if( 'string' === typeof method.run ) {
fn = eval( method.run );
} else {
fn = method.run;
}
item[method.on] = fn(item[method.on]);
return item;
});
});
});
}
return data;

@@ -78,3 +81,6 @@

each: function(data){
return map.each ? _.each(this.getList(), map.each) : data;
if( map.each ) {
_.each(data, map.each);
}
return data;
},

@@ -81,0 +87,0 @@

{
"name": "node-json-transform",
"version": "1.0.9",
"description": "A node module for transforming and performing operations on JSON.",
"main": "index.js",
"scripts": {
"test": "node_modules/jasmine-node/bin/jasmine-node test/"
},
"repository": {
"type": "git",
"url": "https://github.com/bozzltron/node-json-transform"
},
"keywords": [
"json",
"transform",
"node"
],
"author": "Michael Bosworth",
"license": "MIT",
"bugs": {
"url": "https://github.com/bozzltron/node-json-transform/issues"
},
"homepage": "https://github.com/bozzltron/node-json-transform",
"dependencies": {
"underscore": "^1.7.0"
},
"devDependencies": {
"jasmine-node": "^1.14.5",
"underscore": "^1.8.3"
}
"name": "node-json-transform",
"version": "1.0.10",
"description": "A node module for transforming and performing operations on JSON.",
"main": "index.js",
"scripts": {
"test": "node_modules/jasmine-node/bin/jasmine-node test/"
},
"repository": {
"type": "git",
"url": "https://github.com/bozzltron/node-json-transform"
},
"keywords": [
"json",
"transform",
"node"
],
"author": "Michael Bosworth",
"license": "MIT",
"bugs": {
"url": "https://github.com/bozzltron/node-json-transform/issues"
},
"homepage": "https://github.com/bozzltron/node-json-transform",
"dependencies": {
"lodash": "^4.16.4"
},
"devDependencies": {
"jasmine-node": "^1.14.5",
"underscore": "^1.8.3"
}
}

@@ -100,2 +100,3 @@ # node-data-transform

## Changelog
1.0.10 Make each compatible with other options.
1.0.9 Updated the changelog.

@@ -102,0 +103,0 @@ 1.0.8 Added each functionality to the map.

@@ -255,4 +255,38 @@ var DataTransform = require('../index.js').DataTransform,

]);
})
});
it("should be able to combine mapping with each", function(){
var data = {
posts: [
{name: "peter"},
{name: "paul"},
{name: "marry"}
]
};
var map = {
list: 'posts',
item: {
title: 'name',
},
each: function(item){
item.iterated = true;
return item;
}
};
var dataTransform = DataTransform(data, map);
var result = dataTransform.transform();
expect(result).toEqual([
{title: "peter", iterated: true},
{title: "paul", iterated: true},
{title: "marry", iterated: true}
]);
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc