.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / stylelint / lib / utils / findListStyleType.js
1 /* @flow */
2 "use strict";
3
4 const isStandardSyntaxValue = require("./isStandardSyntaxValue");
5 const isVariable = require("./isVariable");
6 const keywordSets = require("../reference/keywordSets");
7 const postcssValueParser = require("postcss-value-parser");
8
9 /**
10  * Get the list-style-type within a `list-style` shorthand property value.
11  */
12 module.exports = function findListStyleType(
13   value /*: string*/
14 ) /*: Array<Object>*/ {
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(
23       valueNodes.nodes[0].value.toLowerCase()
24     )
25   ) {
26     return [valueNodes.nodes[0]];
27   }
28
29   valueNodes.walk(valueNode => {
30     if (valueNode.type === "function") {
31       return false;
32     }
33     if (valueNode.type !== "word") {
34       return;
35     }
36
37     const valueLowerCase = valueNode.value.toLowerCase();
38
39     // Ignore non standard syntax
40     if (!isStandardSyntaxValue(valueLowerCase)) {
41       return;
42     }
43     // Ignore variables
44     if (isVariable(valueLowerCase)) {
45       return;
46     }
47     // Ignore keywords for other font parts
48     if (
49       keywordSets.listStylePositionKeywords.has(valueLowerCase) ||
50       keywordSets.listStyleImageKeywords.has(valueLowerCase)
51     ) {
52       return;
53     }
54
55     listStyleTypes.push(valueNode);
56   });
57
58   return listStyleTypes;
59 };