u-semver
Version:
A micro parser and version resolver for Semantic Version
1 lines • 2.09 kB
JavaScript
!function(t,r){if("function"==typeof define&&define.amd)define(["exports"],r);else if("undefined"!=typeof exports)r(exports);else{var n={exports:{}};r(n.exports),t.uSemver=n.exports}}(this,function(t){"use strict";function r(t){var r=v(t),n=function(t,r,n){return t+r*c[n]};return r.reduce(n,0)}function n(t,n){var e=[t,n].map(r),u=i(e,2),o=u[0],f=u[1],c=[t,n].map(x),a=i(c,2),s=a[0],d=a[1];if(s===d){if(/beta/.test(t)&&/alpha/.test(n))return 1;if(/alpha/.test(t)&&/beta/.test(n)||y(t)&&!y(n))return-1}return o-f}function e(t){var r=b(t),n=s(r);return m(n)?d(function(t){return t===n.split("-")[0]},t)||n:n}function u(t,r,n){if("latest"===t)return e(r);var u=o.exec(t),f=i(u,7),c=f[0],a=f[1],s=f[2],l=f[3],p=f[4],v=f[5],h=f[6];if(!a)return d(function(t){return t===c},r);var y="^"===a?"^("+s+")\\.(\\d+)\\.(\\d+)":"^("+s+")\\.("+l+")\\.(\\d+)",m=[s,l,p,v,h];return n?w(r,y+"(-(\\w+)(\\.(\\d+))?)?$",m):w(r,y+"$",m)}Object.defineProperty(t,"__esModule",{value:!0}),t.resolve=u;var i=function(){function t(t,r){var n=[],e=!0,u=!1,i=void 0;try{for(var o,f=t[Symbol.iterator]();!(e=(o=f.next()).done)&&(n.push(o.value),!r||n.length!==r);e=!0);}catch(c){u=!0,i=c}finally{try{!e&&f["return"]&&f["return"]()}finally{if(u)throw i}}return n}return function(r,n){if(Array.isArray(r))return r;if(Symbol.iterator in Object(r))return t(r,n);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),o=/^([\^\~])?(\d+)\.(\d+)\.(\d+)(-(\w+)(\.(\d+))?)?$/,f=/^(\d+).(\d+).(\d+)/,c=[1e6,1e3,10,0,1],a=function(t){return t[0]},s=function(t){return t[t.length-1]},d=function(t,r){return a(r.filter(t))},l=function(t){return!isNaN(t)},p=function(t){return+t},v=function(t){return t.match(o).slice(1).map(p).filter(l)},h=function(t){return function(r){return v(r).reduce(function(r,n,e){return r&&(void 0!==t[e]?n>=t[e]:!0)},!0)}},y=function(t){return/(alpha|beta)/.test(t)},m=function(t){return t&&t.indexOf("-")>=0},x=function(t){return t.match(f)[0]},b=t.sort=function(t){return t.slice().sort(n)},w=function(t,r,n){return e(t.filter(function(t){return RegExp(r).test(t)}).filter(h(n)))}});