From ab1f759aa100aa31585ee882f4a19f4b0f49d365 Mon Sep 17 00:00:00 2001 From: Ian Ker-Seymer Date: Fri, 20 Jan 2017 00:05:02 -0500 Subject: [PATCH] Add route-parser type declarations (#14013) --- route-parser/index.d.ts | 39 ++++++++++++++++++++++++++++++ route-parser/route-parser-tests.ts | 5 ++++ route-parser/tsconfig.json | 20 +++++++++++++++ route-parser/tslint.json | 3 +++ 4 files changed, 67 insertions(+) create mode 100644 route-parser/index.d.ts create mode 100644 route-parser/route-parser-tests.ts create mode 100644 route-parser/tsconfig.json create mode 100644 route-parser/tslint.json diff --git a/route-parser/index.d.ts b/route-parser/index.d.ts new file mode 100644 index 0000000000..2f5dd84e8d --- /dev/null +++ b/route-parser/index.d.ts @@ -0,0 +1,39 @@ +// Type definitions for route-parser 0.0 +// Project: https://github.com/rcs/route-parser +// Definitions by: Ian Ker-Seymer +// 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; diff --git a/route-parser/route-parser-tests.ts b/route-parser/route-parser-tests.ts new file mode 100644 index 0000000000..e521008291 --- /dev/null +++ b/route-parser/route-parser-tests.ts @@ -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 }); diff --git a/route-parser/tsconfig.json b/route-parser/tsconfig.json new file mode 100644 index 0000000000..6f14fe510c --- /dev/null +++ b/route-parser/tsconfig.json @@ -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 + } +} diff --git a/route-parser/tslint.json b/route-parser/tslint.json new file mode 100644 index 0000000000..192203ab54 --- /dev/null +++ b/route-parser/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "../tslint.json" +} \ No newline at end of file