Comparing version 0.2.6 to 0.2.7
var _ = require('lodash'); | ||
var soap = require('soap'); | ||
var async = require('async'); | ||
var mock = require('./mock'); | ||
@@ -24,2 +25,6 @@ function Clang(config) { | ||
me.api = null; | ||
if (me.config.mock) { | ||
mock(me) | ||
} | ||
} | ||
@@ -141,34 +146,5 @@ | ||
options.lookup = options.lookup || 'externalId'; | ||
options.fieldMap = options.fieldMap || {}; | ||
_.merge(options.fieldMap, { | ||
// default field mappings | ||
particle: 'prefix', | ||
email: 'emailAddress', | ||
gender: { | ||
fieldName: 'gender', | ||
values: { | ||
M: 'MAN', | ||
F: 'WOMAN' | ||
} | ||
} | ||
}); | ||
// 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]; | ||
if (typeof fieldMapTo === 'string') { | ||
// set the value on a 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; | ||
} | ||
else { | ||
// set the value on a the same key | ||
transformedCustomer[key] = value; | ||
} | ||
}); | ||
customer = transformedCustomer; | ||
customer = me.transformFields(customer, options) | ||
var customerArgs = {}; | ||
@@ -297,2 +273,37 @@ if (options.lookup === 'externalId') { | ||
Clang.prototype.transformFields = function(customer, options) { | ||
options = options || {} | ||
options.fieldMap = options.fieldMap || {}; | ||
_.merge(options.fieldMap, { | ||
// default field mappings | ||
particle: 'prefix', | ||
email: 'emailAddress', | ||
gender: { | ||
fieldName: 'gender', | ||
values: { | ||
M: 'MAN', | ||
F: 'WOMAN' | ||
} | ||
} | ||
}); | ||
// 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]; | ||
if (typeof fieldMapTo === 'string') { | ||
// set the value on a 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; | ||
} | ||
else { | ||
// set the value on a the same key | ||
transformedCustomer[key] = value; | ||
} | ||
}); | ||
return transformedCustomer; | ||
}; | ||
//Private stuff starts here | ||
@@ -299,0 +310,0 @@ var setMethods = { |
{ | ||
"name": "clang", | ||
"version": "0.2.6", | ||
"version": "0.2.7", | ||
"description": "Node.js api wrapper for Clang's SOAP api", | ||
@@ -17,12 +17,12 @@ "author": "Christiaan Westerbeek <chris@devotis.nl>", | ||
"engines": { | ||
"node": "*" | ||
"node": ">=4.4.5" | ||
}, | ||
"dependencies": { | ||
"async": "^2.1.2", | ||
"lodash": "^4.16.4", | ||
"soap": "^0.17.0" | ||
"async": "2.4.1", | ||
"lodash": "4.17.4", | ||
"soap": "0.19.2" | ||
}, | ||
"devDependencies": { | ||
"mocha": "^2.3.4", | ||
"should": "^7.1.1" | ||
"mocha": "^3.4.2", | ||
"should": "^11.2.1" | ||
}, | ||
@@ -29,0 +29,0 @@ "directories": { |
@@ -93,1 +93,29 @@ var should = require('should'); | ||
}); | ||
describe('Fields', function() { | ||
it('Transform well', function(done) { | ||
var data = { | ||
a: 1, | ||
email: 'a@b.nl', | ||
gender: 'M', | ||
name: 'me' | ||
} | ||
var options = { | ||
fieldMap: { | ||
name: 'firstname' | ||
} | ||
} | ||
var actual = clang.transformFields(data, options) | ||
var expected = { | ||
a: 1, | ||
emailAddress: 'a@b.nl', | ||
gender: 'MAN', | ||
firstname: 'me' | ||
} | ||
actual.should.be.deepEqual(expected) | ||
setImmediate(done) | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
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
238952
11
6946
+ Addedasync@2.4.1(transitive)
+ Addedbuffer-from@1.1.2(transitive)
+ Addedconcat-stream@1.6.2(transitive)
+ Addedcore-util-is@1.0.3(transitive)
+ Addeddebug@2.2.02.6.9(transitive)
+ Addeddepd@2.0.0(transitive)
+ Addeddestroy@1.2.0(transitive)
+ Addedee-first@1.1.1(transitive)
+ Addedejs@2.5.9(transitive)
+ Addedencodeurl@1.0.22.0.0(transitive)
+ Addedescape-html@1.0.3(transitive)
+ Addedetag@1.8.1(transitive)
+ Addedfinalhandler@0.5.1(transitive)
+ Addedfresh@0.5.2(transitive)
+ Addedhttp-errors@2.0.0(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedisarray@1.0.0(transitive)
+ Addedlodash@4.17.4(transitive)
+ Addedmime@1.6.0(transitive)
+ Addedms@0.7.12.0.02.1.3(transitive)
+ Addedon-finished@2.3.02.4.1(transitive)
+ Addedparseurl@1.3.3(transitive)
+ Addedprocess-nextick-args@2.0.1(transitive)
+ Addedrange-parser@1.2.1(transitive)
+ Addedreadable-stream@2.3.8(transitive)
+ Addedsafe-buffer@5.1.2(transitive)
+ Addedsend@0.19.0(transitive)
+ Addedserve-static@1.16.2(transitive)
+ Addedsetprototypeof@1.2.0(transitive)
+ Addedsoap@0.19.2(transitive)
+ Addedstatuses@1.3.12.0.1(transitive)
+ Addedstring_decoder@1.1.1(transitive)
+ Addedtoidentifier@1.0.1(transitive)
+ Addedtypedarray@0.0.6(transitive)
+ Addedunpipe@1.0.0(transitive)
+ Addedutil-deprecate@1.0.2(transitive)
- Removedasync@2.6.4(transitive)
- Removedejs@2.3.4(transitive)
- Removedlodash@4.17.21(transitive)
- Removednode-uuid@1.4.8(transitive)
- Removedoptional@0.1.4(transitive)
- Removedsafe-buffer@5.2.1(transitive)
- Removedsoap@0.17.0(transitive)
Updatedasync@2.4.1
Updatedlodash@4.17.4
Updatedsoap@0.19.2