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

postcss-resolution-independence

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

postcss-resolution-independence - npm Package Compare versions

Comparing version 1.0.1 to 1.1.0

CHANGELOG.md

52

index.js

@@ -1,3 +0,2 @@

const postcss = require('postcss');
const parser = require('postcss-values-parser');
const {parse} = require('postcss-values-parser');

@@ -24,3 +23,3 @@ /**

*/
module.exports = postcss.plugin('postcss-resolution-independence',
module.exports =
({

@@ -37,26 +36,31 @@ baseSize = 24,

return (css) => {
css.walkDecls(decl => {
const nodes = parser(decl.value, {loose: true}).parse()
nodes.walkNumberNodes(node => {
const value = parseFloat(node.value)
// The standard unit to convert (if no unit, we assume the base unit)
if (node.unit === unit) {
const scaledValue = Math.abs(value * minScaleFactor);
if (scaledValue && scaledValue <= minUnitSize) {
if (Math.abs(value) >= minUnitSize) {
node.value = minUnitSize * (value < 0 ? -1 : 1);
return {
postcssPlugin: 'postcss-resolution-independence',
Once (css) {
css.walkDecls(decl => {
const nodes = parse(decl.value, {ignoreUnknownWords: true})
nodes.walkNumerics(node => {
const value = parseFloat(node.value)
// The standard unit to convert (if no unit, we assume the base unit)
if (node.unit === unit) {
const scaledValue = Math.abs(value * minScaleFactor);
if (scaledValue && scaledValue <= minUnitSize) {
if (Math.abs(value) >= minUnitSize) {
node.value = minUnitSize * (value < 0 ? -1 : 1);
}
} else {
node.value = parseFloat((value / baseSize).toFixed(precision));
node.unit = riUnit;
}
} else {
node.value = parseFloat((value / baseSize).toFixed(precision));
node.unit = riUnit;
} else if (node.unit === absoluteUnit) {
// The absolute unit to convert to our standard unit
node.unit = unit;
}
} else if (node.unit === absoluteUnit) {
// The absolute unit to convert to our standard unit
node.unit = unit;
}
});
decl.value = nodes.toString();
});
decl.value = nodes.toString();
});
}
};
});
};
module.exports.postcss = true;
{
"name": "postcss-resolution-independence",
"version": "1.0.1",
"version": "1.1.0",
"description": "Resolution independence conversion plugin for PostCSS",

@@ -33,9 +33,12 @@ "author": "Jason Robitaille <jason.robitaille@lge.com>",

"dependencies": {
"postcss": "^7.0.0",
"postcss-values-parser": "^2.0.1"
"postcss-values-parser": "^6.0.2"
},
"devDependencies": {
"chai": "^4.3.4",
"mocha": "^9.1.3"
"mocha": "^9.1.3",
"postcss": "^8.4.4"
},
"peerDependencies": {
"postcss": "^8.0.0"
},
"scripts": {

@@ -42,0 +45,0 @@ "test": "mocha --reporter spec"

const chai = require('chai');
const postcss = require('postcss');
const parser = require('postcss-values-parser');
const {parse} = require('postcss-values-parser');
const riPlugin = require('..');

@@ -13,3 +13,3 @@

.then(function (result) {
return parser(result.root.nodes[0].value, {loose:true}).parse();
return parse(result.root.nodes[0].value, {ignoreUnknownWords:true});
})

@@ -34,4 +34,4 @@ );

return processValue().then(out => {
expect(parseFloat(out.nodes[0].nodes[0].value)).to.equal(1.5);
expect(out.nodes[0].nodes[0].unit).to.equal('rem');
expect(parseFloat(out.nodes[0].value)).to.equal(1.5);
expect(out.nodes[0].unit).to.equal('rem');
});

@@ -43,4 +43,4 @@ });

return processValue().then(out => {
expect(parseFloat(out.nodes[0].nodes[0].value)).to.equal(2);
expect(out.nodes[0].nodes[0].unit).to.equal('vh');
expect(parseFloat(out.nodes[0].value)).to.equal(2);
expect(out.nodes[0].unit).to.equal('vh');
});

@@ -52,4 +52,4 @@ });

return processValue({unit: 'em'}).then(out => {
expect(parseFloat(out.nodes[0].nodes[0].value)).to.equal(2);
expect(out.nodes[0].nodes[0].unit).to.equal('rem');
expect(parseFloat(out.nodes[0].value)).to.equal(2);
expect(out.nodes[0].unit).to.equal('rem');
});

@@ -61,4 +61,4 @@ });

return processValue({unit: 'abspx'}).then(out => {
expect(parseFloat(out.nodes[0].nodes[0].value)).to.equal(48);
expect(out.nodes[0].nodes[0].unit).to.equal('px');
expect(parseFloat(out.nodes[0].value)).to.equal(48);
expect(out.nodes[0].unit).to.equal('px');
});

@@ -70,4 +70,4 @@ });

return processValue({value: 0.24}).then(out => {
expect(parseFloat(out.nodes[0].nodes[0].value)).to.equal(0.01);
expect(out.nodes[0].nodes[0].unit).to.equal('rem');
expect(parseFloat(out.nodes[0].value)).to.equal(0.01);
expect(out.nodes[0].unit).to.equal('rem');
});

@@ -79,4 +79,4 @@ });

return processValue({value: 9}).then(out => {
expect(parseFloat(out.nodes[0].nodes[0].value)).to.equal(9);
expect(out.nodes[0].nodes[0].unit).to.equal('px');
expect(parseFloat(out.nodes[0].value)).to.equal(9);
expect(out.nodes[0].unit).to.equal('px');
});

@@ -89,4 +89,4 @@ });

return processValue().then(out => {
expect(parseFloat(out.nodes[0].nodes[0].value)).to.equal(24);
expect(out.nodes[0].nodes[0].unit).to.equal('px');
expect(parseFloat(out.nodes[0].value)).to.equal(24);
expect(out.nodes[0].unit).to.equal('px');
});

@@ -99,4 +99,4 @@ });

return processValue().then(out => {
expect(parseFloat(out.nodes[0].nodes[0].value)).to.equal(1.45);
expect(out.nodes[0].nodes[0].unit).to.equal('rem');
expect(parseFloat(out.nodes[0].value)).to.equal(1.45);
expect(out.nodes[0].unit).to.equal('rem');
});

@@ -103,0 +103,0 @@ });

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