# @jswork/path-dual-parser

> Path matcher supporting both colon and brace URI template syntax.

Latest version **1.0.3** (published 2026-08-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install @jswork/path-dual-parser
pnpm add @jswork/path-dual-parser
yarn add @jswork/path-dual-parser
bun add @jswork/path-dual-parser
```

## Health

**Score 70/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; recently updated; high maintenance score; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2026-08-10 |
| First published | 2026-08-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 49.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | afeiship, yujiao.luo |
| Keywords | path, route, matcher, path-to-regexp, uri-template, dual-syntax |

## Links

- npm: https://www.npmjs.com/package/@jswork/path-dual-parser
- Homepage: https://js.work
- npm.io page: https://npm.io/package/@jswork/path-dual-parser

## Dependencies (1)

- [path-to-regexp](https://npm.io/package/path-to-regexp.md) ^8.4.2

## Alternatives

- [base64url](https://npm.io/package/base64url.md) — 6.1M weekly downloads
- [get-installed-path](https://npm.io/package/get-installed-path.md) — 502.9K weekly downloads
- [@uppy/url](https://npm.io/package/@uppy/url.md) — 185.8K weekly downloads
- [@d3fc/d3fc-shape](https://npm.io/package/@d3fc/d3fc-shape.md) — 16.2K weekly downloads
- [localizer](https://npm.io/package/localizer.md) — 226 weekly downloads

## Recent versions

- 1.0.3 (latest) — 2026-08-10
- 1.0.2 — 2026-08-06
- 1.0.1 — 2026-08-06

## README

# path-dual-parser

<p align="center">
  <img src="./assets/logo.svg" alt="path-dual-parser logo" width="800">
</p>

> Path matcher supporting both colon and brace URI template syntax.

[![version][version-image]][version-url]
[![license][license-image]][license-url]
[![download][download-image]][download-url]

## installation
```shell
pnpm add @jswork/path-dual-parser
```

## usage

### match

Match a path against a template, supports both `:param` and `{param}` syntax:

```ts
import { match } from '@jswork/path-dual-parser';

const m1 = match('/users/:id');
const m2 = match('/users/{id}');

m1('/users/123');  // { path: '/users/123', params: { id: '123' } }
m2('/users/123');  // { path: '/users/123', params: { id: '123' } }
m1('/other');      // false
```

### compile

Compile a template into a URL generator:

```ts
import { compile } from '@jswork/path-dual-parser';

const c1 = compile('/users/:id');
const c2 = compile('/users/{id}');

c1({ id: '123' });  // '/users/123'
c2({ id: '123' });  // '/users/123'
```

### parse

One-step parse template with data to URL (simpler API):

```ts
import { parse } from '@jswork/path-dual-parser';

parse('/users/:id', { id: '123' });      // '/users/123'
parse('/users/{id}', { id: '123' });     // '/users/123'
parse('/users/:userId/posts/{postId}', { userId: '1', postId: '2' });  // '/users/1/posts/2'
```

### params

Extract parameter names from a template:

```ts
import { params } from '@jswork/path-dual-parser';

params('/users/:id/posts/{postId}')  // ['id', 'postId']
params('/users')                     // []
```

### isMatch

Check whether a path matches a template (boolean result):

```ts
import { isMatch } from '@jswork/path-dual-parser';

isMatch('/users/:id', '/users/123')  // true
isMatch('/users/:id', '/posts/1')    // false
```

## license
Code released under [the MIT license](https://github.com/afeiship/path-dual-parser/blob/main/LICENSE.txt).

[version-image]: https://img.shields.io/npm/v/@jswork/path-dual-parser
[version-url]: https://npmjs.org/package/@jswork/path-dual-parser

[license-image]: https://img.shields.io/npm/l/@jswork/path-dual-parser
[license-url]: https://github.com/afeiship/path-dual-parser/blob/main/LICENSE.txt

[download-image]: https://img.shields.io/npm/dm/@jswork/path-dual-parser
[download-url]: https://www.npmjs.com/package/@jswork/path-dual-parser

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