Add route-parser type declarations (#14013)

This commit is contained in:
Ian Ker-Seymer
2017-01-19 21:05:02 -08:00
committed by Mohamed Hegazy
parent 0b60775142
commit ab1f759aa1
4 changed files with 67 additions and 0 deletions
+39
View File
@@ -0,0 +1,39 @@
// Type definitions for route-parser 0.0
// Project: https://github.com/rcs/route-parser
// Definitions by: Ian Ker-Seymer <https://github.com/ianks>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
declare class Route {
/**
* Represents a route
* @example
* var route = new Route('/:foo/:bar');
* @example
* var route = new Route('/:foo/:bar');
*/
constructor(spec: string);
/**
* Match a path against this route, returning the matched parameters if
* it matches, false if not.
* @example
* var route = new Route('/this/is/my/route')
* route.match('/this/is/my/route') // -> {}
* @example
* var route = new Route('/:one/:two')
* route.match('/foo/bar/') // -> {one: 'foo', two: 'bar'}
*/
match(pathname: string): { [i: string]: string } | boolean;
/**
* Reverse a route specification to a path, returning false if it can't be
* fulfilled
* @example
* var route = new Route('/:one/:two')
* route.reverse({one: 'foo', two: 'bar'}) -> '/foo/bar'
*/
reverse(params: { [i: string]: any } ): string | boolean;
}
declare namespace Route {}
export = Route;
+5
View File
@@ -0,0 +1,5 @@
import * as Route from 'route-parser';
const route = new Route('/users/:id');
const matched = route.match('/users/42'); // => { id: '42' }
const reversed = route.reverse({ id: 42 });
+20
View File
@@ -0,0 +1,20 @@
{
"files": [
"index.d.ts",
"route-parser-tests.ts"
],
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": false,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
}
}
+3
View File
@@ -0,0 +1,3 @@
{
"extends": "../tslint.json"
}