Skip to content

Commit

Permalink
Adding Types Support (#2)
Browse files Browse the repository at this point in the history
* now has types support

* json update

Co-authored-by: Victor Kuria <victorkushmere@gmail.com>
  • Loading branch information
mvc-k and Victor Kuria committed Sep 14, 2022
1 parent 32bf47d commit 564609b
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 17 deletions.
36 changes: 19 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"name": "hookrouter",
"version": "1.2.3",
"version": "1.2.4",
"description": "A hook based router for React",
"main": "dist/index.js",
"types": "types/index.d.ts",
"scripts": {
"test": "jest unittest/",
"prepublishOnly": "cross-env NODE_ENV=production babel ./src --out-dir ./dist -s inline",
Expand All @@ -12,10 +13,11 @@
},
"repository": {
"type": "git",
"url": "git+ssh://git@github.com/Paratron/hookrouter.git"
"url": "git+ssh://git@github.com/victorkur/hookrouter.git"
},
"files": [
"dist/*"
"dist/*",
"types/*.d.ts"
],
"author": "Christian Engel <christian.engel@wearekiss.com>",
"license": "ISC",
Expand All @@ -24,21 +26,21 @@
},
"homepage": "https://github.com/Paratron/hookrouter#readme",
"peerDependencies": {
"react": "^16.8.0 || ^17.0.0"
"react": "^17.0.2"
},
"devDependencies": {
"@babel/cli": "^7.2.3",
"@babel/core": "^7.2.2",
"@babel/preset-env": "^7.3.1",
"@babel/preset-react": "^7.0.0",
"cross-env": "5.2.0",
"http-server": "0.11.1",
"jest": "24.6.0",
"node": "11.12.0",
"react": "^16.8.2",
"react-dom": "^16.8.5",
"react-test-renderer": "^16.8.5",
"webpack": "4.29.6",
"webpack-cli": "3.3.0"
"@babel/cli": "^7.14.8",
"@babel/core": "^7.14.8",
"@babel/preset-env": "^7.14.8",
"@babel/preset-react": "^7.14.5",
"cross-env": "^7.0.3",
"http-server": "^0.12.3",
"jest": "^27.0.6",
"node": "^16.5.0",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-test-renderer": "^17.0.2",
"webpack": "^5.45.1",
"webpack-cli": "^4.7.2"
}
}
21 changes: 21 additions & 0 deletions types/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) Microsoft Corporation.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE
63 changes: 63 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Type definitions for hookrouter 2.2
// Project: https://github.com/Paratron/hookrouter
// Definitions by: Mete Can Eris <https://github.com/mcaneris>
// Sam Calvert <https://github.com/sam-outschool>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 3.4
import * as React from 'react';
export namespace HookRouter {
type InterceptedPath = string | null;
interface AProps extends React.AnchorHTMLAttributes<HTMLAnchorElement> {
href: string;
}
interface QueryParams {
[key: string]: any;
}
interface RouteObject<T = any> {
[key: string]: (params: QueryParams) => T;
}
}
export function setLinkProps(props: HookRouter.AProps): HookRouter.AProps;
export function A(props: HookRouter.AProps): React.ReactHTMLElement<HTMLAnchorElement>;
export function confirmNavigation(): void;
export function resetPath(): void;
export function stopInterception(): void;
export function useControlledInterceptor(): [
HookRouter.InterceptedPath,
typeof confirmNavigation,
typeof resetPath,
typeof stopInterception,
];
export function interceptRoute(previousRoute: string, nextRoute: string): string[];
export function get(componentId: number): HookRouter.RouteObject | null;
export function remove(componentId: number): void;
export function useInterceptor(handlerFn: (currentPath: string, nextPath: string) => string): () => typeof remove;
export function setQueryParams(inObj: HookRouter.QueryParams, replace?: boolean): void;
export function getQueryParams(): HookRouter.QueryParams;
export function queryStringToObject(inStr: string): HookRouter.QueryParams;
export function objectToQueryString(inObj: HookRouter.QueryParams): string;
export function useQueryParams(): [HookRouter.QueryParams, typeof setQueryParams];
export function useRedirect(
fromURL: string,
toURL: string,
queryParams?: HookRouter.QueryParams | null,
replace?: boolean,
): void;
export function setBasepath(inBasepath: string): void;
export function getBasepath(): string;
export function resolvePath(inPath: string): string;
export function prepareRoute(inRoute: string): [RegExp, string[]];
export function navigate(
url: string,
replace?: boolean,
queryParams?: HookRouter.QueryParams | null,
replaceQueryParams?: boolean,
): void;
export function setPath(inPath: string): void;
export function getPath(): string;
export function usePath(active?: boolean, withBasePath?: boolean): string;
export function updatePathHooks(): void;
export function getWorkingPath(parentRouterId: string): string;
export function useRoutes<T = any>(routeObj: HookRouter.RouteObject<T>): T | null;
export function useTitle(inString: string): void;
export function getTitle(): string;
32 changes: 32 additions & 0 deletions types/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "@types/hookrouter",
"version": "2.2.5",
"description": "TypeScript definitions for hookrouter",
"license": "MIT",
"contributors": [
{
"name": "Mete Can Eris",
"url": "https://github.com/mcaneris",
"githubUsername": "mcaneris"
},
{
"name": "Sam Calvert",
"url": "https://github.com/sam-outschool",
"githubUsername": "sam-outschool"
}
],
"main": "",
"types": "index.d.ts",
"repository": {
"type": "git",
"url": "https://github.com/DefinitelyTyped/DefinitelyTyped.git",
"directory": "types/hookrouter"
},
"scripts": {},
"dependencies": {
"@types/react": "*",
"csstype": "^3.0.2"
},
"typesPublisherContentHash": "fccdd1b29e9c9035d59fd99b4e8190af85cc633a4c7fb5862ddfbbe52cc535c8",
"typeScriptVersion": "3.4"
}

0 comments on commit 564609b

Please sign in to comment.