@gafreax/cssparser
Advanced tools
Comparing version 1.0.6 to 1.0.7
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.parse = void 0; | ||
exports.parse = exports.compact = exports.stringify = exports.tokenize = void 0; | ||
const tokenize_1 = require("./lib/tokenize"); | ||
Object.defineProperty(exports, "tokenize", { enumerable: true, get: function () { return tokenize_1.tokenize; } }); | ||
const stringify_1 = require("./lib/stringify"); | ||
Object.defineProperty(exports, "stringify", { enumerable: true, get: function () { return stringify_1.stringify; } }); | ||
const compact_1 = require("./lib/compact"); | ||
Object.defineProperty(exports, "compact", { enumerable: true, get: function () { return compact_1.compact; } }); | ||
const parse = (css) => (0, stringify_1.stringify)((0, compact_1.compact)((0, tokenize_1.tokenize)(css))); | ||
exports.parse = parse; |
@@ -11,3 +11,3 @@ "use strict"; | ||
// todo: remove empty rules | ||
const css = `div{color:red}div{float:left}a{color:yellow; /* comment */ background: #aaff00;} p{color:#fffff}div{padding:4px;margin:0px} | ||
const css = `div {color:red}div{float:left}a{color:yellow; /* comment */ background: #aaff00;} p{color:#fffff}div{padding:4px;margin:0px} | ||
.row-7 td.column.first .border { | ||
@@ -364,3 +364,3 @@ border: 0; | ||
const perf = []; | ||
const testNumber = 1; | ||
const testNumber = 1000; | ||
for (let i = 0; i < testNumber; i++) { | ||
@@ -367,0 +367,0 @@ const t1 = performance.now(); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.tokenize = exports.isSkippable = void 0; | ||
exports.tokenize = exports.isPunctuation = exports.isSkippable = void 0; | ||
const mediaQuery_1 = require("./mediaQuery"); | ||
@@ -11,11 +11,33 @@ const utils_1 = require("./utils"); | ||
* @param {string} oldChar old char to compare | ||
* @param {string} nextChar next char to compare | ||
* @returns if the current char is skippable | ||
*/ | ||
const isSkippable = function (char, oldChar) { | ||
const isSkippable = (char, oldChar, nextChar) => { | ||
const whiteSpace = ((0, utils_1.isWhitespace)(oldChar) && (0, utils_1.isWhitespace)(char)) || char === '\n'; | ||
const afterSpace = (oldChar === ';' || oldChar === ':' || oldChar === '{' || oldChar === '}') && (0, utils_1.isWhitespace)(char); | ||
return whiteSpace || afterSpace; | ||
const spaceAfter = (oldChar === ';' || oldChar === ':' || oldChar === '{' || oldChar === '}') && (0, utils_1.isWhitespace)(char); | ||
const punctuationNext = (0, utils_1.isWhitespace)(char) && (0, exports.isPunctuation)(nextChar); | ||
return whiteSpace || spaceAfter || punctuationNext; | ||
}; | ||
exports.isSkippable = isSkippable; | ||
/** | ||
* Verify if the char is punctuation like ; : { } ( ) | ||
* @param char the char to check | ||
* @returns if the char is punctuation like ; : { } ( ) | ||
*/ | ||
const isPunctuation = (char) => { | ||
// this is more readable but slower version return [';', ':', '{', '}', '(', ')'].includes(char) | ||
switch (char) { | ||
case ';': | ||
case ':': | ||
case '{': | ||
case '}': | ||
case '(': | ||
case ')': | ||
return true; | ||
default: | ||
return false; | ||
} | ||
}; | ||
exports.isPunctuation = isPunctuation; | ||
/** | ||
* | ||
@@ -96,2 +118,5 @@ * @param css build media queries tokens | ||
} | ||
if ((0, exports.isSkippable)(char, oldChar, nextChar)) { | ||
continue; | ||
} | ||
if (index >= mediaQueries[mediaQueryParsed]?.start) { | ||
@@ -102,5 +127,2 @@ index = mediaQueries[mediaQueryParsed].end + 1; // NOSONAR | ||
} | ||
if ((0, exports.isSkippable)(char, oldChar)) { | ||
continue; | ||
} | ||
// tokenization | ||
@@ -107,0 +129,0 @@ if (char === '}' && ruleValue?.length === 0) { |
{ | ||
"name": "@gafreax/cssparser", | ||
"version": "1.0.6", | ||
"version": "1.0.7", | ||
"description": "Simple CSS Parser to tokenize CSS, merge rules, and optimize it", | ||
@@ -5,0 +5,0 @@ "main": "dist/src/index.js", |
922663
25645