mirror of
https://github.com/idanoo/GoScrobble
synced 2025-07-27 09:59:14 +00:00
24 lines
852 B
JavaScript
24 lines
852 B
JavaScript
import assign from 'object.assign';
|
|
|
|
/**
|
|
* Extractor function for an ObjectExpression type value node.
|
|
* An object expression is using {}.
|
|
*
|
|
* @returns - a representation of the object
|
|
*/
|
|
export default function extractValueFromObjectExpression(value) {
|
|
// eslint-disable-next-line global-require
|
|
const getValue = require('./index.js').default;
|
|
return value.properties.reduce((obj, property) => {
|
|
const object = { ...obj };
|
|
// Support types: SpreadProperty and ExperimentalSpreadProperty
|
|
if (/^(?:Experimental)?Spread(?:Property|Element)$/.test(property.type)) {
|
|
if (property.argument.type === 'ObjectExpression') {
|
|
return assign(object, extractValueFromObjectExpression(property.argument));
|
|
}
|
|
} else {
|
|
object[getValue(property.key)] = getValue(property.value);
|
|
}
|
|
return object;
|
|
}, {});
|
|
}
|