3 const { common
} = require('@squeep/api-dingus');
7 * Return an array containing x if x is not already an array.
10 const ensureArray
= (x
) => {
11 if (x
=== undefined) {
14 if (!Array
.isArray(x
)) {
22 * Recursively freeze an object.
26 const freezeDeep
= (o
) => {
28 Object
.getOwnPropertyNames(o
).forEach((prop
) => {
29 if (Object
.hasOwnProperty
.call(o
, prop
)
30 && ['object', 'function'].includes(typeof o
[prop
])
31 && !Object
.isFrozen(o
[prop
])) {
32 return freezeDeep(o
[prop
]);
40 * Limit length of string to keep logs sane
45 const logTruncate
= (str
, len
) => {
46 if (typeof str
!== 'string' || str
.toString().length
<= len
) {
49 return str
.toString().slice(0, len
) + `... (${str.toString().length} bytes)`;