# typed-path-generator

> Convert path `/user/:userID` to `({ userID: string | number }) => string`

Latest version **1.5.2** (published 2021-03-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install typed-path-generator
pnpm add typed-path-generator
yarn add typed-path-generator
bun add typed-path-generator
```

Provides the command `typed-path-generator`.

## Health

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

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.5.2 |
| Published | 2021-03-26 |
| First published | 2019-03-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 11 |
| Unpacked size | 34.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | LeetCode front-end team |
| Maintainers | runjuu, leetcode-oss |
| Keywords | route, routing, path-to-regexp, typescript, typed-path |

## Links

- npm: https://www.npmjs.com/package/typed-path-generator
- Repository: https://github.com/LeetCode-OpenSource/typed-path-generator
- Homepage: https://github.com/LeetCode-OpenSource/typed-path-generator#readme
- Issues: https://github.com/LeetCode-OpenSource/typed-path-generator/issues
- npm.io page: https://npm.io/package/typed-path-generator

## Dependencies (11)

- [qs](https://npm.io/package/qs.md) ^6.6.0
- [glob](https://npm.io/package/glob.md) ^7.1.3
- [chalk](https://npm.io/package/chalk.md) ^4.0.0
- [tslib](https://npm.io/package/tslib.md) ^2.1.0
- [lodash](https://npm.io/package/lodash.md) ^4.17.11
- [js-yaml](https://npm.io/package/js-yaml.md) ^4.0.0
- [outdent](https://npm.io/package/outdent.md) ^0.8.0
- [prettier](https://npm.io/package/prettier.md) ^2.0.1
- [commander](https://npm.io/package/commander.md) ^6.0.0
- [log-update](https://npm.io/package/log-update.md) ^4.0.0
- [path-to-regexp](https://npm.io/package/path-to-regexp.md) ^3.0.0

## Alternatives

- [express-promise-router](https://npm.io/package/express-promise-router.md) — 736.1K weekly downloads
- [next-usequerystate](https://npm.io/package/next-usequerystate.md) — 29.8K weekly downloads
- [@bitkyc08/opencodex](https://npm.io/package/@bitkyc08/opencodex.md) — 4.6K weekly downloads
- [lynkr](https://npm.io/package/lynkr.md) — 575 weekly downloads
- [baremetal.js](https://npm.io/package/baremetal.js.md) — 42 weekly downloads

## Recent versions

- 1.5.2 (latest) — 2021-03-26
- 1.4.1-beta.0 (beta) — 2019-09-02
- 1.5.1 — 2021-03-25
- 1.5.0 — 2021-03-25
- 1.4.1 — 2019-09-02
- 1.4.0 — 2019-09-02
- 1.4.0-beta.2 — 2019-09-02
- 1.4.0-beta.1 — 2019-09-02
- 1.4.0-beta.0 — 2019-09-02
- 1.3.0 — 2019-03-12
- 1.2.0 — 2019-03-11
- 1.1.1 — 2019-03-11
- 1.1.0 — 2019-03-11
- 1.0.0 — 2019-03-10

## README

<h1 align="center">🏇 typed-path-generator</h1>
<p align="center">Convert path <code>/user/:userID</code> to <code>(params: { userID: string | number }) => string</code></p>
<p align="center">
  <a href="https://github.com/LeetCode-OpenSource/typed-path-generator/blob/master/LICENSE">
    <img alt="GitHub license" src="https://img.shields.io/badge/license-MIT-blue.svg">
  </a>
  <a href="https://github.com/LeetCode-OpenSource/typed-path-generator/pulls">
    <img alt="PRs Welcome" src="https://img.shields.io/badge/PRs-welcome-brightgreen.svg">
  </a>
  <a href="https://github.com/prettier/prettier">
    <img alt="code style: prettier" src="https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat">
  </a>
  <a href="https://www.npmjs.com/package/typed-path-generator">
    <img alt="npm version" src="https://img.shields.io/npm/v/typed-path-generator.svg?style=flat">
  </a>
</p>

With [Typescript](https://typescriptlang.org/), handling [path parameters](https://github.com/pillarjs/path-to-regexp#parameters) could be very frustrating. Because there is no type checking for path parameters which is only a `string` type, we have to define it manually in an error-prone way. To free us from those work, `typed-path-generator` was created. By pre-processing the path string, `typed-path-generator` will extract the type info from path parameters and generate a well defined Typescript file.

## Quick Start

### Install

using [yarn](https://yarnpkg.com/):

```bash
yarn add typed-path-generator
```

or via [npm](https://docs.npmjs.com):

```bash
npm install typed-path-generator
```

### Config paths

`typed-path-generator` using [YAML](https://yaml.org) as configuration file. Here's an example:

```yaml
options:
  variableName:
    # Used to customize the export variables of generated file.
    # import { path, to } from './generated-file.ts'

    # Optional, default is `staticPath`
    staticPath: path
    # Optional, default is `pathFactory`
    pathFactory: to
    # Optional, default is `ParamsInterface`
    ParamsInterface: Params

paths:
  # type URL = string // any valid URL path that path-to-regexp understands. see https://github.com/pillarjs/path-to-regexp for more details.
  # interface Paths {
  #   [key: string]: URL | Paths
  # }
  user: /user/:userID
  settings:
    emails: /settings/emails
  discuss:
    list: /discuss
    detail: /discuss/:discussID
```

### Generate code

run `typed-path-generator` to generate a relative typescript file:

```bash
typed-path-generator ./your-config-file.yaml
```

furthermore, you can use **[glob patterns](<https://en.wikipedia.org/wiki/Glob_(programming)>)** to specify a group of configuration files:

```bash
typed-path-generator ./packages/**/route.yaml
```

##### Options:

```
  -V, --version          output the version number
  -P, --prettier [path]  specify the config path of Prettier
  -h, --help             output usage information
```

---
_Source: https://npm.io/package/typed-path-generator · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
