Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

postcss-convert-values

Package Overview
Dependencies
Maintainers
1
Versions
76
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

postcss-convert-values - npm Package Compare versions

Comparing version 1.1.1 to 1.2.0

.jscsrc

7

CHANGELOG.md

@@ -0,5 +1,9 @@

# 1.2.0
* Adds support for slash/comma separated values (thanks to @TrySound).
# 1.1.1
* Fixes an issue where trailing zeroes were not being removed in
values that were not `0`.
values that were not `0`. (thanks to @TrySound)

@@ -9,2 +13,3 @@ # 1.1.0

* Adds support for removing leading zeroes from `rem` values.
(thanks to @tunnckoCore)

@@ -11,0 +16,0 @@ # 1.0.3

73

index.js
'use strict';
var postcss = require('postcss');
var list = postcss.list;
var converter = require('./lib/converter');
var reduce = require('reduce-function-call');
var convert = require('./lib/convert');
var eachValue = require('./lib/eachValue');
var parseUnit = require('./lib/parseUnit');
var duration = /^((?:[-+]?[\d]+?)(?:\.?(?:[\d]+?))?)(s|ms)/;
var length = /^((?:[-+]?[\d]+?)(?:\.?(?:[\d]+?))?)?(%|em|rem|ex|in|cm|mm|pt|pc|px)?$/;
var tidyValue = /^([\d]*)?\.([^1-9]*)?$/;
module.exports = postcss.plugin('postcss-convert-values', function () {
return function (css) {
css.eachDecl(function (decl) {
decl.value = eachValue(decl.value, function (value) {
var number, unit;
function durationOptimiser (value) {
if (duration.test(value)) {
return value.replace(duration, function (_, num, unit) {
return converter(num, unit);
});
}
return value;
}
if (!~decl.prop.indexOf('flex') && !isNaN(number = parseFloat(value))) {
unit = parseUnit(value);
function lengthOptimiser (value, prop) {
if (length.test(value)) {
var match = value.match(length),
num = match[1],
integer = parseInt(num),
unit = match[2];
if (parseFloat(num) === integer) {
num = integer;
}
if (num !== 0) {
num = converter(num, unit);
} else if (~prop.indexOf('flex')) {
return value;
}
return num;
}
return value;
}
if (number === 0) {
value = (unit === 'ms' || unit === 's') ? 0 + unit : 0;
} else {
value = convert(number, unit);
}
function eachValue (decl) {
return function (value) {
var match = tidyValue.exec(value);
if (match) {
if (!/\d/.test(match[2])) {
value = value.replace(tidyValue, '$1$2');
} else if (!match[1]) {
value = value.replace(tidyValue, '0');
}
}
value = durationOptimiser(value);
value = lengthOptimiser(value, decl.prop);
return value;
};
}
module.exports = postcss.plugin('postcss-convert-values', function () {
return function (css) {
css.eachDecl(function (decl) {
var each = eachValue(decl);
decl.value = list.space(decl.value).map(each).join(' ');
decl.value = reduce(decl.value, 'calc', function (body, fn) {
var transform = list.space(body).map(each).join(' ');
return fn + '(' + transform + ')';
return value;
}
});

@@ -65,0 +26,0 @@ });

{
"name": "postcss-convert-values",
"version": "1.1.1",
"version": "1.2.0",
"description": "Convert values with PostCSS (e.g. ms -> s)",
"main": "index.js",
"scripts": {
"test": "tape test.js | tap-spec"
"test": "tape test.js | tap-spec",
"jscs": "jscs index.js test.js lib/*.js"
},

@@ -28,5 +29,6 @@ "keywords": [

"dependencies": {
"postcss": "^4.1.4",
"reduce-function-call": "^1.0.1"
"balanced-match": "^0.2.0",
"css-list": "0.0.3",
"postcss": "^4.1.4"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc