( node: undefined | null | CssNode, keywords?: readonly string[] )
| 542 | }; |
| 543 | |
| 544 | const parseLiteral = ( |
| 545 | node: undefined | null | CssNode, |
| 546 | keywords?: readonly string[] |
| 547 | ): |
| 548 | | undefined |
| 549 | | UnitValue |
| 550 | | KeywordValue |
| 551 | | ImageValue |
| 552 | | RgbValue |
| 553 | | ColorValue |
| 554 | | VarValue |
| 555 | | FunctionValue => { |
| 556 | if (node?.type === "Number") { |
| 557 | return { |
| 558 | type: "unit", |
| 559 | unit: "number", |
| 560 | value: Number(node.value), |
| 561 | }; |
| 562 | } |
| 563 | if (node?.type === "Dimension" && availableUnits.has(node.unit)) { |
| 564 | return { |
| 565 | type: "unit", |
| 566 | unit: node.unit as Unit, |
| 567 | value: Number(node.value), |
| 568 | }; |
| 569 | } |
| 570 | if (node?.type === "Percentage") { |
| 571 | return { |
| 572 | type: "unit", |
| 573 | unit: "%", |
| 574 | value: Number(node.value), |
| 575 | }; |
| 576 | } |
| 577 | if (node?.type === "Identifier") { |
| 578 | const name = node.name.toLowerCase(); |
| 579 | if ( |
| 580 | keywords?.map((keyword) => keyword.toLowerCase()).includes(name) || |
| 581 | parseColor(name) |
| 582 | ) { |
| 583 | return { |
| 584 | type: "keyword", |
| 585 | value: name, |
| 586 | }; |
| 587 | } |
| 588 | } |
| 589 | if (node?.type === "Url") { |
| 590 | return { |
| 591 | type: "image", |
| 592 | value: { |
| 593 | type: "url", |
| 594 | url: node.value, |
| 595 | }, |
| 596 | }; |
| 597 | } |
| 598 | if (node?.type === "Hash") { |
| 599 | const hexString = `#${node.value}`; |
| 600 | const color = parseColor(hexString); |
| 601 | if (color) { |
no test coverage detected