.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / stylelint / lib / utils / findAnimationName.js
1 /* @flow */
2 "use strict";
3
4 const getUnitFromValueNode = require("./getUnitFromValueNode");
5 const isStandardSyntaxValue = require("./isStandardSyntaxValue");
6 const isVariable = require("./isVariable");
7 const keywordSets = require("../reference/keywordSets");
8 const postcssValueParser = require("postcss-value-parser");
9
10 /**
11  * Get the font-families within a `font` shorthand property value.
12  */
13 module.exports = function findAnimationName(
14   value /*: string*/
15 ) /*: Array<Object>*/ {
16   const animationNames = [];
17
18   const valueNodes = postcssValueParser(value);
19
20   // Handle `inherit`, `initial` and etc
21   if (
22     valueNodes.nodes.length === 1 &&
23     keywordSets.basicKeywords.has(valueNodes.nodes[0].value.toLowerCase())
24   ) {
25     return [valueNodes.nodes[0]];
26   }
27
28   valueNodes.walk(valueNode => {
29     if (valueNode.type === "function") {
30       return false;
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     // Ignore variables
43     if (isVariable(valueLowerCase)) {
44       return;
45     }
46     // Ignore keywords for other font parts
47     if (keywordSets.animationShorthandKeywords.has(valueLowerCase)) {
48       return;
49     }
50     // Ignore numbers with units
51     const unit = getUnitFromValueNode(valueNode);
52     if (unit || unit === "") {
53       return;
54     }
55
56     animationNames.push(valueNode);
57   });
58
59   return animationNames;
60 };