Last active
October 23, 2017 15:01
-
-
Save apaleslimghost/11c1c009cc84408dfe77cc75e93fa5c0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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