@sendgrid/helpers
Advanced tools
Comparing version 6.1.2 to 6.1.3
@@ -58,3 +58,3 @@ 'use strict'; | ||
data = deepClone(data); | ||
data = toCamelCase(data); | ||
data = toCamelCase(data, ['substitutions', 'customArgs']); | ||
@@ -543,3 +543,3 @@ //Extract properties from data | ||
//Return as snake cased object | ||
return toSnakeCase(json); | ||
return toSnakeCase(json, ['substitutions', 'customArgs']); | ||
} | ||
@@ -546,0 +546,0 @@ |
@@ -50,3 +50,3 @@ 'use strict'; | ||
data = deepClone(data); | ||
data = toCamelCase(data); | ||
data = toCamelCase(data, ['substitutions', 'customArgs']); | ||
@@ -252,3 +252,5 @@ //Extract properties from data | ||
if (typeof substitutions !== 'object') { | ||
throw new Error('Object expected for `substitutions` in reverseMergeSubstitutions'); | ||
throw new Error( | ||
'Object expected for `substitutions` in reverseMergeSubstitutions' | ||
); | ||
} | ||
@@ -316,3 +318,3 @@ this.substitutions = Object.assign({}, substitutions, this.substitutions); | ||
//Return as snake cased object | ||
return toSnakeCase(json, ['substitutions']); | ||
return toSnakeCase(json, ['substitutions', 'customArgs']); | ||
} | ||
@@ -319,0 +321,0 @@ } |
@@ -605,2 +605,23 @@ 'use strict'; | ||
}); | ||
it('should not modify the keys of substitutions and custom args', () => { | ||
const data = { | ||
to: 'to@example.org', | ||
customArgs: {snake_case: 'Test', T_EST: 'Test', camelCase: 'Test'}, | ||
substitutions: {snake_case: 'Test', T_EST: 'Test', camelCase: 'Test'}, | ||
}; | ||
p.fromData(data); | ||
const json = p.toJSON(); | ||
expect(json.substitutions).to.have.property('{{T_EST}}'); | ||
expect(json.substitutions).to.have.property('{{camelCase}}'); | ||
expect(json.substitutions).to.have.property('{{snake_case}}'); | ||
expect(json.substitutions['{{T_EST}}']).to.equal('Test'); | ||
expect(json.substitutions['{{camelCase}}']).to.equal('Test'); | ||
expect(json.substitutions['{{snake_case}}']).to.equal('Test'); | ||
expect(json.custom_args).to.have.property('T_EST'); | ||
expect(json.custom_args).to.have.property('camelCase'); | ||
expect(json.custom_args).to.have.property('snake_case'); | ||
expect(json.custom_args.T_EST).to.equal('Test'); | ||
expect(json.custom_args.camelCase).to.equal('Test'); | ||
expect(json.custom_args.snake_case).to.equal('Test'); | ||
}); | ||
}); | ||
@@ -619,4 +640,4 @@ | ||
headers: {test: 'Test'}, | ||
customArgs: {test: 'Test'}, | ||
substitutions: {test: 'Test'}, | ||
customArgs: {snake_case: 'Test', T_EST: 'Test', camelCase: 'Test'}, | ||
substitutions: {snake_case: 'Test', T_EST: 'Test', camelCase: 'Test'}, | ||
substitutionWrappers: ['[', ']'], | ||
@@ -626,3 +647,3 @@ }; | ||
//Tests | ||
it('should call fromData() from the constructor', function() { | ||
it('should call fromData() from the constructor', () => { | ||
p = new Personalization(data); | ||
@@ -632,3 +653,3 @@ expect(p.to[0].email).to.equal('to@example.org'); | ||
}); | ||
it('should throw an error for invalid input', function() { | ||
it('should throw an error for invalid input', () => { | ||
expect(function() { | ||
@@ -638,3 +659,3 @@ p.fromData(5); | ||
}); | ||
it('should have set all properties', function() { | ||
it('should have set all properties', () => { | ||
p.fromData(data); | ||
@@ -649,7 +670,16 @@ expect(p.to[0].email).to.equal('to@example.org'); | ||
expect(p.headers.test).to.equal('Test'); | ||
expect(p.customArgs.test).to.equal('Test'); | ||
expect(p.substitutions.test).to.equal('Test'); | ||
expect(p.customArgs.snake_case).to.equal('Test'); | ||
expect(p.substitutions.snake_case).to.equal('Test'); | ||
expect(p.substitutionWrappers).to.have.members(['[', ']']); | ||
}); | ||
it('should not modify the keys of substitutions and custom args', () => { | ||
p.fromData(data); | ||
expect(p.substitutions.T_EST).to.equal('Test'); | ||
expect(p.substitutions.camelCase).to.equal('Test'); | ||
expect(p.substitutions.snake_case).to.equal('Test'); | ||
expect(p.customArgs.T_EST).to.equal('Test'); | ||
expect(p.customArgs.camelCase).to.equal('Test'); | ||
expect(p.customArgs.snake_case).to.equal('Test'); | ||
}); | ||
}); | ||
}); |
@@ -18,2 +18,7 @@ 'use strict'; | ||
//Ensure array for ignored values | ||
if (!Array.isArray(ignored)) { | ||
ignored = []; | ||
} | ||
//Process all properties | ||
@@ -24,5 +29,9 @@ for (const key in obj) { | ||
//Convert key to snake case | ||
const converted = converter(key); | ||
//Recursive for child objects, unless ignored | ||
//The ignored check checks both variants of the key | ||
if (typeof obj[key] === 'object' && obj[key] !== null) { | ||
if (!Array.isArray(ignored) || !ignored.includes(key)) { | ||
if (!ignored.includes(key) && !ignored.includes(converted)) { | ||
obj[key] = convertKeys(obj[key], converter, ignored); | ||
@@ -33,3 +42,2 @@ } | ||
//Convert key to snake case and set if needed | ||
const converted = converter(key); | ||
if (converted !== key) { | ||
@@ -36,0 +44,0 @@ obj[converted] = obj[key]; |
@@ -65,11 +65,11 @@ 'use strict'; | ||
it('should not converted nested objects if ignored', function() { | ||
convertKeys(objCopy, strToCamelCase, ['nestedCamelCase']); | ||
convertKeys(objCopy, strToCamelCase, ['nestedSnakeCase']); | ||
expect(objCopy.nestedCamelCase).to.have.property('a'); | ||
expect(objCopy.nestedCamelCase).to.have.property('snakeCase'); | ||
expect(objCopy.nestedCamelCase).to.have.property('camelCase'); | ||
expect(objCopy.nestedCamelCase).not.to.have.property('snake_case'); | ||
expect(objCopy.nestedSnakeCase).to.have.property('a'); | ||
expect(objCopy.nestedSnakeCase).to.have.property('snakeCase'); | ||
expect(objCopy.nestedSnakeCase).to.have.property('camelCase'); | ||
expect(objCopy.nestedSnakeCase).not.to.have.property('snake_case'); | ||
expect(objCopy.nestedCamelCase).to.have.property('a'); | ||
expect(objCopy.nestedCamelCase).to.have.property('camelCase'); | ||
expect(objCopy.nestedCamelCase).to.have.property('snake_case'); | ||
expect(objCopy.nestedCamelCase).not.to.have.property('snakeCase'); | ||
expect(objCopy.nestedSnakeCase).to.have.property('snake_case'); | ||
expect(objCopy.nestedSnakeCase).not.to.have.property('snakeCase'); | ||
}); | ||
@@ -76,0 +76,0 @@ it('should throw an error for non object input', function() { |
@@ -11,3 +11,3 @@ 'use strict'; | ||
*/ | ||
describe('splitNameEmail()', function() { | ||
describe('splitNameEmail', function() { | ||
it('should not split strings without < symbol', function() { | ||
@@ -14,0 +14,0 @@ const [name, email] = splitNameEmail('test@test.com'); |
{ | ||
"name": "@sendgrid/helpers", | ||
"description": "SendGrid NodeJS internal helpers", | ||
"version": "6.1.2", | ||
"version": "6.1.3", | ||
"author": "SendGrid <dx@sendgrid.com> (sendgrid.com)", | ||
@@ -6,0 +6,0 @@ "contributors": [ |
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
89803
2998