diff --git a/package-lock.json b/package-lock.json index 30e69f3..c1ee10d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@swimlane/obfuscator", - "version": "1.1.0", + "version": "1.1.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index c54e828..1ceaed2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@swimlane/obfuscator", - "version": "1.1.0", + "version": "1.1.1", "description": "Obfuscate objects based on a JSON Schema", "main": "dist/index.js", "typings": "dist/index.d.ts", @@ -44,6 +44,14 @@ "json", "schema" ], + "repository": { + "type": "git", + "url": "git+https://github.com/swimlane/obfuscator.git" + }, + "bugs": { + "url": "https://github.com/swimlane/obfuscator/issues" + }, + "homepage": "https://github.com/swimlane/obfuscator#readme", "author": "Swimlane ", "license": "AGPL-3.0", "nyc": { diff --git a/src/Obfuscator.ts b/src/Obfuscator.ts index 2b28d5d..6ac5f92 100644 --- a/src/Obfuscator.ts +++ b/src/Obfuscator.ts @@ -233,6 +233,11 @@ export class Obfuscator { return newValue.map((nv, idx) => Obfuscator.unObfuscate(nv, prevValue[idx], replaceString)); } + // date objects are safe + if (newValue !== null && newValue instanceof Date) { + return newValue; + } + // unobfuscate values in an object if (newValue !== null && typeof newValue === 'object' && prevValue !== null && typeof prevValue === 'object') { const newObj = { ...newValue }; diff --git a/tests/Obfuscator.spec.ts b/tests/Obfuscator.spec.ts index 90c2f63..904df53 100644 --- a/tests/Obfuscator.spec.ts +++ b/tests/Obfuscator.spec.ts @@ -334,6 +334,20 @@ describe('Obfuscator', () => { expect(Obfuscator.unObfuscate(null, null)).to.be.null; done(); }); + + it('should handle dates', done => { + const newDate = new Date(); + const oldDate = new Date(new Date().getTime() - 1000); + const newVal = { + foo: Obfuscator.defaultReplaceString, + fizz: newDate + }; + const oldVal = { foo: 'bar', fizz: oldDate }; + const result = Obfuscator.unObfuscate(newVal, oldVal); + expect(result.fizz instanceof Date); + expect(result.fizz.getTime()).to.eq(newDate.getTime()); + done(); + }); }); describe('.predicateTypeFormat()', () => {