diff --git a/notNeededPackages.json b/notNeededPackages.json index 4acd790e24..86aa89f7dd 100644 --- a/notNeededPackages.json +++ b/notNeededPackages.json @@ -1656,6 +1656,12 @@ "sourceRepoURL": "https://github.com/dpa99c/phonegap-launch-navigator", "asOfVersion": "4.0.0" }, + { + "libraryName": "Universal Router", + "typingsPackageName": "universal-router", + "sourceRepoURL": "https://github.com/kriasoft/universal-router", + "asOfVersion": "8.0.0" + }, { "libraryName": "upper-case", "typingsPackageName": "upper-case", diff --git a/types/universal-router/generateUrls.d.ts b/types/universal-router/generateUrls.d.ts deleted file mode 100644 index 620cef3344..0000000000 --- a/types/universal-router/generateUrls.d.ts +++ /dev/null @@ -1,14 +0,0 @@ -import UniversalRouter, { Params } from "."; -import { PathFunctionOptions } from 'path-to-regexp'; - -export interface GenerateUrlsOptions extends PathFunctionOptions { - /** - * Provide a function to stringifyQueryParams option to generate URL with query string from unknown route params. - */ - stringifyQueryParams?: (params: Params) => string; -} - -/** - * In most web applications it's much simpler to just use a string for hyperlinks. - */ -export default function generateUrls(router: UniversalRouter, options?: GenerateUrlsOptions): (routeName: string, params?: Params) => string; diff --git a/types/universal-router/index.d.ts b/types/universal-router/index.d.ts deleted file mode 100644 index 8dd2357f03..0000000000 --- a/types/universal-router/index.d.ts +++ /dev/null @@ -1,122 +0,0 @@ -// Type definitions for universal-router 7.0 -// Project: https://github.com/kriasoft/universal-router -// Definitions by: Jack Moore -// Tomek Łaziuk -// Lodin -// acidghost -// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.3 - -import pathToRegexp = require('path-to-regexp'); - -/** - * Params is a key/value object that represents extracted URL parameters. - * Each URL parameter resolves to a string. - */ -export interface Params { - [_: string]: any; -} - -/** - * In addition to a URL path string, any arbitrary data can be passed to the `router.resolve()` method, that becomes available inside action functions. - */ -export interface Context { - [_: string]: any; -} - -export interface PathnameContext extends Context { - /** - * URL which was transmitted to `router.resolve()`. - */ - pathname: string; -} - -export interface ActionContext extends PathnameContext { - /** - * Current router instance. - */ - router: UniversalRouter; - /** - * Matched route object. - */ - route: Route; - /** - * Middleware style function which can continue resolving. - */ - next: (resume?: boolean, parent?: Route, prevResult?: any) => Promise; - /** - * Base URL path relative to the path of the current route. - */ - baseUrl: string; - /** - * Matched path. - */ - path: string; - /** - * Matched path params. - */ - params: Params; - /** - * An array of keys found in the path, see `path-to-regexp` documentation for details. - * @see https://github.com/pillarjs/path-to-regexp - */ - keys: pathToRegexp.Key[]; -} - -/** - * A Route is a singular route in your application. It contains a path, an - * action function, and optional children which are an array of Route. - * - * @template C User context that is made union with ActionContext. - * @template R Result that every action function resolves to. If the action returns a Promise, R can be the type the Promise resolves to. - */ -export interface Route { - path?: string | RegExp | Array; - /** - * unique string - */ - name?: string; - /** - * automatically filled by the router - */ - parent?: Route | null; - /** - * array of route objects - */ - children?: Routes | null; - /** - * action method should return anything except `null` or `undefined` to be resolved by router - * otherwise router will throw `Page not found` error if all matched routes returned nothing - */ - action?: (context: ActionContext & C, params: Params) => R | Promise | void; -} - -/** - * Routes in an array of type Route. - * @template C User context that is made union with ActionContext. - * @template R Result that every action function resolves to. If the action returns a Promise, R can be the type the Promise resolves to. - */ -export type Routes = Array>; - -export interface Options { - context?: C; - baseUrl?: string; - resolveRoute?: (context: ActionContext & C, params: Params) => any; - errorHandler?: (error: Error & { status: number }, context: C) => any; -} - -/** - * @see https://github.com/kriasoft/universal-router/blob/v6.0.0/docs/api.md - */ -export default class UniversalRouter { - constructor(routes: Routes | Route, options?: Options) - /** - * Traverses the list of routes in the order they are defined until it finds the first route that matches provided URL path string - * and whose action function returns anything other than null or undefined. - */ - resolve(pathnameOrContext: string | PathnameContext): Promise; - /** - * `path-to-regexp` function - */ - static pathToRegexp: typeof pathToRegexp; -} diff --git a/types/universal-router/package.json b/types/universal-router/package.json deleted file mode 100644 index 0ab257c45a..0000000000 --- a/types/universal-router/package.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "private": true, - "dependencies": { - "path-to-regexp": "^2.2.0" - } -} diff --git a/types/universal-router/tsconfig.json b/types/universal-router/tsconfig.json deleted file mode 100644 index 8ad0ee94ef..0000000000 --- a/types/universal-router/tsconfig.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "compilerOptions": { - "module": "commonjs", - "target": "es6", - "lib": [ - "es6", - "dom" - ], - "noImplicitAny": true, - "noImplicitThis": true, - "strictNullChecks": false, - "strictFunctionTypes": true, - "baseUrl": "../", - "typeRoots": [ - "../" - ], - "types": [], - "noEmit": true, - "forceConsistentCasingInFileNames": true - }, - "files": [ - "index.d.ts", - "generateUrls.d.ts", - "universal-router-tests.ts" - ] -} diff --git a/types/universal-router/tslint.json b/types/universal-router/tslint.json deleted file mode 100644 index f93cf8562a..0000000000 --- a/types/universal-router/tslint.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "extends": "dtslint/dt.json" -} diff --git a/types/universal-router/universal-router-tests.ts b/types/universal-router/universal-router-tests.ts deleted file mode 100644 index 40b5ac32c1..0000000000 --- a/types/universal-router/universal-router-tests.ts +++ /dev/null @@ -1,74 +0,0 @@ -import UniversalRouter from "universal-router"; -import generateUrls from "universal-router/generateUrls"; - -new UniversalRouter( - { - path: '', - name: 'root', - action: (context) => context.path, - }, - { - context: { - user: 'name', - }, - baseUrl: '/base', - errorHandler: (error, context) => { - console.error(error); - console.dir(context); - return error.status === 404 - ? '

Page Not Found

' - : '

Oops! Something went wrong

'; - }, - }, -).resolve('/').then(console.log); - -new UniversalRouter({ - path: '/admin', - children: [ - { - path: '', - action: () => 'Admin Page', - }, - { - path: '/users', - children: [ - { - path: '', - action: () => 'User List', - }, - { - path: '/:username', - action: () => 'User Profile', - }, - ], - }, - ], -}).resolve({ pathname: '/admin/users/john' }) - .then(result => console.log(result)); - -new UniversalRouter({ - path: '', // optional - async action({ next }) { - console.log('middleware: start'); - const child = await next(); - console.log('middleware: end'); - return child; - }, - children: [ - { - path: '/hello', - action() { - console.log('route: return a result'); - return 'Hello, world!'; - }, - }, - ], -}); - -const url = generateUrls(new UniversalRouter([ - { name: 'users', path: '/users' }, - { name: 'user', path: '/user/:username' }, -], { baseUrl: '/base' })); - -url('users'); // => '/base/users' -url('user', { username: 'john' }); // => '/base/user/john'