@btilford/uri-template

0.0.2 • Public • Published

title: Readme


uri-template

Javascript RFC 6570 URI templating.

Installation

npm install @btilford/uri-template

Usage

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.

Features

Variable Types

  • 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}

Other

  • Explode {something*}
  • Max Length {something:10}
  • Multiple args for all types https://app{.env,tld}

Builder

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}

Readme

Keywords

Package Sidebar

Install

npm i @btilford/uri-template

Weekly Downloads

1

Version

0.0.2

License

SEE LICENSE IN LICENSE

Unpacked Size

80 kB

Total Files

25

Last publish

Collaborators

  • btilford