1.4.0
[squeep-authentication-module] / lib / common.js
1 'use strict';
2
3 const { common } = require('@squeep/api-dingus');
4
5
6 /**
7 * Recursively freeze an object.
8 * @param {Object} o
9 * @returns {Object}
10 */
11 const freezeDeep = (o) => {
12 Object.freeze(o);
13 Object.getOwnPropertyNames(o).forEach((prop) => {
14 if (Object.hasOwnProperty.call(o, prop)
15 && ['object', 'function'].includes(typeof o[prop]) // eslint-disable-line security/detect-object-injection
16 && !Object.isFrozen(o[prop])) { // eslint-disable-line security/detect-object-injection
17 return freezeDeep(o[prop]); // eslint-disable-line security/detect-object-injection
18 }
19 });
20 return o;
21 }
22
23 module.exports = Object.assign(Object.create(common), {
24 freezeDeep,
25 });