diff --git a/index.js b/index.js index e1f316f..3fe9b42 100644 --- a/index.js +++ b/index.js @@ -39,7 +39,7 @@ module.exports = { const pathArray = getPathSegments(path); if (pathArray.length === 0) { - return; + return value; } for (let i = 0; i < pathArray.length; i++) { diff --git a/test.js b/test.js index 0354205..a43c89e 100644 --- a/test.js +++ b/test.js @@ -213,3 +213,7 @@ test('prevent setting/getting `__proto__`', t => { t.is(dotProp.get({}, '__proto__'), undefined); }); + +test('return default value if path is invalid', t => { + t.is(dotProp.get({}, 'constructor', '🦄'), '🦄'); +});