Socket
Socket
Sign inDemoInstall

uri-templates

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

uri-templates

URI Templates (RFC6570) including de-substitution


Version published
Weekly downloads
637K
decreased by-25.54%
Maintainers
1
Weekly downloads
 
Created

What is uri-templates?

The 'uri-templates' npm package allows you to parse and expand URI templates as defined by RFC 6570. It provides a simple and efficient way to handle URI templates, making it easier to work with dynamic URLs in your applications.

What are uri-templates's main functionalities?

Parsing URI Templates

This feature allows you to parse a URI template and extract variables from a given URI. In the example, the template '/{username}/repos' is used to parse the URI '/john/repos', extracting the variable 'username' with the value 'john'.

const UriTemplate = require('uri-templates');
const template = UriTemplate('/{username}/repos');
const parsed = template.fromUri('/john/repos');
console.log(parsed); // { username: 'john' }

Expanding URI Templates

This feature allows you to expand a URI template by providing values for the variables. In the example, the template '/{username}/repos' is expanded with the value 'john' for the variable 'username', resulting in the URI '/john/repos'.

const UriTemplate = require('uri-templates');
const template = UriTemplate('/{username}/repos');
const expanded = template.fill({ username: 'john' });
console.log(expanded); // '/john/repos'

Handling Complex Templates

This feature allows you to handle more complex URI templates with query parameters. In the example, the template '/search{?q,lang}' is expanded with the values 'nodejs' for 'q' and 'en' for 'lang', resulting in the URI '/search?q=nodejs&lang=en'.

const UriTemplate = require('uri-templates');
const template = UriTemplate('/search{?q,lang}');
const expanded = template.fill({ q: 'nodejs', lang: 'en' });
console.log(expanded); // '/search?q=nodejs&lang=en'

Other packages similar to uri-templates

Keywords

FAQs

Package last updated on 29 May 2016

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