brandeur-plugin-sort-property
Version:
Brandeur plugin that sorts properties according a priority map
22 lines • 662 B
JavaScript
import isPlainObject from 'isobject';
export default function sortPropertyPlugin() {
let propertyPriority = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
function getPriority(property) {
return propertyPriority[property] || 0;
}
return function sortProperty(style) {
return Object.keys(style).sort((a, b) => getPriority(a) - getPriority(b)).reduce((out, property) => {
const value = style[property];
if (isPlainObject(value)) {
return {
...out,
[property]: sortProperty(value)
};
}
return {
...out,
[property]: value
};
}, {});
};
}