mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-05-25 10:01:30 -04:00
34 lines
1.0 KiB
JavaScript
Executable File
34 lines
1.0 KiB
JavaScript
Executable File
/**
|
|
* @fileoverview Utility functions for React version configuration
|
|
* @author Yannick Croissant
|
|
*/
|
|
'use strict';
|
|
|
|
function getFromContext(context) {
|
|
var confVer = '999.999.999';
|
|
// .eslintrc shared settings (http://eslint.org/docs/user-guide/configuring#adding-shared-settings)
|
|
if (context.settings.react && context.settings.react.version) {
|
|
confVer = context.settings.react.version;
|
|
}
|
|
confVer = /^[0-9]+\.[0-9]+$/.test(confVer) ? confVer + '.0' : confVer;
|
|
return confVer.split('.').map(function(part) {
|
|
return Number(part);
|
|
});
|
|
}
|
|
|
|
function test(context, methodVer) {
|
|
var confVer = getFromContext(context);
|
|
methodVer = methodVer.split('.').map(function(part) {
|
|
return Number(part);
|
|
});
|
|
var higherMajor = methodVer[0] < confVer[0];
|
|
var higherMinor = methodVer[0] === confVer[0] && methodVer[1] < confVer[1];
|
|
var higherOrEqualPatch = methodVer[0] === confVer[0] && methodVer[1] === confVer[1] && methodVer[2] <= confVer[2];
|
|
|
|
return higherMajor || higherMinor || higherOrEqualPatch;
|
|
}
|
|
|
|
module.exports = {
|
|
test: test
|
|
};
|