autotest.utils.js 1.3 KB
Newer Older
杜庆泉's avatar
杜庆泉 已提交
1
"use strict";function t(t,r){const s=t.split("."),e=r.split("."),n=Math.max(s.length,e.length);for(let t=0;t<n;t++){const r=parseInt(s[t]||"0"),n=parseInt(e[t]||"0");if(r>n)return 1;if(r<n)return-1}return 0}function r(r,s){if("*"===s||s===r)return!0;switch(s.slice(0,2)){case">=":return t(r,s.substring(2))>=0;case"<=":return t(r,s.substring(2))<=0;case"!=":return 0!==t(r,s.substring(2))}switch(s.charAt(0)){case">":return t(r,s.substring(1))>0;case"<":return t(r,s.substring(1))<0;case"=":return 0===t(r,s.substring(1));case"^":return parseInt(r.split(".")[0])===parseInt(s.substring(1).split(".")[0])&&t(r,s.substring(1))>=0;case"~":return t(r,(s=s.substring(1).trim())+".0")>=0&&t(r,`${s[0]}.${parseInt(s[2])+1}`)<0;default:return-1!==t(r,s)}}exports.invokeApi=function(t,r,s,...e){if(r||function(t){return!("[object Object]"!==Object.prototype.toString.call(t)||!["success","fail"].find((r=>"function"==typeof t[r])))}(s)){const{success:r,fail:n,...i}=s;return new Promise(((s,u)=>{t({...i,success(t){r&&r(t),s(t)},fail(t){n&&n(t),u(t)}},...e)}))}return t(s,...e)},exports.platformMatch=function(t,s,e){let n=!0;e&&(n=r(s.uniRuntimeVersion,e));const i=t[s.uniPlatform];if(n&&i){if(i[s.osName]){const t=i[s.osName];return r(s[t.versionKey]||"*",t.version||"*")}return r(s[i.versionKey]||"*",i.version||"*")}return!1},exports.satisfies=r;