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

uri-template-lite

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

uri-template-lite

URI Template [RFC 6570] expansion and extraction

  • 23.4.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

URI Template Lite – Coverage size Buy Me A Tea

URI Template RFC 6570 expansion and extraction.

Usage

npm install uri-template-lite

var UriTemplate = require("uri-template-lite")

// Call `expand` directly
var data = {"domain":"example.com", "user":"fred", "query":"mycelium"}
UriTemplate.expand("http://{domain}/~{user}/foo{?query,number}", data)
// Returns http://example.com/~fred/foo?query=mycelium

// ..or use `Template` constructor
var template = new UriTemplate("http://{domain}/~{user}/foo{?query,number}")
template.expand({"domain":"example.com", "user":"fred", "query":"mycelium", "number": 3})
// Returns http://example.com/~fred/foo?query=mycelium&number=3

// Extract variables
template.match("http://example.com/~fred/foo?query=mycelium&number=3")
// Returns {"domain":"example.com", "user":"fred", "query":"mycelium", "number": "3"}

template.match("http://other.com/?query=mycelium")
// Returns null

About error handling

This implementation 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.

Browser Support

It should work IE6 and up but automated testing is currently broken.

  • For older browsers it requires browser-upgrade-lite package or other ES5 polyfill.
  • FF3-4 escape should be patched to remove non-standard 2nd param, browser-upgrade-lite does that.

GitHub repo | npm package | URI Template RFC 6570 and Tests | Coveralls coverage
Buy Me A Tea

Licence

Copyright (c) 2014-2022 Lauri Rooden <lauri@rooden.ee>
The MIT License

Keywords

FAQs

Package last updated on 25 Apr 2023

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