Skip to content
Snippets Groups Projects
Select Git revision
  • master default protected
  • 1.31
  • 4.15.1
  • 4.15.0
  • 4.14.0
  • 4.13.1
  • 4.13.0
  • 4.12.0
  • 4.11.1
  • 4.11.0
  • 4.10.4
  • 4.10.3
  • 4.10.2
  • 4.10.1
  • 4.10.0
  • 4.9.0
  • 4.8.0
  • 4.7.0
  • 4.6.1
  • 4.6.0
  • 4.5.1
  • 4.5.0
22 results

freeze.mjs

Blame
  • freeze.mjs 950 B
    /**
     * Copyright schukai GmbH and contributors 2023. All Rights Reserved.
     * Node module: @schukai/monster
     * This file is licensed under the AGPLv3 License.
     * License text available at https://www.gnu.org/licenses/agpl-3.0.en.html
     */
    
    import { validateObject } from "../types/validate.mjs";
    
    export { deepFreeze };
    
    /**
     * Deep freeze a object
     *
     * @param {object} object object to be freeze
     * @license AGPLv3
     * @since 1.0.0
     * @returns {object}
     * @memberOf Monster.Util
     * @copyright schukai GmbH
     * @throws {TypeError} value is not a object
     */
    function deepFreeze(object) {
    	validateObject(object);
    
    	// Retrieve the defined property names of the object
    	let propNames = Object.getOwnPropertyNames(object);
    
    	// Freeze properties before freezing yourself
    	for (const name of propNames) {
    		const value = object[name];
    
    		object[name] =
    			value && typeof value === "object" ? deepFreeze(value) : value;
    	}
    
    	return Object.freeze(object);
    }