Skip to content

Instantly share code, notes, and snippets.

@kirbysayshi
Created November 7, 2013 23:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kirbysayshi/7363675 to your computer and use it in GitHub Desktop.
Save kirbysayshi/7363675 to your computer and use it in GitHub Desktop.
requirebin sketch
var semver = require('semver');
var version = '0.3.1+jquery-2.1.0';
console.log(semver.valid(version))
console.log(semver.inc(version, 'prerelease'))
console.log(semver.inc(version, 'patch'))
console.log(semver.inc(version, 'minor'))
console.log(semver.inc(version, 'major'))
require=function(r,e,t){function n(n,s){if(!e[n]){if(!r[n]){var o="function"==typeof require&&require;if(!s&&o)return o(n,!0);if(i)return i(n,!0);throw Error("Cannot find module '"+n+"'")}var u=e[n]={exports:{}};r[n][0].call(u.exports,function(t){var r=r[n][1][t];return n(r?r:t)},u,u.exports)}return e[n].exports}for(var i="function"==typeof require&&require,o=0;t.length>o;o++)n(t[o]);return n}({semver:[function(r,e){e.exports=r("1KQryr")},{}],"1KQryr":[function(r,e,t){(function(r){function t(version,loose){var r=loose?P[ee]:P[W];return r.test(version)?new o(version,loose):null}function n(version,loose){var v=t(version,loose);return v?v.version:null}function i(version,loose){var s=t(version,loose);return s?s.version:null}function o(version,loose){if(version instanceof o){if(version.loose===loose)return version;version=version.version}if(!(this instanceof o))return new o(version,loose);this.loose=loose;var m=version.trim().match(loose?P[ee]:P[W]);if(!m)throw new TypeError("Invalid Version: "+version);this.raw=version,this.major=+m[1],this.minor=+m[2],this.patch=+m[3],this.prerelease=m[4]?m[4].split(".").map(function(id){return/^[0-9]+$/.test(id)?+id:id}):[],this.build=m[5]?m[5].split("."):[],this.format()}function s(version,release,loose){try{return new o(version,loose).inc(release).version}catch(er){return null}}function a(a,b){var anum=Se.test(a),bnum=Se.test(b);return anum&&bnum&&(a=+a,b=+b),anum&&!bnum?-1:bnum&&!anum?1:b>a?-1:a>b?1:0}function u(a,b){return a(b,a)}function c(a,b,loose){return new o(a,loose).compare(b)}function f(a,b){return c(a,b,!0)}function p(a,b,loose){return c(b,a,loose)}function v(list,loose){return list.sort(function(a,b){return r.compare(a,b,loose)})}function h(list,loose){return list.sort(function(a,b){return r.rcompare(a,b,loose)})}function l(a,b,loose){return c(a,b,loose)>0}function m(a,b,loose){return 0>c(a,b,loose)}function g(a,b,loose){return 0===c(a,b,loose)}function y(a,b,loose){return 0!==c(a,b,loose)}function d(a,b,loose){return c(a,b,loose)>=0}function w(a,b,loose){return 0>=c(a,b,loose)}function $(a,op,b,loose){var ret;switch(op){case"===":ret=a===b;break;case"!==":ret=a!==b;break;case"":case"=":case"==":ret=g(a,b,loose);break;case"!=":ret=y(a,b,loose);break;case">":ret=l(a,b,loose);break;case">=":ret=d(a,b,loose);break;case"<":ret=m(a,b,loose);break;case"<=":ret=w(a,b,loose);break;default:throw new TypeError("Invalid operator: "+op)}return ret}function j(comp,loose){if(comp instanceof j){if(comp.loose===loose)return comp;comp=comp.value}return this instanceof j?(this.loose=loose,this.parse(comp),this.value=this.semver===ke?"":this.operator+this.semver.version,void 0):new j(comp,loose)}function b(range,loose){if(range instanceof b&&range.loose===loose)return range;if(!(this instanceof b))return new b(range,loose);if(this.loose=loose,this.raw=range,this.set=range.split(/\s*\|\|\s*/).map(function(range){return this.parseRange(range.trim())},this).filter(function(c){return c.length}),!this.set.length)throw new TypeError("Invalid SemVer Range: "+range);this.format()}function x(range,loose){return new b(range,loose).set.map(function(comp){return comp.map(function(c){return c.value}).join(" ").trim().split(" ")})}function E(comp,loose){return comp=k(comp,loose),comp=R(comp,loose),comp=I(comp,loose),comp=A(comp,loose)}function q(id){return!id||"x"===id.toLowerCase()||"*"===id}function R(comp,loose){return comp.trim().split(/\s+/).map(function(comp){return S(comp,loose)}).join(" ")}function S(comp,loose){var r=loose?P[he]:P[ve];return comp.replace(r,function(_,M,m,p,pr){var ret;return q(M)?ret="":q(m)?ret=">="+M+".0.0-0 <"+(+M+1)+".0.0-0":q(p)?ret=">="+M+"."+m+".0-0 <"+M+"."+(+m+1)+".0-0":pr?("-"!==pr.charAt(0)&&(pr="-"+pr),ret=">="+M+"."+m+"."+p+pr+" <"+M+"."+(+m+1)+".0-0"):ret=">="+M+"."+m+"."+p+"-0"+" <"+M+"."+(+m+1)+".0-0",ret})}function k(comp,loose){return comp.trim().split(/\s+/).map(function(comp){return V(comp,loose)}).join(" ")}function V(comp,loose){var r=loose?P[de]:P[ye];return comp.replace(r,function(_,M,m,p,pr){var ret;return q(M)?ret="":q(m)?ret=">="+M+".0.0-0 <"+(+M+1)+".0.0-0":q(p)?ret="0"===M?">="+M+"."+m+".0-0 <"+M+"."+(+m+1)+".0-0":">="+M+"."+m+".0-0 <"+(+M+1)+".0.0-0":pr?("-"!==pr.charAt(0)&&(pr="-"+pr),ret="0"===M?"0"===m?"="+M+"."+m+"."+p+pr:">="+M+"."+m+"."+p+pr+" <"+M+"."+(+m+1)+".0-0":">="+M+"."+m+"."+p+pr+" <"+(+M+1)+".0.0-0"):ret="0"===M?"0"===m?"="+M+"."+m+"."+p:">="+M+"."+m+"."+p+"-0"+" <"+M+"."+(+m+1)+".0-0":">="+M+"."+m+"."+p+"-0"+" <"+(+M+1)+".0.0-0",ret})}function I(comp,loose){return comp.split(/\s+/).map(function(comp){return C(comp,loose)}).join(" ")}function C(comp,loose){comp=comp.trim();var r=loose?P[ue]:P[ae];return comp.replace(r,function(ret,gtlt,M,m,p){var xM=q(M),xm=xM||q(m),xp=xm||q(p),anyX=xp;return"="===gtlt&&anyX&&(gtlt=""),gtlt&&anyX?(xM&&(M=0),xm&&(m=0),xp&&(p=0),">"===gtlt&&(gtlt=">=",xM||(xm?(M=+M+1,m=0,p=0):xp&&(m=+m+1,p=0))),ret=gtlt+M+"."+m+"."+p+"-0"):xM?ret="*":xm?ret=">="+M+".0.0-0 <"+(+M+1)+".0.0-0":xp&&(ret=">="+M+"."+m+".0-0 <"+M+"."+(+m+1)+".0-0"),ret})}function A(comp){return comp.trim().replace(P[qe],"")}function K($0,from,fM,fm,fp,fpr,fb,to,tM,tm,tp,tpr){return from=q(fM)?"":q(fm)?">="+fM+".0.0-0":q(fp)?">="+fM+"."+fm+".0-0":">="+from,to=q(tM)?"":q(tm)?"<"+(+tM+1)+".0.0-0":q(tp)?"<"+tM+"."+(+tm+1)+".0-0":tpr?"<="+tM+"."+tm+"."+tp+"-"+tpr:"<="+to,(from+" "+to).trim()}function Q(set,version){for(var i=0;set.length>i;i++)if(!set[i].test(version))return!1;return!0}function T(version,range,loose){try{range=new b(range,loose)}catch(er){return!1}return range.test(version)}function z(versions,range,loose){return versions.filter(function(version){return T(version,range,loose)}).sort(function(a,b){return p(a,b,loose)})[0]||null}function M(range,loose){try{return new b(range,loose).range||"*"}catch(er){return null}}"object"==typeof e&&e.exports===r&&(r=e.exports=o),r.SEMVER_SPEC_VERSION="2.0.0";var P=r.re=[],Z=r.src=[],L=0,X=L++;Z[X]="0|[1-9]\\d*";var _=L++;Z[_]="[0-9]+";var N=L++;Z[N]="\\d*[a-zA-Z-][a-zA-Z0-9-]*";var O=L++;Z[O]="("+Z[X]+")\\."+"("+Z[X]+")\\."+"("+Z[X]+")";var B=L++;Z[B]="("+Z[_]+")\\."+"("+Z[_]+")\\."+"("+Z[_]+")";var D=L++;Z[D]="(?:"+Z[X]+"|"+Z[N]+")";var F=L++;Z[F]="(?:"+Z[_]+"|"+Z[N]+")";var G=L++;Z[G]="(?:-("+Z[D]+"(?:\\."+Z[D]+")*))";var H=L++;Z[H]="(?:-?("+Z[F]+"(?:\\."+Z[F]+")*))";var J=L++;Z[J]="[0-9A-Za-z-]+";var U=L++;Z[U]="(?:\\+("+Z[J]+"(?:\\."+Z[J]+")*))";var W=L++,Y="v?"+Z[O]+Z[G]+"?"+Z[U]+"?";Z[W]="^"+Y+"$";var re="[v=\\s]*"+Z[B]+Z[H]+"?"+Z[U]+"?",ee=L++;Z[ee]="^"+re+"$";var te=L++;Z[te]="((?:<|>)?=?)";var ne=L++;Z[ne]=Z[_]+"|x|X|\\*";var ie=L++;Z[ie]=Z[X]+"|x|X|\\*";var oe=L++;Z[oe]="[v=\\s]*("+Z[ie]+")"+"(?:\\.("+Z[ie]+")"+"(?:\\.("+Z[ie]+")"+"(?:("+Z[G]+")"+")?)?)?";var se=L++;Z[se]="[v=\\s]*("+Z[ne]+")"+"(?:\\.("+Z[ne]+")"+"(?:\\.("+Z[ne]+")"+"(?:("+Z[H]+")"+")?)?)?";var ae=L++;Z[ae]="^"+Z[te]+"\\s*"+Z[oe]+"$";var ue=L++;Z[ue]="^"+Z[te]+"\\s*"+Z[se]+"$";var ce=L++;Z[ce]="(?:~>?)";var fe=L++;Z[fe]="(\\s*)"+Z[ce]+"\\s+",P[fe]=RegExp(Z[fe],"g");var pe="$1~",ve=L++;Z[ve]="^"+Z[ce]+Z[oe]+"$";var he=L++;Z[he]="^"+Z[ce]+Z[se]+"$";var le=L++;Z[le]="(?:\\^)";var me=L++;Z[me]="(\\s*)"+Z[le]+"\\s+",P[me]=RegExp(Z[me],"g");var ge="$1^",ye=L++;Z[ye]="^"+Z[le]+Z[oe]+"$";var de=L++;Z[de]="^"+Z[le]+Z[se]+"$";var we=L++;Z[we]="^"+Z[te]+"\\s*("+re+")$|^$";var $e=L++;Z[$e]="^"+Z[te]+"\\s*("+Y+")$|^$";var je=L++;Z[je]="(\\s*)"+Z[te]+"\\s*("+re+"|"+Z[oe]+")",P[je]=RegExp(Z[je],"g");var be="$1$2$3",xe=L++;Z[xe]="^\\s*("+Z[oe]+")"+"\\s+-\\s+"+"("+Z[oe]+")"+"\\s*$";var Ee=L++;Z[Ee]="^\\s*("+Z[se]+")"+"\\s+-\\s+"+"("+Z[se]+")"+"\\s*$";var qe=L++;Z[qe]="(<|>)?=?\\s*\\*";for(var Re=0;L>Re;Re++)P[Re]||(P[Re]=RegExp(Z[Re]));r.parse=t,r.valid=n,r.clean=i,r.SemVer=o,o.prototype.format=function(){return this.version=this.major+"."+this.minor+"."+this.patch,this.prerelease.length&&(this.version+="-"+this.prerelease.join(".")),this.version},o.prototype.inspect=function(){return'<SemVer "'+this+'">'},o.prototype.toString=function(){return this.version},o.prototype.compare=function(other){return other instanceof o||(other=new o(other,this.loose)),this.compareMain(other)||this.comparePre(other)},o.prototype.compareMain=function(other){return other instanceof o||(other=new o(other,this.loose)),a(this.major,other.major)||a(this.minor,other.minor)||a(this.patch,other.patch)},o.prototype.comparePre=function(other){if(other instanceof o||(other=new o(other,this.loose)),this.prerelease.length&&!other.prerelease.length)return-1;if(!this.prerelease.length&&other.prerelease.length)return 1;if(!this.prerelease.lenth&&!other.prerelease.length)return 0;var i=0;do{var a=this.prerelease[i],b=other.prerelease[i];if(void 0===a&&void 0===b)return 0;if(void 0===b)return 1;if(void 0===a)return-1;if(a!==b)return a(a,b)}while(++i)},o.prototype.inc=function(release){switch(release){case"major":this.major++,this.minor=-1;case"minor":this.minor++,this.patch=-1;case"patch":this.patch++,this.prerelease=[];break;case"prerelease":if(0===this.prerelease.length)this.prerelease=[0];else{for(var i=this.prerelease.length;--i>=0;)"number"==typeof this.prerelease[i]&&(this.prerelease[i]++,i=-2);-1===i&&this.prerelease.push(0)}break;default:throw Error("invalid increment argument: "+release)}return this.format(),this},r.inc=s,r.compareIdentifiers=a;var Se=/^[0-9]+$/;r.rcompareIdentifiers=u,r.compare=c,r.compareLoose=f,r.rcompare=p,r.sort=v,r.rsort=h,r.gt=l,r.lt=m,r.eq=g,r.neq=y,r.gte=d,r.lte=w,r.cmp=$,r.Comparator=j;var ke={};j.prototype.parse=function(comp){var r=this.loose?P[we]:P[$e],m=comp.match(r);if(!m)throw new TypeError("Invalid comparator: "+comp);this.operator=m[1],m[2]?(this.semver=new o(m[2],this.loose),"<"!==this.operator||this.semver.prerelease.length||(this.semver.prerelease=["0"],this.semver.format())):this.semver=ke},j.prototype.inspect=function(){return'<SemVer Comparator "'+this+'">'},j.prototype.toString=function(){return this.value},j.prototype.test=function(version){return this.semver===ke?!0:$(version,this.operator,this.semver,this.loose)},r.Range=b,b.prototype.inspect=function(){return'<SemVer Range "'+this.range+'">'},b.prototype.format=function(){return this.range=this.set.map(function(comps){return comps.join(" ").trim()}).join("||").trim(),this.range},b.prototype.toString=function(){return this.range},b.prototype.parseRange=function(range){var loose=this.loose;range=range.trim();var hr=loose?P[Ee]:P[xe];range=range.replace(hr,K),range=range.replace(P[je],be),range=range.replace(P[fe],pe),range=range.replace(P[me],ge),range=range.split(/\s+/).join(" ");var compRe=loose?P[we]:P[$e],set=range.split(" ").map(function(comp){return E(comp,loose)}).join(" ").split(/\s+/);return this.loose&&(set=set.filter(function(comp){return!!comp.match(compRe)})),set=set.map(function(comp){return new j(comp,loose)})},r.toComparators=x,b.prototype.test=function(version){if(!version)return!1;for(var i=0;this.set.length>i;i++)if(Q(this.set[i],version))return!0;return!1},r.satisfies=T,r.maxSatisfying=z,r.validRange=M,"function"==typeof define&&define.amd&&define(r)})("object"==typeof t?t:"function"==typeof define&&define.amd?{}:semver={})},{}]},{},[]);var semver=require("semver"),version="0.3.1+jquery-2.1.0-beta";console.log(semver.valid(version)),console.log(semver.inc(version,"prerelease")),console.log(semver.inc(version,"patch")),console.log(semver.inc(version,"minor")),console.log(semver.inc(version,"major"));
<style type='text/css'>html, body { margin: 0; padding: 0; border: 0; }
body, html { height: 100%; width: 100%; }</style>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment