This repository has been archived on 2024-07-27. You can view files and clone it, but cannot push or open issues or pull requests.
keksAccountGUI/node_modulesOLD/@vue/cli-shared-utils/lib/object.js

50 lines
1 KiB
JavaScript
Raw Normal View History

2019-08-11 18:48:02 +00:00
exports.set = function (target, path, value) {
const fields = path.split('.')
let obj = target
const l = fields.length
for (let i = 0; i < l - 1; i++) {
const key = fields[i]
if (!obj[key]) {
obj[key] = {}
}
obj = obj[key]
}
obj[fields[l - 1]] = value
}
exports.get = function (target, path) {
const fields = path.split('.')
let obj = target
const l = fields.length
for (let i = 0; i < l - 1; i++) {
const key = fields[i]
if (!obj[key]) {
return undefined
}
obj = obj[key]
}
return obj[fields[l - 1]]
}
exports.unset = function (target, path) {
const fields = path.split('.')
let obj = target
const l = fields.length
const objs = []
for (let i = 0; i < l - 1; i++) {
const key = fields[i]
if (!obj[key]) {
return
}
objs.splice(0, 0, { obj, key, value: obj[key] })
obj = obj[key]
}
delete obj[fields[l - 1]]
// Clear empty objects
for (const { obj, key, value } of objs) {
if (!Object.keys(value).length) {
delete obj[key]
}
}
}