diff --git a/src/change-by-example-spec.js b/src/change-by-example-spec.js index 8b8d8f1..e3c7244 100644 --- a/src/change-by-example-spec.js +++ b/src/change-by-example-spec.js @@ -44,6 +44,36 @@ describe('change-by-example', () => { la(R.equals(output, expected), diff(expected, output).text) }) + it('should not crash on non-strings', () => { + const source = { + name: { + first: 'joe', + last: 'smith' + } + } + const destination = { + name: { + first: 'joe' + } + } + finds(source, destination) + }) + + it('works with nested objects', () => { + const source = { + age: 42, + name: { + first: 'joe', + last: 'smith' + } + } + const destination = { + first: 'Joe', + last: 'Smith' + } + finds(source, destination) + }) + describe('delete property', () => { const source = { foo: 'f', diff --git a/src/index.js b/src/index.js index c639ab9..576aa5c 100644 --- a/src/index.js +++ b/src/index.js @@ -32,12 +32,14 @@ function o2o (source, destination) { R.keys(source).some(key => { const sourceValue = source[key] const foundTransform = transforms.some(t => { - const out = t.f(sourceValue) - if (R.equals(value, out)) { - sourceKey = key - transform = t - return true - } + try { + const out = t.f(sourceValue) + if (R.equals(value, out)) { + sourceKey = key + transform = t + return true + } + } catch (e) {} }) return foundTransform })