Files
homepage-template/node_modules/@11ty/eleventy/src/Util/Objects/DeepFreeze.js
2024-11-03 17:41:45 +01:00

21 lines
470 B
JavaScript

import { isPlainObject } from "@11ty/eleventy-utils";
// via https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze
function DeepFreeze(obj, topLevelExceptions) {
for (let name of Reflect.ownKeys(obj)) {
if ((topLevelExceptions || []).find((key) => key === name)) {
continue;
}
const value = obj[name];
if (isPlainObject(value)) {
DeepFreeze(value);
}
}
return Object.freeze(obj);
}
export { DeepFreeze };