declapract
Version:
A tool to declaratively define best practices, maintainable evolve them, and scalably enforce them.
29 lines • 1.7 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.checkDoesFoundValuePassesMinVersionCheck = exports.isCheckMinVersionExpression = exports.getMinVersionFromCheckMinVersionExpression = void 0;
const defineMinPackageVersionRegex_1 = require("../../../../publicFileCheckFunctionUtilities/defineMinPackageVersionRegex");
/**
* grabs the `x.y.z` part from strings that match the shape `@declapract{check.minVersion('x.y.z')}`
*
* returns null if no match
*/
const getMinVersionFromCheckMinVersionExpression = (value) => (new RegExp(/^\@declapract\{check\.minVersion\('([0-9\.]+)'\)\}$/).exec(value) ?? [])[1] ?? null;
exports.getMinVersionFromCheckMinVersionExpression = getMinVersionFromCheckMinVersionExpression;
/**
* checks whether the string matches the form "@declapract{check.minVersion('x.y.z')}" (with nothing before and nothing after, too)
*/
const isCheckMinVersionExpression = (value) => !!(0, exports.getMinVersionFromCheckMinVersionExpression)(value);
exports.isCheckMinVersionExpression = isCheckMinVersionExpression;
/**
* evaluates a foundValue against a minVersion, to check if it passes it or not
*/
const checkDoesFoundValuePassesMinVersionCheck = ({ foundValue, minVersion, }) => {
// define the regex to check against
const minVersionRegexp = (0, defineMinPackageVersionRegex_1.defineMinPackageVersionRegex)(minVersion);
// if foundValue does not match it, return the error message
if (typeof foundValue !== 'string')
return false;
return minVersionRegexp.test(foundValue);
};
exports.checkDoesFoundValuePassesMinVersionCheck = checkDoesFoundValuePassesMinVersionCheck;
//# sourceMappingURL=check.minVersion.js.map