(object, path, defaultValue)
| 156 | |
| 157 | // changed from https://github.com/sindresorhus/dot-prop/blob/master/index.js |
| 158 | export function getValue(object, path, defaultValue) { |
| 159 | if (object === null || typeof object !== 'object' || typeof path !== 'string') { |
| 160 | return defaultValue; |
| 161 | } |
| 162 | |
| 163 | const pathArray = getPathSegments(path); |
| 164 | |
| 165 | for (let i = 0; i < pathArray.length; i++) { |
| 166 | if (!Object.prototype.propertyIsEnumerable.call(object, pathArray[i])) { |
| 167 | return defaultValue; |
| 168 | } |
| 169 | |
| 170 | object = object[pathArray[i]]; |
| 171 | |
| 172 | if (object === undefined || object === null) { |
| 173 | if (i !== pathArray.length - 1) { |
| 174 | return defaultValue; |
| 175 | } |
| 176 | |
| 177 | break; |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | return object; |
| 182 | } |
| 183 | |
| 184 | // copied from https://www.30secondsofcode.org/js/s/debounce |
| 185 | export const debounce = (fn, ms = 0) => { |
no test coverage detected