UNPKG

parsel-js

Version:

A tiny, permissive CSS selector parser

18 lines (14 loc) 360 B
// Inserts a property before another in an object literal without breaking references to it export default function insert(obj, {before, property, value}) { let found, temp = {}; for (let p in obj) { if (p === before) { found = true; } if (found) { temp[p] = obj[p]; delete obj[p]; } } Object.assign(obj, {property: value, ...temp}); }