Socket
Socket
Sign inDemoInstall

clang

Package Overview
Dependencies
Maintainers
1
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

clang - npm Package Compare versions

Comparing version 0.2.6 to 0.2.7

lib/fixtures.js

73

lib/clang.js
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

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