@adguard/agtree
Version:
Tool set for working with adblock filter lists
33 lines (31 loc) • 1.01 kB
JavaScript
/*
* AGTree v4.1.1 (build date: Thu, 23 Apr 2026 09:15:37 GMT)
* (c) 2026 Adguard Software Ltd.
* Released under the MIT license
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
*/
/**
* Simple deep freeze implementation.
* It freezes the object and all its properties recursively.
*
* @template T Type of the object to freeze.
*
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze#deep_freezing}
*
* @param object Object to freeze.
*
* @returns Frozen object.
*/
const deepFreeze = (object) => {
// Retrieve the property names defined on object
const propNames = Reflect.ownKeys(object);
// Freeze properties before freezing self
for (const name of propNames) {
const value = object[name];
if ((value && typeof value === 'object') || typeof value === 'function') {
deepFreeze(value);
}
}
return Object.freeze(object);
};
export { deepFreeze };