title |
---|
Readme |
Javascript RFC 6570 URI templating.
npm install @btilford/uri-template
const { UriTemplate } = require('@btilford/uri-template');
const template = UriTemplate.parse('https://github.com/btilford/js-uri-template/tree/{/branch}');
const url = template.expand({branch:'master'}).format();
// https://github.com/btilford/js-uri-template/tree/master
See usage for more examples.
- simple variables
{anything}
- label variables
{.hostname}
- fragment variables
{#anchor}
- path segment variables
{/name}
- path style parameter variables
{;myvar}
- query variables
{?offset}
- query continuation variables
{&limit}
- reserved string variables
{+var}
- Explode
{something*}
- Max Length
{something:10}
- Multiple args for all types
https://app{.env,tld}
There is also a template builder available to build template strings.
const { UriTemplateBuilder } = require('@btilford/uri-template');
const templateString = UriTemplateBuilder.from('https://github.com/btilford/js-uri-template/blob')
.path('branch', 'file')
.format();
// https://github.com/btilford/js-uri-template/blob{/branch,file}