@cssfn/css-selectors
Advanced tools
Comparing version 2.0.2 to 2.0.3
@@ -5,2 +5,16 @@ const whitespaceList = [' ', '\n', '\r', '\t', '\f', '\v']; | ||
// parses: | ||
const isNotEmptyExpression = (expression) => (!!expression // not `undefined`|`null`|`false`|emptyString | ||
&& | ||
(expression !== true) // not `true` | ||
); | ||
const joinExpressions = (expressions) => { | ||
if (!Array.isArray(expressions)) { | ||
if (isNotEmptyExpression(expressions)) | ||
return expressions; | ||
return ''; | ||
} // if | ||
return (expressions.flat(Infinity) | ||
.filter(isNotEmptyExpression) | ||
.join(',')); | ||
}; | ||
class ParseSelectors { | ||
@@ -445,3 +459,3 @@ //#region private fields | ||
constructor(expressions) { | ||
this.#expression = [expressions].flat(Infinity).filter((exp) => (typeof (exp) === 'string') && (exp !== '')).join(','); | ||
this.#expression = joinExpressions(expressions); | ||
this.#expressionLength = this.#expression.length; | ||
@@ -448,0 +462,0 @@ this.#pos = 0; |
{ | ||
"name": "@cssfn/css-selectors", | ||
"version": "2.0.2", | ||
"version": "2.0.3", | ||
"description": "Manipulates css selector - parse, transform, calculate specificity, and more.", | ||
@@ -33,4 +33,3 @@ "keywords": [ | ||
"@cssfn/types": "^2.0.1" | ||
}, | ||
"gitHead": "34d5af25d0ea66caecd79d9b575e7baf8a3a4116" | ||
} | ||
} |
@@ -82,2 +82,22 @@ // cssfn: | ||
// parses: | ||
const isNotEmptyExpression = (expression: OptionalOrBoolean<string>): expression is string => ( | ||
!!expression // not `undefined`|`null`|`false`|emptyString | ||
&& | ||
(expression !== true) // not `true` | ||
); | ||
const joinExpressions = (expressions: SingleOrDeepArray<OptionalOrBoolean<string>>): string => { | ||
if (!Array.isArray(expressions)) { | ||
if (isNotEmptyExpression(expressions)) return expressions; | ||
return ''; | ||
} // if | ||
return ( | ||
((expressions as any).flat(Infinity) as OptionalOrBoolean<string>[]) | ||
.filter(isNotEmptyExpression) | ||
.join(',') | ||
); | ||
}; | ||
class ParseSelectors { | ||
@@ -516,3 +536,3 @@ //#region private fields | ||
constructor(expressions: SingleOrDeepArray<OptionalOrBoolean<string>>) { | ||
this.#expression = (([expressions] as any).flat(Infinity) as OptionalOrBoolean<string>[]).filter((exp) => (typeof(exp) === 'string') && (exp !== '')).join(','); | ||
this.#expression = joinExpressions(expressions); | ||
this.#expressionLength = this.#expression.length; | ||
@@ -519,0 +539,0 @@ this.#pos = 0; |
351486
9671