UNPKG

2.05 kBJavaScriptView Raw
1'use strict';
2
3const autoprefixer = require('autoprefixer');
4const Browsers = require('autoprefixer/lib/browsers');
5const Prefixes = require('autoprefixer/lib/prefixes');
6
7/**
8 * Use Autoprefixer's secret powers to determine whether or
9 * not a certain CSS identifier contains a vendor prefix that
10 * Autoprefixer, given the standardized identifier, could add itself.
11 *
12 * Used by `*-no-vendor-prefix-*` rules to find superfluous
13 * vendor prefixes.
14 */
15
16const prefixes = new Prefixes(
17 autoprefixer.data.prefixes,
18 new Browsers(autoprefixer.data.browsers, []),
19);
20
21/**
22 * Most identifier types have to be looked up in a unique way,
23 * so we're exposing special functions for each.
24 */
25module.exports = {
26 /**
27 * @param {string} identifier
28 * @returns {boolean}
29 */
30 atRuleName(identifier) {
31 return Boolean(prefixes.remove[`@${identifier.toLowerCase()}`]);
32 },
33
34 /**
35 * @param {string} identifier
36 * @returns {boolean}
37 */
38 selector(identifier) {
39 return prefixes.remove.selectors.some((/** @type {{ prefixed: string}} */ selectorObj) => {
40 return identifier.toLowerCase() === selectorObj.prefixed;
41 });
42 },
43
44 /**
45 * @param {string} identifier
46 * @returns {boolean}
47 */
48 mediaFeatureName(identifier) {
49 return identifier.toLowerCase().includes('device-pixel-ratio');
50 },
51
52 /**
53 * @param {string} identifier
54 * @returns {boolean}
55 */
56 property(identifier) {
57 return Boolean(autoprefixer.data.prefixes[prefixes.unprefixed(identifier.toLowerCase())]);
58 },
59
60 /**
61 *
62 * @param {string} prop
63 * @param {string} value
64 * @returns {boolean}
65 */
66 propertyValue(prop, value) {
67 const possiblePrefixableValues =
68 (prefixes.remove[prop.toLowerCase()] && prefixes.remove[prop.toLowerCase()].values) || false;
69
70 return (
71 possiblePrefixableValues &&
72 possiblePrefixableValues.some((/** @type {{ prefixed: string}} */ valueObj) => {
73 return value.toLowerCase() === valueObj.prefixed;
74 })
75 );
76 },
77
78 /**
79 *
80 * @param {string} value
81 * @returns {string}
82 */
83 unprefix(value) {
84 return value.replace(/-\w+-/, '');
85 },
86};