MCPcopy Create free account
hub / github.com/violentmonkey/violentmonkey / deepSize

Function deepSize

src/common/object.js:174–182  ·  view source on GitHub ↗
(val)

Source from the content-addressed store, hash-verified

172}
173
174export function deepSize(val) {
175 if (val === undefined) return 0;
176 if (val === true || val == null) return 4;
177 if (val === false) return 5;
178 if (typeof val === 'string') return val.length + 2; // not counting escapes for \n\r\t and so on
179 if (typeof val !== 'object') return `${val}`.length; // number and whatever
180 if (Array.isArray(val)) return val.reduce((sum, v) => sum + 1 + deepSize(v), 2);
181 return Object.keys(val).reduce((sum, k) => sum + k.length + 4 + deepSize(val[k]), 2);
182}
183
184export function nest(obj, key) {
185 return obj[key] || (obj[key] = {});

Callers 4

getSizesFunction · 0.90
touchFunction · 0.90
flushLaterFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected