mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-12 21:10:23 +00:00
Add route-parser type declarations (#14013)
This commit is contained in:
committed by
Mohamed Hegazy
parent
0b60775142
commit
ab1f759aa1
Vendored
+39
@@ -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;
|
||||
@@ -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 });
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"extends": "../tslint.json"
|
||||
}
|
||||
Reference in New Issue
Block a user