Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

uri-templates-es

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

uri-templates-es

URI Templates (RFC6570) including de-substitution

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
515
increased by15.73%
Maintainers
1
Weekly downloads
 
Created
Source

UriTemplatesEs

Last release version   Pipeline info   Total open issues   Total downloads by npm   License info  

This is a ported library version built to support es standard.

Can find original library here.

URI Templates (RFC6570) in JavaScript, including de-substitution.

It is tested against the official test suite, including the extended tests (more that 300 tests).

The 'de-substitution' extracts parameter values from URIs. It is also tested against the official test suite (including extended tests).

Usages

Install library using the next command:

npm i uri-templates-es --save

Create a template object:

import { UriTemplate } from 'uri-templates-es';

const template1 = new UriTemplate('/date/{colour}/{shape}/');
const template2 = new UriTemplate('/prefix/{?params*}');

Example of substitution using an object:

// '/categories/green/round/'
const uri1 = template1.fill({colour: 'green', shape: 'round'});

// '/prefix/?a=A&b=B&c=C
const uri2 = template2.fillFromObject({
	params: {a: 'A', b: 'B', c: 'C'}
});

Example of substitution using a callback:

// '/categories/example_colour/example_shape/'
const uri1b = template1.fill(function (varName) {
	return 'example_' + varName;
});

Example of guess variables from URI ('de-substitution'):

const uri2b = '/prefix/?beep=boop&bleep=bloop';
const params = template2.fromUri(uri2b);
/*
{
  params: {
    beep: 'boop',
    bleep: 'bloop'
    
  }
*/

While templates can be ambiguous (e.g. '{var1}{var2}'), it will still produce something that reconstructs into the original URI.

It can handle all the cases in the official test suite, including the extended tests:

const template = new UriTemplate('{/id*}{?fields,token}');

const values = template.fromUri('/person/albums?fields=id,name,picture&token=12345');
/*
{
  id: ['person', 'albums'],
  fields: ['id', 'name', 'picture'],
  token: '12345'
}
*/

Keywords

FAQs

Package last updated on 30 Oct 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc