tfk-360-unwrap-contact
Advanced tools
Comparing version 2.0.1 to 2.0.2
31
index.js
'use strict' | ||
function unwrapContact (contact) { | ||
const resolve = (path, obj) => { | ||
return path.split('.').reduce((prev, curr) => { | ||
return prev ? prev[curr] : undefined | ||
}, obj) | ||
} | ||
module.exports = (contact) => { | ||
if (!contact) { | ||
throw new Error('Missing required input: contact object') | ||
} else if (!contact.GetPrivatePersonsResult) { | ||
throw new Error('Malformed contact object') | ||
} | ||
var person = false | ||
if (contact.GetPrivatePersonsResult) { | ||
if (contact.GetPrivatePersonsResult.PrivatePersons && contact.GetPrivatePersonsResult.PrivatePersons.PrivatePersonBase) { | ||
if (contact.GetPrivatePersonsResult.PrivatePersons.PrivatePersonBase.length === 1) { | ||
person = contact.GetPrivatePersonsResult.PrivatePersons.PrivatePersonBase[0] | ||
} else { | ||
throw new Error('More than 1 person in contact object') | ||
} | ||
} | ||
const person = resolve('GetPrivatePersonsResult.PrivatePersons.PrivatePersonBase', contact) || resolve('GetPrivatePersonsResult.PrivatePersons.PrivatePersonResult', contact) | ||
if (!person) { | ||
return false | ||
} else if (person.length === 1) { | ||
return person[0] | ||
} else if (person.length >= 1) { | ||
throw new Error('More than 1 person in contact object') | ||
} else { | ||
throw new Error('Malformed contact object') | ||
} | ||
return person | ||
} | ||
module.exports = unwrapContact |
{ | ||
"name": "tfk-360-unwrap-contact", | ||
"version": "2.0.1", | ||
"version": "2.0.2", | ||
"description": "Unwraps GetPrivatePersonsResult from Public 360", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -55,1 +55,9 @@ 'use strict' | ||
}) | ||
tap.test('It returns expected result', function (test) { | ||
var contact = require('./data/GetPrivatePersonNew.json') | ||
var expected = require('./data/unwrappedContactNew.json') | ||
var result = unwrapContact(contact) | ||
tap.equal(JSON.stringify(result), JSON.stringify(expected), 'Contact unwrapped OK') | ||
test.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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
11427
15
242
0