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

Comparing version 0.0.3 to 0.0.4

68

index.js

@@ -5,4 +5,4 @@

/*
* @version 0.0.3
* @date 2014-01-05
* @version 0.0.4
* @date 2014-01-06
* @author Lauri Rooden - https://github.com/litejs/uri-template-lite

@@ -16,3 +16,3 @@ * @license MIT License - http://lauri.rooden.ee/mit-license.txt

var RESERVED = /[\]\[:\/?#@!$&()*+,;=']/g
, re = /\{([+#.\/;?&]?)((?:[\w%.]+(\*|:\d)?,?)+)\}/g
, RE = /\{([+#.\/;?&]?)((?:[\w%.]+(\*|:\d)?,?)+)\}/g
, JOINERS = {

@@ -27,3 +27,3 @@ '':",", '+':",", '#':"," //, ';':";"

function addLabeled(name, val, joiner) {
function addNamed(name, val, joiner) {
return name + (val || joiner == "&" ? "=" : "") + val;

@@ -37,43 +37,41 @@ }

function work(data, _, op, vals) {
var joiner = JOINERS[op] || op
, enc = op && joiner == "," ? encodeURI : encodeNormal
, fn = (joiner == ";" || joiner == "&") && addLabeled
, out = mapCleanJoin(vals.split(","), function(name){
var exp = name != (name = name.split("*")[0])
, len = !exp && (len = name.split(":"), name=len[0], len[1])
, val = data[name]
function expand(template, data) {
return template.replace(RE, function(_, op, vals) {
var joiner = JOINERS[op] || op
, enc = op && joiner == "," ? encodeURI : encodeNormal
, add = (joiner == ";" || joiner == "&") && addNamed
, out = mapCleanJoin(vals.split(","), function(name){
var exp = name != (name = name.split("*")[0])
, len = !exp && (len = name.split(":"), name=len[0], len[1])
, val = data[name]
if (val == null) return
if (val == null) return
if (typeof val == "object") {
if (Array.isArray(val)) {
val = mapCleanJoin(val, enc,
exp ? fn ? joiner + name + "=" : joiner : "," )
if (typeof val == "object") {
if (Array.isArray(val)) {
val = mapCleanJoin(val, enc,
exp ? add ? joiner + name + "=" : joiner : "," )
}
else {
len = exp ? "=" : ","
val = mapCleanJoin(Object.keys(val), function(key){
return enc(key) + len + enc(val[key])
}, exp && (joiner == "/" || add) ? joiner : "," )
if (exp) add = null
}
if (!val) return
}
else {
var list_joiner = exp ? "=" : ","
val = mapCleanJoin(Object.keys(val), function(key){
return enc(key) + list_joiner + enc(val[key])
}, exp && (joiner == "/" || fn) ? joiner : "," )
if (exp) fn = null
val = enc( len ? val.slice(0, len) : val )
}
if (!val) return
}
else {
val = enc( len ? val.slice(0, len) : val )
}
return fn ? fn(name, val, joiner) : val
}, joiner)
return add ? add(name, val, joiner) : val
}, joiner)
return out ? (op!="+"?op+out:out) : out === "" && (op=="#"||op==".") ? op : ""
}
return out ? (op!="+"?op+out:out) : out === "" && (op=="#"||op==".") ? op : ""
}
)}
function expand(template, data) {
return template.replace(re, work.bind(null, data))
}
root.expand = expand
}(this);

@@ -1,2 +0,2 @@

!function(f){function m(c){return encodeURIComponent(c).replace(n,escape)}function p(c,b,a){return c+(b||"&"==a?"=":"")+b}function l(c,b,a){c=c.map(b).filter(function(c){return"string"==typeof c});return c.length&&c.join(a)}function q(c,b,a,f){var e=r[a]||a,k=a&&","==e?encodeURI:m,g=(";"==e||"&"==e)&&p;return(b=l(f.split(","),function(a){var b=a!=(a=a.split("*")[0]),h=!b&&(h=a.split(":"),a=h[0],h[1]),d=c[a];if(null!=d){if("object"==typeof d){if(Array.isArray(d))d=l(d,k,b?g?e+a+"=":e:",");else{var f=
b?"=":",",d=l(Object.keys(d),function(a){return k(a)+f+k(d[a])},b&&("/"==e||g)?e:",");b&&(g=null)}if(!d)return}else d=k(h?d.slice(0,h):d);return g?g(a,d,e):d}},e))?"+"!=a?a+b:b:""!==b||"#"!=a&&"."!=a?"":a}var n=/[\]\[:\/?#@!$&()*+,;=']/g,s=/\{([+#.\/;?&]?)((?:[\w%.]+(\*|:\d)?,?)+)\}/g,r={"":",","+":",","#":",","?":"&"};f.expand=function(c,b){return c.replace(s,q.bind(null,b))}}(this);
!function(k){function n(a){return encodeURIComponent(a).replace(p,escape)}function q(a,f,l){return a+(f||"&"==l?"=":"")+f}function m(a,f,l){a=a.map(f).filter(function(a){return"string"==typeof a});return a.length&&a.join(l)}var p=/[\]\[:\/?#@!$&()*+,;=']/g,r=/\{([+#.\/;?&]?)((?:[\w%.]+(\*|:\d)?,?)+)\}/g,s={"":",","+":",","#":",","?":"&"};k.expand=function(a,f){return a.replace(r,function(a,b,k){var d=s[b]||b,h=b&&","==d?encodeURI:n,g=(";"==d||"&"==d)&&q;return(a=m(k.split(","),function(a){var b=a!=
(a=a.split("*")[0]),e=!b&&(e=a.split(":"),a=e[0],e[1]),c=f[a];if(null!=c){if("object"==typeof c){if(Array.isArray(c)?c=m(c,h,b?g?d+a+"=":d:","):(e=b?"=":",",c=m(Object.keys(c),function(a){return h(a)+e+h(c[a])},b&&("/"==d||g)?d:","),b&&(g=null)),!c)return}else c=h(e?c.slice(0,e):c);return g?g(a,c,d):c}},d))?"+"!=b?b+a:a:""!==a||"#"!=b&&"."!=b?"":b})}}(this);
{
"name": "uri-template-lite",
"version": "0.0.3",
"version": "0.0.4",
"license": "MIT",

@@ -5,0 +5,0 @@ "description": "URI Templates.",

@version 0.0.3
@date 2014-01-05
@version 0.0.4
@date 2014-01-06

@@ -6,0 +6,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