stylelint
Version:
A mighty CSS linter that helps you avoid errors and enforce conventions.
30 lines (23 loc) • 874 B
JavaScript
import matchesStringOrRegExp from './matchesStringOrRegExp.mjs';
/**
* Check if an options object's propertyName contains a user-defined entry
* whose key pattern matches inputName and whose value pattern matches inputValue.
*
* @param {Record<string, unknown> | undefined} options
* @param {string} propertyName
* @param {string} inputName
* @param {string} inputValue
*
* @returns {boolean}
*/
export default function optionsMatchesEntry(options, propertyName, inputName, inputValue) {
if (!options) return false;
const propertyValue = options[propertyName];
if (!propertyValue) return false;
const entries = Object.entries(propertyValue);
const matchedEntry = entries.find(([namePattern]) =>
matchesStringOrRegExp(inputName, namePattern),
);
if (!matchedEntry) return false;
return Boolean(matchesStringOrRegExp(inputValue, matchedEntry[1]));
}