deep-freeze.js 276 B

123456789101112
  1. 'use strict';
  2. const is = require('@sindresorhus/is');
  3. module.exports = function deepFreeze(object) {
  4. for (const [key, value] of Object.entries(object)) {
  5. if (is.plainObject(value) || is.array(value)) {
  6. deepFreeze(object[key]);
  7. }
  8. }
  9. return Object.freeze(object);
  10. };