Merge pull request #14475 from tlaziuk/range-parser

[range-parser] new definitions, version 1.2
This commit is contained in:
Arthur Ozga
2017-02-10 14:11:00 -08:00
committed by GitHub
4 changed files with 57 additions and 0 deletions
+25
View File
@@ -0,0 +1,25 @@
// Type definitions for range-parser 1.2
// Project: https://github.com/jshttp/range-parser
// Definitions by: Tomek Łaziuk <https://github.com/tlaziuk>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
declare function RangeParser(size: number, str: string, options?: RangeParser.Options): RangeParser.Result | RangeParser.Ranges;
declare namespace RangeParser {
export interface Ranges extends Array<Range> {
type: string;
}
export interface Range {
start: number;
end: number;
}
export interface Options {
combine?: boolean;
}
export const enum Result {
invaild = -2,
unsatisifiable = -1,
}
}
export = RangeParser;
+11
View File
@@ -0,0 +1,11 @@
import * as RangeParser from 'range-parser';
console.assert(RangeParser(200, `malformed`) === RangeParser.Result.invaild);
console.assert(RangeParser(200, `bytes=500-20`) === RangeParser.Result.unsatisifiable);
const range = RangeParser(1000, `bytes=0-499`);
if (typeof range !== 'number') {
console.assert(range.type === `bytes`);
console.assert(range.length === 1);
}
+20
View File
@@ -0,0 +1,20 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"range-parser-tests.ts"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "../tslint.json" }