Skip to content

Commit e64853a

Browse files
authored
Merge pull request #24 from technicallyfeasible/bug/using-es6
Fixing unexpected usage of es6 arrow functions in published file
2 parents e62709e + 05be9b0 commit e64853a

File tree

1 file changed

+24
-21
lines changed

1 file changed

+24
-21
lines changed

index.js

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,20 @@ exports.DataTransform = function(data, map){
1212

1313
getValue : function(obj, key, newKey) {
1414

15-
if(typeof(obj) == "undefined") {
15+
if(typeof obj === 'undefined') {
1616
return;
1717
}
1818

1919
if(key == '' || key == undefined) {
2020
return obj;
2121
}
2222

23-
var value = obj || data,
24-
key = key || map.list,
25-
keys = null;
26-
if(key == "") {
27-
value = "";
23+
var value = obj || data;
24+
var keys = null;
25+
26+
key = key || map.list;
27+
if(key == '') {
28+
value = '';
2829
} else {
2930
keys = key.split('.');
3031
for(var i = 0; i < keys.length; i++ ) {
@@ -43,22 +44,22 @@ exports.DataTransform = function(data, map){
4344

4445
setValue : function(obj, key, newValue) {
4546

46-
if(typeof(obj) == "undefined") {
47+
if(typeof obj === "undefined") {
4748
return;
4849
}
4950

5051
if(key == '' || key == undefined) {
5152
return;
5253
}
5354

54-
if(key == "") {
55+
if(key == '') {
5556
return;
5657
}
5758

58-
keys = key.split('.');
59+
var keys = key.split('.');
5960
var target = obj;
6061
for(var i = 0; i < keys.length; i++ ) {
61-
if(i == keys.length-1){
62+
if(i === keys.length - 1) {
6263
target[keys[i]] = newValue;
6364
return;
6465
}
@@ -74,12 +75,12 @@ exports.DataTransform = function(data, map){
7475

7576
transform : function(context) {
7677

77-
var value = this.getValue(data, map.list),
78-
normalized = {};
78+
var value = this.getValue(data, map.list);
79+
var normalized = {};
7980

8081
if(value) {
8182
var list = this.getList();
82-
var normalized = map.item ? _.map(list, _.bind(this.iterator, this, map.item)) : list;
83+
normalized = map.item ? _.map(list, _.bind(this.iterator, this, map.item)) : list;
8384
normalized = _.bind(this.operate, this, normalized)(context);
8485
normalized = this.each(normalized, context);
8586
normalized = this.removeAll(normalized);
@@ -97,7 +98,7 @@ exports.DataTransform = function(data, map){
9798
},
9899

99100
remove: function(item){
100-
_.each(map.remove, (key)=>{
101+
_.each(map.remove, function (key) {
101102
delete item[key];
102103
});
103104
return item;
@@ -114,7 +115,7 @@ exports.DataTransform = function(data, map){
114115
} else {
115116
fn = method.run;
116117
}
117-
this.setValue(item,method.on,fn(this.getValue(item,method.on), context))
118+
this.setValue(item,method.on,fn(this.getValue(item,method.on), context));
118119
return item;
119120
},this));
120121
},this));
@@ -125,7 +126,9 @@ exports.DataTransform = function(data, map){
125126

126127
each: function(data, context){
127128
if( map.each ) {
128-
_.each(data, (value, index, collection) => map.each(value, index, collection, context));
129+
_.each(data, function (value, index, collection) {
130+
return map.each(value, index, collection, context);
131+
});
129132
}
130133
return data;
131134
},
@@ -135,17 +138,17 @@ exports.DataTransform = function(data, map){
135138
var obj = {};
136139

137140
//to support simple arrays with recursion
138-
if(typeof(map) == "string") {
141+
if(typeof map === 'string') {
139142
return this.getValue(item, map);
140143
}
141144
_.each(map, _.bind(function(oldkey, newkey) {
142-
if(typeof(oldkey) == "string" && oldkey.length > 0) {
145+
if(typeof oldkey === 'string' && oldkey.length > 0) {
143146
obj[newkey] = this.getValue(item, oldkey, newkey);
144147
} else if( _.isArray(oldkey) ) {
145-
array = _.map(oldkey, _.bind(function(item,map) {return this.iterator(map,item)}, this , item));//need to swap arguments for bind
148+
var array = _.map(oldkey, _.bind(function(item,map) {return this.iterator(map,item)}, this , item));//need to swap arguments for bind
146149
obj[newkey] = array;
147-
} else if(typeof oldkey == 'object'){
148-
var bound = _.bind(this.iterator, this, oldkey,item)
150+
} else if(typeof oldkey === 'object'){
151+
var bound = _.bind(this.iterator, this, oldkey,item);
149152
obj[newkey] = bound();
150153
}
151154
else {

0 commit comments

Comments
 (0)