Created definitions for 'semver'

https://github.com/isaacs/node-semver
This commit is contained in:
Bart van der Schoor 2014-01-27 02:35:25 +01:00
parent bbbca02b99
commit df1b0f4fc7
3 changed files with 168 additions and 0 deletions

View File

@ -219,6 +219,7 @@ List of Definitions
* [require.js](http://requirejs.org/) (by [Josh Baldwin](https://github.com/jbaldwin/))
* [Sammy.js](http://sammyjs.org/) (by [Boris Yankov](https://github.com/borisyankov))
* [Select2](http://ivaynberg.github.com/select2/) (by [Boris Yankov](https://github.com/borisyankov))
* [Semver](https://github.com/isaacs/node-semver) (by [Bart van der Schoor](https://github.com/Bartvds))
* [Sencha Touch](http://www.sencha.com/products/touch/) (by [Brian Kotek](https://github.com/brian428))
* [SharePoint](http://sptypescript.codeplex.com) (by [Stanislav Vyshchepan](http://gandjustas.blogspot.ru) and [Andrey Markeev](http://markeev.com))
* [SignalR](http://www.asp.net/signalr) (by [Boris Yankov](https://github.com/borisyankov))

92
semver/semver-tests.ts Normal file
View File

@ -0,0 +1,92 @@
/// <reference path="semver.d.ts" />
var obj:Object;
var bool:boolean;
var num:number;
var str:string;
var x:any = null;
var arr:any[];
var exp:RegExp;
var strArr:string[];
var numArr:string[];
var mod:typeof SemverModule;
var v1:string, v2:string;
var version:string;
var versions:string[];
var loose:boolean;
str = mod.valid(str);
str = mod.valid(str, loose);
//TODO maybe add an enum for release?
str = mod.inc(str, str, loose);
//Comparison
bool = mod.gt(v1, v2, loose);
bool = mod.gte(v1, v2, loose);
bool = mod.lt(v1, v2, loose);
bool = mod.lte(v1, v2, loose);
bool = mod.eq(v1, v2, loose);
bool = mod.neq(v1, v2, loose);
bool = mod.cmp(v1, x, v2, loose);
num = mod.compare(v1, v2, loose);
num = mod.rcompare(v1, v2, loose);
//Ranges
str = mod.validRange(str, loose);
str = mod.satisfies(version, str, loose);
str = mod.maxSatisfying(versions, str, loose);
bool = mod.gtr(version, str, loose);
bool = mod.ltr(version, str, loose);
bool = mod.outside(version, str, str, loose);
var ver = new mod.Semver(str, bool);
str = ver.raw;
bool = ver.loose;
str = ver.format();
str = ver.inspect();
str = ver.toString();
num = ver.major;
num = ver.minor;
num = ver.patch;
str = ver.version;
strArr = ver.build;
strArr = ver.prerelease;
num = ver.compare(ver);
num = ver.compareMain(ver);
num = ver.comparePre(ver);
ver = ver.inc(str);
var comp = new SemverModule.Comparator(str, bool);
str = comp.raw;
bool = comp.loose;
str = comp.format();
str = comp.inspect();
str = comp.toString();
ver = comp.semver;
str = comp.operator;
bool = comp.value;
comp.parse(str);
bool = comp.test(ver);
var range = new SemverModule.Range(str, bool);
str = range.raw;
bool = range.loose;
str = range.format();
str = range.inspect();
str = range.toString();
bool = range.test(ver);
var sets:SemverModule.Comparator[][];
sets = range.set();
var lims:SemverModule.Comparator[];
lims = range.parseRange(str);

75
semver/semver.d.ts vendored Normal file
View File

@ -0,0 +1,75 @@
// Type definitions for semver v2.2.1
// Project: https://github.com/isaacs/node-semver
// Definitions by: Bart van der Schoor <https://github.com/Bartvds>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
declare module SemverModule {
function valid(v:string, loose?:boolean):string; // Return the parsed version, or null if it's not valid.
//TODO maybe add an enum for release?
function inc(v:string, release:string, loose?:boolean):string; // Return the version incremented by the release type (major, minor, patch, or prerelease), or null if it's not valid.
//Comparison
function gt(v1:string, v2:string, loose?:boolean):boolean; // v1 > v2
function gte(v1:string, v2:string, loose?:boolean):boolean; // v1 >= v2
function lt(v1:string, v2:string, loose?:boolean):boolean; // v1 < v2
function lte(v1:string, v2:string, loose?:boolean):boolean; // v1 <= v2
function eq(v1:string, v2:string, loose?:boolean):boolean; // v1 == v2 This is true if they're logically equivalent, even if they're not the exact same string. You already know how to compare strings.
function neq(v1:string, v2:string, loose?:boolean):boolean; // v1 != v2 The opposite of eq.
function cmp(v1:string, comparator:any, v2:string, loose?:boolean):boolean; // Pass in a comparison string, and it'll call the corresponding function above. "===" and "!==" do simple string comparison, but are included for completeness. Throws if an invalid comparison string is provided.
function compare(v1:string, v2:string, loose?:boolean):number; // Return 0 if v1 == v2, or 1 if v1 is greater, or -1 if v2 is greater. Sorts in ascending order if passed to Array.sort().
function rcompare(v1:string, v2:string, loose?:boolean):number; // The reverse of compare. Sorts an array of versions in descending order when passed to Array.sort().
//Ranges
function validRange(range:string, loose?:boolean):string; // Return the valid range or null if it's not valid
function satisfies(version:string, range:string, loose?:boolean):string; // Return true if the version satisfies the range.
function maxSatisfying(versions:string[], range:string, loose?:boolean):string; // Return the highest version in the list that satisfies the range, or null if none of them do.
function gtr(version:string, range:string, loose?:boolean):boolean; // Return true if version is greater than all the versions possible in the range.
function ltr(version:string, range:string, loose?:boolean):boolean; // Return true if version is less than all the versions possible in the range.
function outside(version:string, range:string, hilo:string, loose?:boolean):boolean; // Return true if the version is outside the bounds of the range in either the high or low direction. The hilo argument must be either the string '>' or '<'. (This is the function called by gtr and ltr.)
class SemverBase {
raw:string;
loose:boolean;
format():string;
inspect():string;
toString():string;
}
class Semver extends SemverBase {
constructor(version:string, loose?:boolean);
major:number;
minor:number;
patch:number;
version:string;
build:string[];
prerelease:string[];
compare(other:Semver):number;
compareMain(other:Semver):number;
comparePre(other:Semver):number;
inc(release:string):Semver;
}
class Comparator extends SemverBase {
constructor(comp:string, loose?:boolean);
semver:Semver;
operator:string;
value:boolean;
parse(comp:string) :void;
test(version:Semver):boolean;
}
class Range extends SemverBase {
constructor(range:string, loose?:boolean);
set():Comparator[][];
parseRange(range:string):Comparator[];
test(version:Semver):boolean;
}
}
declare module "semver" {
export = SemverModule;
}