New:Socket for Asana Is Now Available.Learn more
Get Started

postcss-normalize-whitespace

Package Overview
Dependencies
Maintainers
7
Versions
47
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

postcss-normalize-whitespace - npm Package Compare versions

Comparing version
8.0.1
to
8.0.2
+18
-7
package.json
{
"name": "postcss-normalize-whitespace",
"version": "8.0.1",
"version": "8.0.2",
"description": "Trim whitespace inside and around CSS rules & declarations.",
"main": "src/index.js",
"types": "types/index.d.ts",
"exports": {
".": {
"types": "./types/index.d.ts",
"default": "./src/index.js"
},
"./src": "./src/index.js",
"./src/index": "./src/index.js",
"./src/index.js": "./src/index.js",
"./package.json": "./package.json"
},
"files": [

@@ -22,5 +30,8 @@ "src",

"email": "beneb.info@gmail.com",
"url": "http://beneb.info"
"url": "https://beneb.info"
},
"repository": "cssnano/cssnano",
"repository": {
"type": "git",
"url": "cssnano/cssnano"
},
"dependencies": {

@@ -36,7 +47,7 @@ "postcss-value-parser": "^4.2.0"

"devDependencies": {
"postcss": "^8.5.15"
"postcss": "^8.5.25"
},
"peerDependencies": {
"postcss": "^8.5.15"
"postcss": "^8.5.25"
}
}

@@ -42,4 +42,4 @@ # [postcss][postcss]-normalize-whitespace

MIT © [Ben Briggs](http://beneb.info)
MIT © [Ben Briggs](https://beneb.info)
[postcss]: https://github.com/postcss/postcss

@@ -8,2 +8,4 @@ 'use strict';

const variableFunctions = new Set(['var', 'env', 'constant']);
const ieHackRegex = /\s*(\\9)\s*/;
const whitespaceRegex = /\s/g;

@@ -44,3 +46,41 @@ /**

/**
* @type {import('postcss').PluginCreator<void>}
*
* @param {import('postcss').Declaration} node
* @param {Map<string, string>} cache
* @return {void}
*/
function trimDeclaration(node, cache) {
// Ensure that !important values do not have any excess whitespace
if (node.important) {
node.raws.important = '!important';
}
// Remove whitespaces around ie 9 hack
node.value = node.value.replace(ieHackRegex, '$1');
const value = node.value;
if (cache.has(value)) {
node.value = /** @type {string} **/ (cache.get(value));
} else {
const parsed = valueParser(node.value);
const result = parsed.walk(reduceWhitespaces).toString();
// Trim whitespace inside functions & dividers
node.value = result;
cache.set(value, result);
}
// Remove extra semicolons and whitespace before the declaration
if (node.raws.before) {
const prev = node.prev();
if (prev && prev.type !== rule) {
node.raws.before = node.raws.before.replace(/;/g, '');
}
}
node.raws.between = ':';
node.raws.semicolon = false;
}
/**
* @return {import('postcss').Plugin}

@@ -52,4 +92,7 @@ */

/**
* @param {import('postcss').Root} css
*/
OnceExit(css) {
const cache = new Map();
const declarationCache = new Map();

@@ -60,40 +103,7 @@ css.walk((node) => {

if ([decl, rule, atrule].includes(type) && node.raws.before) {
node.raws.before = node.raws.before.replace(/\s/g, '');
node.raws.before = node.raws.before.replace(whitespaceRegex, '');
}
if (type === decl) {
// Ensure that !important values do not have any excess whitespace
if (node.important) {
node.raws.important = '!important';
}
// Remove whitespaces around ie 9 hack
node.value = node.value.replace(/\s*(\\9)\s*/, '$1');
const value = node.value;
if (cache.has(value)) {
node.value = cache.get(value);
} else {
const parsed = valueParser(node.value);
const result = parsed.walk(reduceWhitespaces).toString();
// Trim whitespace inside functions & dividers
node.value = result;
cache.set(value, result);
}
if (node.prop.startsWith('--') && node.value === '') {
node.value = ' ';
}
// Remove extra semicolons and whitespace before the declaration
if (node.raws.before) {
const prev = node.prev();
if (prev && prev.type !== rule) {
node.raws.before = node.raws.before.replace(/;/g, '');
}
}
node.raws.between = ':';
node.raws.semicolon = false;
if (type === decl && !node.prop.startsWith('--')) {
trimDeclaration(node, declarationCache);
} else if (type === rule || type === atrule) {

@@ -112,2 +122,4 @@ node.raws.between = node.raws.after = '';

pluginCreator.postcss = true;
module.exports = pluginCreator;
module.exports = /** @type {import('postcss').PluginCreator<void>}*/ (
pluginCreator
);

@@ -1,10 +0,3 @@

export = pluginCreator;
/**
* @type {import('postcss').PluginCreator<void>}
* @return {import('postcss').Plugin}
*/
declare function pluginCreator(): import("postcss").Plugin;
declare namespace pluginCreator {
let postcss: true;
}
declare const _exports: import("postcss").PluginCreator<void>;
export = _exports;
//# sourceMappingURL=index.d.ts.map

@@ -1,1 +0,1 @@

{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":";AAyCA;;;GAGG;AACH,kCAFY,OAAO,SAAS,EAAE,MAAM,CA6DnC"}
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":""}

Sorry, the diff of this file is not supported yet