url-template

3.1.1last stable release 1 year ago
Complexity Score
Low
Open Issues
0
Dependent Projects
148
Weekly Downloadsglobal
3,279,949

License

  • BSD-3-Clause
    • Yesattribution
    • Permissivelinking
    • Permissivedistribution
    • Permissivemodification
    • Nopatent grant
    • Yesprivate use
    • Permissivesublicensing
    • Notrademark grant

Downloads

Readme

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.

Dependencies

Loading dependencies...

CVE IssuesActive
0
Scorecards Score
3.60
Test Coverage
No Data
Follows Semver
Yes
Github Stars
180
Dependenciestotal
2
DependenciesOutdated
0
DependenciesDeprecated
0
Threat Modelling
No
Repo Audits
No

Learn how to distribute url-template in your own private NPM registry

npm config set registry  https://npm.cloudsmith.com/owner/repo
Processing...
Done
npm install url-template
Processing...
Done

13 Releases

NPM on Cloudsmith

Getting started with NPM on Cloudsmith is fast and easy.