UNPKG

1.38 kBJavaScriptView Raw
1'use strict';
2
3const isStandardSyntaxValue = require('./isStandardSyntaxValue');
4const isVariable = require('./isVariable');
5const keywordSets = require('../reference/keywordSets');
6const postcssValueParser = require('postcss-value-parser');
7
8/**
9 * Get the list-style-type within a `list-style` shorthand property value.
10 *
11 * @param {string} value
12 */
13module.exports = function findListStyleType(value) {
14 /** @type {Array<import('postcss-value-parser').WordNode>} */
15 const listStyleTypes = [];
16
17 const valueNodes = postcssValueParser(value);
18
19 // Handle `inherit`, `initial` and etc
20 if (
21 valueNodes.nodes.length === 1 &&
22 keywordSets.listStyleTypeKeywords.has(valueNodes.nodes[0].value.toLowerCase())
23 ) {
24 return [valueNodes.nodes[0]];
25 }
26
27 valueNodes.walk((valueNode) => {
28 if (valueNode.type === 'function') {
29 return false;
30 }
31
32 if (valueNode.type !== 'word') {
33 return;
34 }
35
36 const valueLowerCase = valueNode.value.toLowerCase();
37
38 // Ignore non standard syntax
39 if (!isStandardSyntaxValue(valueLowerCase)) {
40 return;
41 }
42
43 // Ignore variables
44 if (isVariable(valueLowerCase)) {
45 return;
46 }
47
48 // Ignore keywords for other font parts
49 if (
50 keywordSets.listStylePositionKeywords.has(valueLowerCase) ||
51 keywordSets.listStyleImageKeywords.has(valueLowerCase)
52 ) {
53 return;
54 }
55
56 listStyleTypes.push(valueNode);
57 });
58
59 return listStyleTypes;
60};