Skip to content

Commit

Permalink
refactor(postcss-merge-rules): replace array with regex
Browse files Browse the repository at this point in the history
  • Loading branch information
ludofischer committed Nov 8, 2021
1 parent 0102008 commit 42c8bea
Showing 1 changed file with 5 additions and 21 deletions.
26 changes: 5 additions & 21 deletions packages/postcss-merge-rules/src/lib/ensureCompatibility.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,15 @@ const cssFirstLine = 'css-first-line';
const cssInOutOfRange = 'css-in-out-of-range';
const formValidation = 'form-validation';

/** @type {string[]} */
const prefixes = [
'-ah-',
'-apple-',
'-atsc-',
'-epub-',
'-hp-',
'-khtml-',
'-moz-',
'-ms-',
'-o-',
'-rim-',
'-ro-',
'-tc-',
'-wap-',
'-webkit-',
'-xv-',
];
const vendorPrefix =
/-(ah|apple|atsc|epub|hp|khtml|moz|ms|o|rim|ro|tc|wap|webkit|xv)-/;

/**
* @param {string} selector
* @return {string[]}
*/
export function filterPrefixes(selector) {
return prefixes.filter((prefix) => selector.indexOf(prefix) !== -1);
function filterPrefixes(selector) {
return selector.match(vendorPrefix);
}

// Internet Explorer use :-ms-input-placeholder.
Expand All @@ -57,7 +41,7 @@ export function sameVendor(selectorsA, selectorsB) {
* @return {boolean}
*/
export function noVendor(selector) {
return !filterPrefixes(selector).length;
return !vendorPrefix.test(selector);
}

export const pseudoElements = {
Expand Down

0 comments on commit 42c8bea

Please sign in to comment.