url-template
A URI template implementation (RFC 6570 compliant)
Last updated 2 years ago by jkoops .
BSD-3-Clause · Repository · Bugs · Original npm · Tarball · package.json
$ npm install url-template 
SYNC missed versions from official npm registry.

A JavaScript URI template implementation

This is a simple URI template implementation following the RFC 6570 URI Template specification. 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:

$ npm install url-template

If you want to use it directly in a browser use a CDN like Skypack.

Example

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.

Current Tags

  • 3.1.1                                ...           latest (a year ago)

13 Versions

  • 3.1.1                                ...           a year ago
  • 3.1.0                                ...           2 years ago
  • 3.0.0                                ...           3 years ago
  • 2.0.8                                ...           8 years ago
  • 2.0.7                                ...           8 years ago
  • 2.0.6                                ...           10 years ago
  • 2.0.5                                ...           10 years ago
  • 2.0.4                                ...           11 years ago
  • 2.0.2                                ...           11 years ago
  • 2.0.1                                ...           12 years ago
  • 2.0.0                                ...           12 years ago
  • 1.1.0                                ...           12 years ago
  • 1.0.0                                ...           12 years ago
Maintainers (2)
Downloads
Total 11
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (2)

© 2010 - cnpmjs.org x YWFE | Home | YWFE