postcss-convert-values 2.4.0 → 2.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,23 @@
1
+ # 2.6.1
2
+
3
+ * Resolves an issue where IE hacks were being removed from `0` values
4
+ (thanks to @Justineo).
5
+
6
+ # 2.6.0
7
+
8
+ * Added clamping of the values for the `shape-image-threshold` property, using
9
+ the same logic as introduced in version `2.5.0`.
10
+
11
+ # 2.5.0
12
+
13
+ * Added clamping of the values for the `opacity` property to the `0-1` range.
14
+ For example, this will convert `opacity: 1.1` to `opacity: 1`.
15
+
16
+ # 2.4.1
17
+
18
+ * Resolves an issue where the units would be stripped from zero values in
19
+ custom properties (thanks to @jgerigmeyer).
20
+
1
21
  # 2.4.0
2
22
 
3
23
  * Added a `precision` option to enable rounding of decimal places for
package/README.md CHANGED
@@ -77,15 +77,26 @@ leave these values as is.
77
77
 
78
78
  It is recommended for most use cases to set this option to `2`.
79
79
 
80
- ## Contributing
81
80
 
82
- Pull requests are welcome. If you add functionality, then please add unit tests
83
- to cover it.
81
+ ## Contributors
82
+
83
+ Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds/all-contributors#emoji-key)):
84
+
85
+ <!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
86
+ | [<img src="https://avatars.githubusercontent.com/u/1282980?v=3" width="100px;"/><br /><sub>Ben Briggs</sub>](http://beneb.info)<br />[💻](https://github.com/ben-eb/postcss-convert-values/commits?author=ben-eb) [📖](https://github.com/ben-eb/postcss-convert-values/commits?author=ben-eb) 👀 [⚠️](https://github.com/ben-eb/postcss-convert-values/commits?author=ben-eb) | [<img src="https://avatars.githubusercontent.com/u/5635476?v=3" width="100px;"/><br /><sub>Bogdan Chadkin</sub>](https://github.com/TrySound)<br />[💻](https://github.com/ben-eb/postcss-convert-values/commits?author=TrySound) [📖](https://github.com/ben-eb/postcss-convert-values/commits?author=TrySound) 👀 [⚠️](https://github.com/ben-eb/postcss-convert-values/commits?author=TrySound) | [<img src="https://avatars.githubusercontent.com/u/177485?v=3" width="100px;"/><br /><sub>Roman Komarov</sub>](http://kizu.ru/en/)<br />[🐛](https://github.com/ben-eb/postcss-convert-values/issues?q=author%3Akizu) | [<img src="https://avatars.githubusercontent.com/u/5103477?v=3" width="100px;"/><br /><sub>Dmitry Kiselyov</sub>](http://codepen.io/dmitrykiselyov)<br />[🐛](https://github.com/ben-eb/postcss-convert-values/issues?q=author%3Admitrykiselyov) | [<img src="https://avatars.githubusercontent.com/u/5038030?v=3" width="100px;"/><br /><sub>Charlike Mike Reagent</sub>](http://www.tunnckocore.tk)<br />[💻](https://github.com/ben-eb/postcss-convert-values/commits?author=tunnckoCore) [⚠️](https://github.com/ben-eb/postcss-convert-values/commits?author=tunnckoCore) | [<img src="https://avatars.githubusercontent.com/u/815848?v=3" width="100px;"/><br /><sub>Vyacheslav Shebanov</sub>](https://github.com/Termina1)<br />[📖](https://github.com/ben-eb/postcss-convert-values/commits?author=Termina1) | [<img src="https://avatars.githubusercontent.com/u/192323?v=3" width="100px;"/><br /><sub>Marek ‘saji’ Augustynowicz</sub>](http://twitter.com/saji_)<br />[💻](https://github.com/ben-eb/postcss-convert-values/commits?author=marek-saji) [⚠️](https://github.com/ben-eb/postcss-convert-values/commits?author=marek-saji) |
87
+ | :---: | :---: | :---: | :---: | :---: | :---: | :---: |
88
+ | [<img src="https://avatars.githubusercontent.com/u/552316?v=3" width="100px;"/><br /><sub>Jonny Gerig Meyer</sub>](www.oddbird.net)<br />[💻](https://github.com/ben-eb/postcss-convert-values/commits?author=jgerigmeyer) [⚠️](https://github.com/ben-eb/postcss-convert-values/commits?author=jgerigmeyer) | [<img src="https://avatars.githubusercontent.com/u/1726061?v=3" width="100px;"/><br /><sub>GU Yiling</sub>](http://lync.in/)<br />[💻](https://github.com/ben-eb/postcss-convert-values/commits?author=Justineo) [⚠️](https://github.com/ben-eb/postcss-convert-values/commits?author=Justineo) |
89
+ <!-- ALL-CONTRIBUTORS-LIST:END -->
90
+
91
+ This project follows the [all-contributors] specification. Contributions of
92
+ any kind welcome!
84
93
 
85
94
  ## License
86
95
 
87
96
  MIT © [Ben Briggs](http://beneb.info)
88
97
 
98
+
99
+ [all-contributors]: https://github.com/kentcdodds/all-contributors
89
100
  [ci]: https://travis-ci.org/ben-eb/postcss-convert-values
90
101
  [colormin]: https://github.com/ben-eb/postcss-colormin
91
102
  [deps]: https://gemnasium.com/ben-eb/postcss-convert-values
package/dist/index.js CHANGED
@@ -6,23 +6,25 @@ var _postcss = require('postcss');
6
6
 
7
7
  var _postcss2 = _interopRequireDefault(_postcss);
8
8
 
9
- var _convert = require('./lib/convert');
10
-
11
- var _convert2 = _interopRequireDefault(_convert);
12
-
13
9
  var _postcssValueParser = require('postcss-value-parser');
14
10
 
15
11
  var _postcssValueParser2 = _interopRequireDefault(_postcssValueParser);
16
12
 
13
+ var _convert = require('./lib/convert');
14
+
15
+ var _convert2 = _interopRequireDefault(_convert);
16
+
17
17
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
18
18
 
19
- function parseWord(node, opts, stripZeroUnit) {
19
+ var LENGTH_UNITS = ['em', 'ex', 'ch', 'rem', 'vw', 'vh', 'vmin', 'vmax', 'cm', 'mm', 'q', 'in', 'pt', 'pc', 'px'];
20
+
21
+ function parseWord(node, opts, keepZeroUnit) {
20
22
  var pair = (0, _postcssValueParser.unit)(node.value);
21
23
  if (pair) {
22
24
  var num = Number(pair.number);
23
25
  var u = pair.unit.toLowerCase();
24
26
  if (num === 0) {
25
- node.value = stripZeroUnit || u === 'ms' || u === 's' || u === 'deg' || u === 'rad' || u === 'grad' || u === 'turn' ? 0 + u : 0;
27
+ node.value = keepZeroUnit || !~LENGTH_UNITS.indexOf(u) && u !== '%' ? 0 + u : 0;
26
28
  } else {
27
29
  node.value = (0, _convert2.default)(num, u, opts);
28
30
 
@@ -34,23 +36,41 @@ function parseWord(node, opts, stripZeroUnit) {
34
36
  }
35
37
  }
36
38
 
39
+ function clampOpacity(node) {
40
+ var pair = (0, _postcssValueParser.unit)(node.value);
41
+ if (!pair) {
42
+ return;
43
+ }
44
+ var num = Number(pair.number);
45
+ if (num > 1) {
46
+ node.value = 1 + pair.unit;
47
+ } else if (num < 0) {
48
+ node.value = 0 + pair.unit;
49
+ }
50
+ }
51
+
37
52
  function shouldStripPercent(_ref) {
38
- var value = _ref.value;
39
- var prop = _ref.prop;
40
- var parent = _ref.parent;
53
+ var value = _ref.value,
54
+ prop = _ref.prop,
55
+ parent = _ref.parent;
41
56
 
42
57
  return ~value.indexOf('%') && (prop === 'max-height' || prop === 'height') || parent.parent && parent.parent.name === 'keyframes' && prop === 'stroke-dasharray' || prop === 'stroke-dashoffset' || prop === 'stroke-width';
43
58
  }
44
59
 
45
60
  function transform(opts) {
46
61
  return function (decl) {
47
- if (~decl.prop.indexOf('flex')) {
62
+ var prop = decl.prop;
63
+
64
+ if (~prop.indexOf('flex') || prop.indexOf('--') === 0) {
48
65
  return;
49
66
  }
50
67
 
51
68
  decl.value = (0, _postcssValueParser2.default)(decl.value).walk(function (node) {
52
69
  if (node.type === 'word') {
53
70
  parseWord(node, opts, shouldStripPercent(decl));
71
+ if (prop === 'opacity' || prop === 'shape-image-threshold') {
72
+ clampOpacity(node);
73
+ }
54
74
  } else if (node.type === 'function') {
55
75
  if (node.value === 'calc' || node.value === 'hsl' || node.value === 'hsla') {
56
76
  (0, _postcssValueParser.walk)(node.nodes, function (n) {
@@ -68,15 +88,17 @@ function transform(opts) {
68
88
  };
69
89
  }
70
90
 
71
- exports.default = _postcss2.default.plugin('postcss-convert-values', function () {
72
- var opts = arguments.length <= 0 || arguments[0] === undefined ? { precision: false } : arguments[0];
91
+ var plugin = 'postcss-convert-values';
92
+
93
+ exports.default = _postcss2.default.plugin(plugin, function () {
94
+ var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : { precision: false };
73
95
 
74
96
  if (opts.length === undefined && opts.convertLength !== undefined) {
75
- console.warn('postcss-convert-values: `convertLength` option is deprecated. Use `length`');
97
+ console.warn(plugin + ': `convertLength` option is deprecated. Use `length`');
76
98
  opts.length = opts.convertLength;
77
99
  }
78
100
  if (opts.length === undefined && opts.convertTime !== undefined) {
79
- console.warn('postcss-convert-values: `convertTime` option is deprecated. Use `time`');
101
+ console.warn(plugin + ': `convertTime` option is deprecated. Use `time`');
80
102
  opts.time = opts.convertTime;
81
103
  }
82
104
  return function (css) {
@@ -3,9 +3,9 @@
3
3
  exports.__esModule = true;
4
4
 
5
5
  exports.default = function (number, unit, _ref) {
6
- var time = _ref.time;
7
- var length = _ref.length;
8
- var angle = _ref.angle;
6
+ var time = _ref.time,
7
+ length = _ref.length,
8
+ angle = _ref.angle;
9
9
 
10
10
  var value = dropLeadingZero(number) + (unit ? unit : '');
11
11
  var converted = void 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "postcss-convert-values",
3
- "version": "2.4.0",
3
+ "version": "2.6.1",
4
4
  "description": "Convert values with PostCSS (e.g. ms -> s)",
5
5
  "main": "dist/index.js",
6
6
  "files": [
@@ -8,9 +8,12 @@
8
8
  "dist"
9
9
  ],
10
10
  "scripts": {
11
+ "contributorAdd": "all-contributors add",
12
+ "contributorGenerate": "all-contributors generate",
11
13
  "pretest": "eslint src",
12
14
  "prepublish": "del-cli dist && BABEL_ENV=publish babel src --out-dir dist --ignore /__tests__/",
13
- "test": "ava"
15
+ "test": "ava",
16
+ "test-012": "ava"
14
17
  },
15
18
  "keywords": [
16
19
  "css",
@@ -20,7 +23,8 @@
20
23
  ],
21
24
  "license": "MIT",
22
25
  "devDependencies": {
23
- "ava": "^0.15.0",
26
+ "all-contributors-cli": "^3.0.5",
27
+ "ava": "^0.17.0",
24
28
  "babel-cli": "^6.3.17",
25
29
  "babel-core": "^6.3.26",
26
30
  "babel-plugin-add-module-exports": "^0.2.1",
@@ -29,8 +33,10 @@
29
33
  "babel-preset-stage-0": "^6.3.13",
30
34
  "babel-register": "^6.9.0",
31
35
  "del-cli": "^0.2.0",
32
- "eslint": "^2.0.0",
33
- "eslint-config-cssnano": "^2.0.0"
36
+ "eslint": "^3.0.0",
37
+ "eslint-config-cssnano": "^3.0.0",
38
+ "eslint-plugin-babel": "^3.3.0",
39
+ "eslint-plugin-import": "^2.0.1"
34
40
  },
35
41
  "homepage": "https://github.com/ben-eb/postcss-convert-values",
36
42
  "author": {