renovate/lib/util/package-rules/current-value.ts

23 lines
640 B
TypeScript
Raw Normal View History

2022-09-25 00:56:02 -06:00
import is from '@sindresorhus/is';
import type { PackageRule, PackageRuleInputConfig } from '../../config/types';
import { getRegexOrGlobPredicate } from '../string-match';
2022-09-25 00:56:02 -06:00
import { Matcher } from './base';
export class CurrentValueMatcher extends Matcher {
override matches(
{ currentValue }: PackageRuleInputConfig,
{ matchCurrentValue }: PackageRule,
2022-09-25 00:56:02 -06:00
): boolean | null {
if (is.undefined(matchCurrentValue)) {
return null;
}
const matchCurrentValuePred = getRegexOrGlobPredicate(matchCurrentValue);
2022-09-25 00:56:02 -06:00
if (!currentValue) {
return false;
}
return matchCurrentValuePred(currentValue);
}
}