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

postcss-normalize-positions

Package Overview
Dependencies
Maintainers
4
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

postcss-normalize-positions - npm Package Compare versions

Comparing version 4.0.1 to 4.0.2

49

dist/index.js

@@ -37,6 +37,7 @@ 'use strict';

function transform(decl) {
const values = (0, _postcssValueParser2.default)(decl.value);
const args = (0, _cssnanoUtilGetArguments2.default)(values);
function transform(value) {
const parsed = (0, _postcssValueParser2.default)(value);
const args = (0, _cssnanoUtilGetArguments2.default)(parsed);
const relevant = [];
args.forEach(arg => {

@@ -47,10 +48,14 @@ relevant.push({

});
arg.forEach((part, index) => {
const isPosition = ~directions.indexOf(part.value.toLowerCase()) || (0, _postcssValueParser.unit)(part.value);
const len = relevant.length - 1;
if (relevant[len].start === null && isPosition) {
relevant[len].start = index;
relevant[len].end = index;
return;
}
if (relevant[len].start !== null) {

@@ -61,4 +66,6 @@ if (part.type === 'space') {

relevant[len].end = index;
return;
}
return;

@@ -68,2 +75,3 @@ }

});
relevant.forEach((range, index) => {

@@ -73,8 +81,12 @@ if (range.start === null) {

}
const position = args[index].slice(range.start, range.end + 1);
if (position.length > 3) {
return;
}
const firstValue = position[0].value.toLowerCase();
const secondValue = position[2] && position[2].value ? position[2].value.toLowerCase() : null;
if (position.length === 1 || secondValue === 'center') {

@@ -84,20 +96,28 @@ if (secondValue) {

}
const map = Object.assign({}, horizontal, {
center
});
if ((0, _has2.default)(map, firstValue)) {
position[0].value = map[firstValue];
}
return;
}
if (firstValue === 'center' && ~directions.indexOf(secondValue)) {
position[0].value = position[1].value = '';
if ((0, _has2.default)(horizontal, secondValue)) {
position[2].value = horizontal[secondValue];
}
return;
}
if ((0, _has2.default)(horizontal, firstValue) && (0, _has2.default)(vertical, secondValue)) {
position[0].value = horizontal[firstValue];
position[2].value = vertical[secondValue];
return;

@@ -107,11 +127,30 @@ } else if ((0, _has2.default)(vertical, firstValue) && (0, _has2.default)(horizontal, secondValue)) {

position[2].value = vertical[firstValue];
return;
}
});
decl.value = values.toString();
return parsed.toString();
}
exports.default = (0, _postcss.plugin)('postcss-normalize-positions', () => {
return css => css.walkDecls(/^(background(-position)?|(-webkit-)?perspective-origin)$/i, transform);
return css => {
const cache = {};
css.walkDecls(/^(background(-position)?|(-webkit-)?perspective-origin)$/i, decl => {
const value = decl.value;
if (cache[value]) {
decl.value = cache[value];
return;
}
const result = transform(value);
decl.value = result;
cache[value] = result;
});
};
});
module.exports = exports['default'];

2

package.json
{
"name": "postcss-normalize-positions",
"version": "4.0.1",
"version": "4.0.2",
"description": "Normalize keyword values for position into length values.",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

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