# url-template

> A URI template implementation (RFC 6570 compliant)

Latest version **3.1.1** (published 2023-12-13) · BSD-3-Clause license · 0 weekly downloads

## Install

```sh
npm install url-template
pnpm add url-template
yarn add url-template
bun add url-template
```

## Health

**Score 40/100 (D)** — status: abandoned.

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

Warnings: low downloads.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 3.1.1 |
| Published | 2023-12-13 |
| First published | 2012-10-31 |
| Weekly downloads | 0 |
| License | BSD-3-Clause |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | ^12.20.0 \|\| ^14.13.1 \|\| >=16.0.0 |
| Dependencies | 0 |
| Unpacked size | 7.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 194 |
| Author | Bram Stein |
| Maintainers | jkoops, bramstein |
| Keywords | uri-template, uri template, uri, url, rfc 6570, url template, url-template |

## Links

- npm: https://www.npmjs.com/package/url-template
- Repository: https://github.com/bramstein/url-template
- Homepage: https://github.com/bramstein/url-template#readme
- Issues: https://github.com/bramstein/url-template/issues
- npm.io page: https://npm.io/package/url-template

## 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

- 3.1.1 (latest) — 2023-12-13
- 3.1.0 — 2022-07-17
- 3.0.0 — 2022-01-31
- 2.0.8 — 2016-07-07
- 2.0.7 — 2016-05-30
- 2.0.6 — 2015-03-27
- 2.0.5 — 2015-03-06
- 2.0.4 — 2013-09-26
- 2.0.2 — 2013-07-01
- 2.0.1 — 2013-04-23
- 2.0.0 — 2013-04-23
- 1.1.0 — 2013-02-20
- 1.0.0 — 2012-10-31

## README

## A JavaScript URI template implementation

This is a simple URI template implementation following the [RFC 6570 URI Template specification](http://tools.ietf.org/html/rfc6570). The implementation supports all levels defined in the specification and is extensively tested.

## Installation

For use with Node.js or build tools you can install it through npm:

```sh
$ npm install url-template
```

If you want to use it directly in a browser use a CDN like [Skypack](https://www.skypack.dev/view/url-template).

## Example

```js
import { parseTemplate } from 'url-template';

const emailUrlTemplate = parseTemplate('/{email}/{folder}/{id}');
const emailUrl = emailUrlTemplate.expand({
  email: 'user@domain',
  folder: 'test',
  id: 42
});

console.log(emailUrl);
// Returns '/user@domain/test/42'
```

## A note on error handling and reporting

The RFC states that errors in the templates could optionally be handled and reported to the user. This implementation takes a slightly different approach in that it tries to do a best effort template expansion and leaves erroneous expressions in the returned URI instead of throwing errors. So for example, the incorrect expression `{unclosed` will return `{unclosed` as output. The leaves incorrect URLs to be handled by your URL library of choice.

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