diff --git a/changelog.md b/changelog.md index f577c48..1591506 100644 --- a/changelog.md +++ b/changelog.md @@ -1,3 +1,13 @@ + +## 0.1.2 (2017-04-04) + +* 0.1.2 ([231629a](https://github.com/GitScrum/posthtml-class-to-css-module/commit/231629a)) +* chore(changelog): Update changelog ([2ee2855](https://github.com/GitScrum/posthtml-class-to-css-module/commit/2ee2855)) +* chore(package): update clean and pattern lintjs ([18e6b0a](https://github.com/GitScrum/posthtml-class-to-css-module/commit/18e6b0a)) +* perf(index): remove double recursion ([680dddc](https://github.com/GitScrum/posthtml-class-to-css-module/commit/680dddc)) + + + ## 0.1.1 (2017-04-04) diff --git a/package.json b/package.json index 6df49b7..107ac56 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "posthtml-class-to-css-module", - "version": "0.1.1", + "version": "0.1.2", "description": "A posthtml plugin for removing tags", "license": "MIT", "repository": "GitScrum/posthtml-class-to-css-module", @@ -16,7 +16,7 @@ "node": ">=4" }, "scripts": { - "lintjs": "eslint ./src/*.js ./test/*.js", + "lintjs": "eslint ./{src,test}/*.js", "lintmd": "eslint --ext md --rule indent: [error, 4] .", "pretest": "clinton && npm run lintjs && npm run lintmd", "commitmsg": "conventional-changelog-lint -e", @@ -25,8 +25,7 @@ "minor": "np minor --any-branch", "major": "np major --any-branch", "test": "nyc ava", - "clean": "rm -rf lib", - "build": "npm run clean && babel src -d lib", + "build": "rimraf lib && babel src -d lib", "prepublish": "npm run build", "update": "updtr && ava-codemods --force", "testen": "testen -n -- ava" @@ -74,6 +73,7 @@ "np": "^2.6.0", "nyc": "^10.1.2", "posthtml": "^0.9.0", + "rimraf": "^2.6.1", "testen": "^2.2.0", "updtr": "^1.0.0" }, diff --git a/src/index.js b/src/index.js index afdd762..8ea78d1 100644 --- a/src/index.js +++ b/src/index.js @@ -1,27 +1,20 @@ import Reflect from 'core-js/fn/reflect'; -const clone = tree => tree.match( +const clone = (tree, options) => tree.match( {attrs: {class: /.+/}}, node => { node.attrs = Object.assign(node.attrs, {'css-module': node.attrs.class}); - return node; - } -); - -const removeClass = tree => tree.match( - {attrs: {class: /.+/}}, - node => { - node.attrs = Object.keys(node.attrs) - .reduce((attrs, key) => Object.assign(attrs, key === 'class' ? {} : {[key]: node.attrs[key]}), {}); + if (Reflect.has(options, 'removeClass') && options.removeClass) { + delete node.attrs.class; + } return node; } ); const cloneClassTo = (tree, options) => Promise.resolve(tree) - .then(tree => clone(tree)) - .then(tree => (Reflect.has(options, 'removeClass') && options.removeClass) ? removeClass(tree) : tree) + .then(tree => clone(tree, options)) .then(tree => tree); export default (options = {}) => {