Skip to content

Instantly share code, notes, and snippets.

@apaleslimghost
Last active October 23, 2017 15:01
Show Gist options
  • Save apaleslimghost/11c1c009cc84408dfe77cc75e93fa5c0 to your computer and use it in GitHub Desktop.
Save apaleslimghost/11c1c009cc84408dfe77cc75e93fa5c0 to your computer and use it in GitHub Desktop.
const {calculateSpecificity} = require('clear-cut');
const orderBy = require('lodash.orderby');
module.exports = replacers => {
const selectors = orderBy(Object.keys(replacers), calculateSpecificity, 'desc');
return ($, ...args) => {
selectors.forEach(selector => {
$(selector).each((i, el) => {
const $el = $(el);
const newEl = replacers[selector]($el, i, $, ...args);
if(newEl) {
$el.replaceWith(newEl);
}
});
});
return $;
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment