bfj
Version:
Big-friendly JSON. Asynchronous streaming functions for large JSON data sets.
28 lines (25 loc) • 648 B
JavaScript
module.exports = setProperty
/**
* Set an own data property on an object.
*
* A `__proto__` key must be defined rather than assigned, otherwise it mutates
* the object's prototype instead of creating the property that the JSON input
* represents.
*
* @param object: The object to set the property on.
* @param key: The property key.
* @param value: The property value.
**/
function setProperty (object, key, value) {
if (key === '__proto__') {
Object.defineProperty(object, key, {
value,
writable: true,
enumerable: true,
configurable: true
})
} else {
object[key] = value
}
}