diff --git a/lib/freeze.js b/lib/freeze.js index e4d8eb4..cd1ae6a 100644 --- a/lib/freeze.js +++ b/lib/freeze.js @@ -1,9 +1,10 @@ function isFreezable(obj) { - if (Object.isFrozen(obj)) { - return false; - } + return Array.isArray(obj) || + typeof obj === 'object'; +} - return Array.isArray(obj) || typeof obj === 'object'; +function needsFreezing(obj) { + return isFreezable(obj) && !Object.isFrozen(obj); } function recur(obj) { @@ -11,7 +12,7 @@ function recur(obj) { Object.keys(obj).forEach((key) => { const value = obj[key]; - if (isFreezable(value)) { + if (needsFreezing(value)) { recur(value); } }); @@ -24,7 +25,7 @@ export default function freeze(obj) { return obj; } - if (isFreezable(obj)) { + if (needsFreezing(obj)) { recur(obj); }