@cssfn/css-selectors
Advanced tools
Comparing version 2.0.4 to 2.0.5
@@ -9,10 +9,22 @@ const whitespaceList = [' ', '\n', '\r', '\t', '\f', '\v']; | ||
); | ||
function* unwrapExpressions(expressions) { | ||
for (const expression of expressions) { | ||
if (!Array.isArray(expression)) { | ||
if (!isNotEmptyExpression(expression)) | ||
continue; // falsy or empty string => ignore | ||
yield expression; | ||
continue; | ||
} // if | ||
for (const subExpression of unwrapExpressions(expression)) { | ||
yield subExpression; | ||
} // for | ||
} // for | ||
} | ||
const joinExpressions = (expressions) => { | ||
if (!Array.isArray(expressions)) { | ||
if (isNotEmptyExpression(expressions)) | ||
return expressions; | ||
return ''; | ||
if (!isNotEmptyExpression(expressions)) | ||
return ''; // falsy or empty string => empty result | ||
return expressions; | ||
} // if | ||
return (expressions.flat(Infinity) | ||
.filter(isNotEmptyExpression) | ||
return (Array.from(unwrapExpressions(expressions)) | ||
.join(',')); | ||
@@ -19,0 +31,0 @@ }; |
{ | ||
"name": "@cssfn/css-selectors", | ||
"version": "2.0.4", | ||
"version": "2.0.5", | ||
"description": "Manipulates css selector - parse, transform, calculate specificity, and more.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -5,2 +5,3 @@ // cssfn: | ||
SingleOrArray, | ||
DeepArray, | ||
SingleOrDeepArray, | ||
@@ -88,6 +89,21 @@ } from '@cssfn/types' | ||
); | ||
function* unwrapExpressions(expressions: DeepArray<OptionalOrBoolean<string>>): Generator<string> { | ||
for (const expression of expressions) { | ||
if (!Array.isArray(expression)) { | ||
if (!isNotEmptyExpression(expression)) continue; // falsy or empty string => ignore | ||
yield expression; | ||
continue; | ||
} // if | ||
for (const subExpression of unwrapExpressions(expression)) { | ||
yield subExpression; | ||
} // for | ||
} // for | ||
} | ||
const joinExpressions = (expressions: SingleOrDeepArray<OptionalOrBoolean<string>>): string => { | ||
if (!Array.isArray(expressions)) { | ||
if (isNotEmptyExpression(expressions)) return expressions; | ||
return ''; | ||
if (!isNotEmptyExpression(expressions)) return ''; // falsy or empty string => empty result | ||
return expressions; | ||
} // if | ||
@@ -98,4 +114,3 @@ | ||
return ( | ||
((expressions as any).flat(Infinity) as OptionalOrBoolean<string>[]) | ||
.filter(isNotEmptyExpression) | ||
Array.from(unwrapExpressions(expressions)) | ||
.join(',') | ||
@@ -102,0 +117,0 @@ ); |
352446
9695