2019-10-11 15:29:27 +00:00
|
|
|
/**
|
2020-06-26 12:01:35 +00:00
|
|
|
* External dependencies
|
2019-10-11 15:29:27 +00:00
|
|
|
*/
|
2020-06-26 12:01:35 +00:00
|
|
|
import compareVersions from 'compare-versions';
|
2019-10-11 15:29:27 +00:00
|
|
|
|
|
|
|
/**
|
2020-06-26 12:01:35 +00:00
|
|
|
* Internal dependencies
|
2019-10-11 15:29:27 +00:00
|
|
|
*/
|
2020-06-26 12:01:35 +00:00
|
|
|
import { getSetting } from './get-setting';
|
2019-10-11 15:29:27 +00:00
|
|
|
|
2019-09-23 18:07:13 +00:00
|
|
|
export * from './default-constants';
|
2019-10-11 15:29:27 +00:00
|
|
|
export { setSetting } from './set-setting';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Note: this attempts to coerce the wpVersion to a semver for comparison
|
|
|
|
* This will result in dropping any beta/rc values.
|
|
|
|
*
|
|
|
|
* `5.3-beta1-4252` would get converted to `5.3.0-rc.4252`
|
|
|
|
* `5.3-beta1` would get converted to `5.3.0-rc`.
|
|
|
|
* `5.3` would not be touched.
|
|
|
|
*
|
|
|
|
* For the purpose of these comparisons all pre-release versions are normalized
|
|
|
|
* to `rc`.
|
2019-12-10 17:17:46 +00:00
|
|
|
*
|
|
|
|
* @param {string} version Version to compare.
|
|
|
|
* @param {string} operator Comparison operator.
|
2019-10-11 15:29:27 +00:00
|
|
|
*/
|
|
|
|
export const compareWithWpVersion = ( version, operator ) => {
|
|
|
|
let replacement = getSetting( 'wpVersion', '' ).replace(
|
|
|
|
/-[a-zA-Z0-9]*[\-]*/,
|
|
|
|
'.0-rc.'
|
|
|
|
);
|
|
|
|
replacement = replacement.endsWith( '.' )
|
|
|
|
? replacement.substring( 0, replacement.length - 1 )
|
|
|
|
: replacement;
|
|
|
|
return compareVersions.compare( version, replacement, operator );
|
|
|
|
};
|
|
|
|
|
|
|
|
export { compareVersions, getSetting };
|
2019-11-28 16:33:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a string with the site's wp-admin URL appended. JS version of `admin_url`.
|
|
|
|
*
|
2019-12-10 17:17:46 +00:00
|
|
|
* @param {string} path Relative path.
|
|
|
|
* @return {string} Full admin URL.
|
2019-11-28 16:33:29 +00:00
|
|
|
*/
|
|
|
|
export const getAdminLink = ( path ) => getSetting( 'adminUrl' ) + path;
|