Socket
Socket
Sign inDemoInstall

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 - npm Package Compare versions

Comparing version 22.9.0 to 23.4.0

55

index.js

@@ -0,15 +1,13 @@

/* global escape */
/*! litejs.com/MIT-LICENSE.txt */
/**
* @version 20.5.0
* @author Lauri Rooden <lauri@rooden.ee>
* @license MIT License
*/
!function() {
"use strict";
module.exports = Template
module.exports.expand = expand
!function(URI) {
"use strict";
/**

@@ -27,9 +25,13 @@ * URI Template

URI.encoder = encodeURIComponent
URI.decoder = decodeURIComponent
/*** EXPAND ***/
function encodeNormal(val) {
return URI.encoder(val).replace(RESERVED, escape)
return encodeURIComponent(val).replace(RESERVED, escape)
}
function catchDecode(str) {
try {
return decodeURIComponent(str)
} catch(e) {
return str
}
}

@@ -45,7 +47,7 @@ function notNull(s) {

function expand(template, data) {
function expand(template, data, opts) {
return template.replace(expandRe, function(_, op, vals) {
var sep = SEPARATORS[op] || op
, named = sep == ";" || sep == "&"
, enc = op && sep == "," ? encodeURI : encodeNormal
, enc = op && sep == "," ? encodeURI : opts && opts.encoder || encodeNormal
, out = mapCleanJoin(vals.split(","), function(_name) {

@@ -84,9 +86,9 @@ var mod = _name.split(/[*:]/)

URI.expand = expand
/**/
URI.Template = function Template(template) {
function Template(template, opts_) {
var self = this
//if (!(self instanceof Template)) return new Template(template)
/*** PARSE ***/
, opts = Object.assign({
decoder: catchDecode
}, opts_)
, pos = 0

@@ -110,3 +112,3 @@ , lengths = {}

}
fnStr += "t=($[" + pos + "]||'').split('" + (mod ? named ? sep + name + "=" : sep : ",") + "').map(d);"
fnStr += "t=($[" + pos + "]||'').split('" + (mod[1] ? named ? sep + name + "=" : sep : ",") + "').map(d);"
fnStr += "o[\"" + name + "\"]=" + (mod[1] === "" ? "t;" : "t.length>1?t:t[0];")

@@ -116,4 +118,4 @@ re = escapeRegExp(i === 0 ? op === "+" ? "" : op : sep) + (

escapeRegExp(name) + "(?:=" + re + ")?" :
sep == "&" ?
escapeRegExp(name + "=") + re :
//sep == "&" ?
//escapeRegExp(name + "=") + re :
re

@@ -130,3 +132,3 @@ )

var match = re.exec(uri)
return match && fn(match, URI.decoder)
return match && fn(match, opts.decoder)
}

@@ -137,10 +139,9 @@

}
/**/
/*** EXPAND ***/
self.expand = expand.bind(self, template)
/**/
self.expand = function(data) {
return expand(template, data, opts)
}
}
// `this` is `exports` in NodeJS and `window` in browser.
}(this.URI || (this.URI = {})); // jshint ignore:line
}(); // jshint ignore:line
{
"name": "uri-template-lite",
"version": "22.9.0",
"version": "23.4.0",
"license": "MIT",

@@ -17,17 +17,17 @@ "author": "Lauri Rooden <lauri@rooden.ee>",

"files": [],
"bugs": "https://github.com/litejs/uri-template-lite/issues",
"repository": "git://github.com/litejs/uri-template-lite.git",
"scripts": {
"test": "lj test"
"test": "lj test --coverage --brief test/index.js && jshint *.js",
"test-fast": "lj test --brief test/index.js"
},
"repository": "github:litejs/uri-template-lite",
"devDependencies": {
"@litejs/cli": "21.11.0"
"@litejs/cli": "23.4.3",
"jshint": "2.13.6"
},
"litejs": {
"build": false,
"lint": [
"jshint *.js"
]
"global": false
},
"jshintConfig": {
"esversion": 5,
"asi": true,

@@ -37,4 +37,9 @@ "evil": true,

"maxdepth": 6,
"node": true,
"nonbsp": true,
"undef": true,
"unused": true,
"shadow": "outer",
"quotmark": "double"
}
}

@@ -17,15 +17,19 @@

Usage
-----
`npm install uri-template-lite`
```javascript
var UriTemplate = require("uri-template-lite")
// Call `expand` directly
var data = {"domain":"example.com", "user":"fred", "query":"mycelium"}
URI.expand("http://{domain}/~{user}/foo{?query,number}", data)
UriTemplate.expand("http://{domain}/~{user}/foo{?query,number}", data)
// Returns http://example.com/~fred/foo?query=mycelium
// ..or use `Template` constructor
var data = {"domain":"example.com", "user":"fred", "query":"mycelium", "number": 3}
var template = new URI.Template("http://{domain}/~{user}/foo{?query,number}")
template.expand(data)
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

@@ -42,18 +46,3 @@

Installation
------------
To use it in the browser, include uri-template.js in your site
```html
<script src=uri-template.js></script>
```
In node.js: `npm install uri-template-lite`
```javascript
var URI = require("uri-template-lite").URI
```
About error handling

@@ -88,5 +77,4 @@ --------------------

[Tests](https://github.com/uri-templates/uritemplate-test) |
[Travis CI](https://travis-ci.org/litejs/uri-template-lite) |
[Coveralls coverage](https://coveralls.io/github/litejs/uri-template-lite) |
[Buy Me A Tea][8]
[Coveralls coverage][2]
[Buy Me A Tea][6]

@@ -96,3 +84,3 @@

Copyright (c) 2014-2019 Lauri Rooden &lt;lauri@rooden.ee&gt;
Copyright (c) 2014-2022 Lauri Rooden &lt;lauri@rooden.ee&gt;
[The MIT License](http://lauri.rooden.ee/mit-license.txt)

@@ -99,0 +87,0 @@

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