Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
<a name="0.1.2"></a>
## 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))



<a name="0.1.1"></a>
## 0.1.1 (2017-04-04)

Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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",
Expand All @@ -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"
Expand Down Expand Up @@ -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"
},
Expand Down
17 changes: 5 additions & 12 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -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 = {}) => {
Expand Down