Skip to content

Commit 72b1188

Browse files
committed
initial commit
0 parents  commit 72b1188

File tree

10 files changed

+170
-0
lines changed

10 files changed

+170
-0
lines changed

.editorconfig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
root = true
2+
3+
[*]
4+
indent_style = space
5+
indent_size = 4
6+
end_of_line = lf
7+
charset = utf-8
8+
trim_trailing_whitespace = true
9+
insert_final_newline = true
10+
11+
[*.{json,yml}]
12+
indent_size = 2

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules/
2+
npm-debug.log

.npmignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.gitignore
2+
3+
node_modules/
4+
npm-debug.log
5+
6+
test.js
7+
.travis.yml

.travis.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
language: node_js
2+
node_js:
3+
- "5"
4+
- "4"
5+
- "0.12"

CHANGELOG.md

Whitespace-only changes.

LICENSE

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
The MIT License (MIT)
2+
3+
Copyright 2016 Matthias Müller <MattDiMu@users.noreply.github.com>
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of
6+
this software and associated documentation files (the "Software"), to deal in
7+
the Software without restriction, including without limitation the rights to
8+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9+
the Software, and to permit persons to whom the Software is furnished to do so,
10+
subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# PostCSS Replace Overflow Wrap [![Build Status][ci-img]][ci]
2+
3+
[PostCSS] plugin to replace overflow-wrap with word-wrap. May optionally retain both declarations.
4+
5+
[PostCSS]: https://github.com/postcss/postcss
6+
[ci-img]: https://travis-ci.org/MattDiMu/postcss-replace-overflow-wrap.svg
7+
[ci]: https://travis-ci.org/MattDiMu/postcss-replace-overflow-wrap
8+
9+
10+
```css
11+
/* before */
12+
.foo {
13+
overflow-wrap: break-word;
14+
}
15+
16+
/* after */
17+
.foo {
18+
word-wrap: break-word;
19+
}
20+
```
21+
22+
```css
23+
/* before, when the option { method: 'copy' } is passed */
24+
.foo {
25+
overflow-wrap: break-word;
26+
}
27+
28+
/* after */
29+
.foo {
30+
word-wrap: break-word;
31+
overflow-wrap: break-word;
32+
}
33+
```
34+
35+
36+
## Usage
37+
38+
```js
39+
postcss([ require('postcss-replace-overflow-wrap') ])
40+
```
41+
42+
See [PostCSS] docs for examples for your environment.

index.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
var postcss = require('postcss');
2+
3+
module.exports = postcss.plugin('postcss-replace-overflow-wrap', function (opts) {
4+
opts = opts || {};
5+
var method = opts.method || 'replace';
6+
7+
return function (css, result) { // eslint-disable-line no-unused-vars
8+
css.walkRules(function (rule) {
9+
rule.walkDecls(function (decl, i) { // eslint-disable-line no-unused-vars
10+
if (decl.prop === 'overflow-wrap') {
11+
decl.cloneBefore({ prop: 'word-wrap' });
12+
if (method === 'replace') {
13+
decl.remove();
14+
}
15+
}
16+
});
17+
});
18+
};
19+
});

package.json

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"name": "postcss-replace-overflow-wrap",
3+
"version": "0.0.0",
4+
"description": "PostCSS plugin to replace overflow-wrap with word-wrap or optionally retain both declarations.",
5+
"keywords": [
6+
"postcss",
7+
"css",
8+
"postcss-plugin",
9+
"overflow-wrap",
10+
"word-wrap"
11+
],
12+
"author": "Matthias Müller <MattDiMu@users.noreply.github.com>",
13+
"license": "MIT",
14+
"repository": "MattDiMu/postcss-replace-overflow-wrap",
15+
"bugs": {
16+
"url": "https://github.com/MattDiMu/postcss-replace-overflow-wrap/issues"
17+
},
18+
"homepage": "https://github.com/MattDiMu/postcss-replace-overflow-wrap",
19+
"dependencies": {
20+
"postcss": "^5.0.16"
21+
},
22+
"devDependencies": {
23+
"ava": "^0.14.0",
24+
"eslint": "^2.1.0",
25+
"eslint-config-postcss": "^2.0.0"
26+
},
27+
"scripts": {
28+
"test": "ava && eslint *.js"
29+
},
30+
"eslintConfig": {
31+
"extends": "eslint-config-postcss/es5",
32+
"rules": {
33+
"max-len": 0
34+
}
35+
}
36+
}

test.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import postcss from 'postcss';
2+
import test from 'ava';
3+
4+
import plugin from './';
5+
6+
function run(t, input, output, opts = { }) {
7+
return postcss([ plugin(opts) ]).process(input)
8+
.then( result => {
9+
t.deepEqual(result.css, output);
10+
t.deepEqual(result.warnings().length, 0);
11+
});
12+
}
13+
14+
15+
test('replace overflow-wrap with word-wrap, no options', t => {
16+
return run(t,
17+
'.someClass{ overflow-wrap: break-word; }',
18+
'.someClass{ word-wrap: break-word; }'
19+
, {});
20+
});
21+
22+
test('add word-wrap right before overflow-wrap due to passed arg', t => {
23+
return run(t,
24+
'.anotherClass{font-size:1rem;overflow-wrap:break-word;}',
25+
'.anotherClass{font-size:1rem;word-wrap:break-word;overflow-wrap:break-word;}'
26+
, { method: 'copy' });
27+
});

0 commit comments

Comments
 (0)