Comparing version 0.2.7 to 0.2.8
@@ -271,6 +271,4 @@ var _ = require('lodash'); | ||
Clang.prototype.transformFields = function(customer, options) { | ||
options = options || {} | ||
options.fieldMap = options.fieldMap || {}; | ||
_.merge(options.fieldMap, { | ||
Clang.prototype.transformFields = function(customer, options = {}) { | ||
options.fieldMap = Object.assign({ | ||
// default field mappings | ||
@@ -286,21 +284,23 @@ particle: 'prefix', | ||
} | ||
}); | ||
}, options.fieldMap || {}) | ||
// create a new object with altered keys and values based on the fieldMap configuration | ||
var transformedCustomer = {}; | ||
_.forOwn(customer, function(value, key) { | ||
var fieldMapTo = options.fieldMap[key]; | ||
let transformedCustomer = {} | ||
Object.keys(customer).forEach((key) => { | ||
let value = customer[key] | ||
let fieldMapTo = options.fieldMap[key] | ||
if (typeof fieldMapTo === 'string') { | ||
// set the value on a new key | ||
transformedCustomer[fieldMapTo] = value; | ||
// set the value on the new key | ||
transformedCustomer[fieldMapTo] = value | ||
} | ||
else if (typeof fieldMapTo === 'object') { | ||
// take the fieldName and values configuration of this fieldMap to transform the key and value | ||
transformedCustomer[fieldMapTo.fieldName] = fieldMapTo.values[value] || value; | ||
transformedCustomer[fieldMapTo.fieldName] = fieldMapTo.values[value] || value | ||
} | ||
else { | ||
// set the value on a the same key | ||
transformedCustomer[key] = value; | ||
// set the value on the same key | ||
transformedCustomer[key] = value | ||
} | ||
}); | ||
return transformedCustomer; | ||
}) | ||
return transformedCustomer | ||
}; | ||
@@ -307,0 +307,0 @@ |
{ | ||
"name": "clang", | ||
"version": "0.2.7", | ||
"version": "0.2.8", | ||
"description": "Node.js api wrapper for Clang's SOAP api", | ||
@@ -5,0 +5,0 @@ "author": "Christiaan Westerbeek <chris@devotis.nl>", |
@@ -97,6 +97,6 @@ var should = require('should'); | ||
var data = { | ||
a: 1, | ||
email: 'a@b.nl', | ||
gender: 'M', | ||
name: 'me' | ||
a: 1, | ||
email: 'a@b.nl', | ||
gender: 'M', | ||
name: 'me' | ||
} | ||
@@ -117,6 +117,17 @@ var options = { | ||
actual.should.be.deepEqual(expected) | ||
setImmediate(done) | ||
}); | ||
it('Transformation creates an new object', function(done) { | ||
var data = { | ||
a: 'a@b.nl' | ||
} | ||
var actual = clang.transformFields(data) | ||
actual.should.be.deepEqual(data) | ||
actual.should.not.be.equal(data) | ||
setImmediate(done) | ||
}); | ||
}); |
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
239184
6954