# @djess-v/router

> Simple JS router

Latest version **1.0.5** (published 2023-06-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install @djess-v/router
pnpm add @djess-v/router
yarn add @djess-v/router
bun add @djess-v/router
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.5 |
| Published | 2023-06-29 |
| First published | 2023-06-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 15.8 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Djess-V |
| Maintainers | djess-v |

## Links

- npm: https://www.npmjs.com/package/@djess-v/router
- Repository: https://github.com/Djess-V/otus--homework--18
- Homepage: https://github.com/Djess-V/otus--homework--18#readme
- Issues: https://github.com/Djess-V/otus--homework--18/issues
- npm.io page: https://npm.io/package/@djess-v/router

## Dependencies (1)

- [uuid](https://npm.io/package/uuid.md) ^9.0.0

## Recent versions

- 1.0.5 (latest) — 2023-06-29
- 1.0.4 — 2023-06-29
- 1.0.3 — 2023-06-29
- 1.0.2 — 2023-06-27
- 1.0.1 — 2023-06-26
- 1.0.0 — 2023-06-19

## README

<h1 align="center">Библиотека клиентского роутинга</h1>

<p align="center">
<img alt="Badge" src="https://github.com/djess-v/otus--homework--18/actions/workflows/sanity-check.yml/badge.svg" />
</p>

## Getting Started

Install @djess-v/router using [`npm`](https://www.npmjs.com/package/@djess-v/router):

```bash
npm install @djess-v/router
```

Typing

```bash
export interface IArgs {
    currentPath: string;
    previousPath: string | null;
    state: Record<string, any>;
}
export type IState = Record<string, any>;
export type IMatch = RegExp | string | ((path: string) => boolean);
export type IHook = (...args: IArgs[]) => Promise<any> | any;
export interface IHooks {
    onEnter?: IHook;
    onLeave?: IHook;
    onBeforeEnter?: IHook;
}
export interface IListener {
    id: string;
    match: IMatch;
    hooks: IHooks;
}
export interface IRouter {
    on: (match: IMatch, hooks?: IHooks) => () => void;
    go: (url: string, state: IState) => void;
    unsubscribeAll: () => void;
}
declare class Router implements IRouter {
    private listeners;
    private previousPath;
    private currentPath;
    private mode;
    constructor(mode?: "history" | "hash");
    static isMatch: (match: IMatch, path: string) => boolean;
    static getQueryParams: () => IState;
    private init;
    unsubscribeAll: () => void;
    private getPath;
    private handleListener;
    private handleAllListeners;
    on: (match: IMatch, hooks?: IHooks) => (() => void);
    go: (url: string, state?: IState) => void;
    private handleClick;
    private bindHandleClick;
    private handlePopState;
    private bindHandlePopState;
    private handleHashChange;
    private bindHandleHashChange;
}
```

Using

```bash
const router = new Router();

router.on("/", {
  onEnter: () => {
    // your code
  },
  // other hooks
});
```

## License

@djess-v/router is [MIT licensed](./LICENSE).

---
_Source: https://npm.io/package/@djess-v/router · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
