(val)
| 172 | } |
| 173 | |
| 174 | export 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 | |
| 184 | export function nest(obj, key) { |
| 185 | return obj[key] || (obj[key] = {}); |
no outgoing calls
no test coverage detected