uri-template-lite
Advanced tools
Comparing version 0.0.5 to 0.1.0
30
index.js
@@ -5,6 +5,7 @@ | ||
/* | ||
* @version 0.0.5 | ||
* @date 2014-01-06 | ||
* @author Lauri Rooden - https://github.com/litejs/uri-template-lite | ||
* @license MIT License - http://lauri.rooden.ee/mit-license.txt | ||
* @version 0.1.0 | ||
* @date 2014-01-07 | ||
* @stability 2 - Unstable | ||
* @author Lauri Rooden <lauri@rooden.ee> | ||
* @license MIT License | ||
*/ | ||
@@ -14,3 +15,3 @@ | ||
!function(root) { | ||
!function(URI) { | ||
var RESERVED = /[\]\[:\/?#@!$&()*+,;=']/g | ||
@@ -24,3 +25,6 @@ , RE = /\{([+#.\/;?&]?)((?:[\w%.]+(\*|:\d)?,?)+)\}/g | ||
function encodeNormal(val) { | ||
return encodeURIComponent(val).replace(RESERVED, escape ); | ||
return encodeURIComponent(val).replace(RESERVED, function(s) { | ||
// Do not apply a non-standard second argument for escape in FF3-4. | ||
return escape(s) | ||
}); | ||
} | ||
@@ -42,3 +46,3 @@ | ||
, add = (joiner == ";" || joiner == "&") && addNamed | ||
, out = mapCleanJoin(vals.split(","), function(name){ | ||
, out = mapCleanJoin(vals.split(","), function(name) { | ||
var exp = name != (name = name.split("*")[0]) | ||
@@ -52,10 +56,9 @@ , len = !exp && (len = name.split(":"), name=len[0], len[1]) | ||
if (Array.isArray(val)) { | ||
val = mapCleanJoin(val, enc, | ||
exp ? add ? joiner + name + "=" : joiner : "," ) | ||
val = mapCleanJoin(val, enc, exp ? add ? joiner + name + "=" : joiner : "," ) | ||
} | ||
else { | ||
len = exp ? "=" : "," | ||
val = mapCleanJoin(Object.keys(val), function(key){ | ||
val = mapCleanJoin(Object.keys(val), function(key) { | ||
return enc(key) + len + enc(val[key]) | ||
}, exp && (joiner == "/" || add) ? joiner : "," ) | ||
}, exp && (add || joiner == "/") ? joiner : "," ) | ||
if (exp) add = null | ||
@@ -76,4 +79,5 @@ } | ||
root.expand = expand | ||
}(this); | ||
URI.expand = expand | ||
// `this` is `exports` in NodeJS and `window` in browser. | ||
}(this.URI || (this.URI = {})); | ||
{ | ||
"name": "uri-template-lite", | ||
"version": "0.0.5", | ||
"version": "0.1.0", | ||
"stability": 2, | ||
"license": "MIT", | ||
"description": "URI Templates.", | ||
"author": "Lauri Rooden <lauri@rooden.ee>", | ||
"description": "URI Template [RFC 6570] implementation in less than 1kb", | ||
"keywords": [ | ||
"uri", | ||
"template", | ||
"litejs" | ||
], | ||
"main": "index.js", | ||
"author": "Lauri Rooden <lauri@rooden.ee>", | ||
"readmeFilename": "README.md", | ||
"scripts": { | ||
"build": "node node_modules/buildman/index.js --all", | ||
"travis-test": "istanbul cover ./tests/run.js && (coveralls < coverage/lcov.info || exit 0)", | ||
"test": "node tests/run.js" | ||
}, | ||
"repository": { | ||
@@ -15,13 +27,2 @@ "type": "git", | ||
}, | ||
"scripts": { | ||
"build": "node node_modules/buildman/index.js --all", | ||
"travis-test": "istanbul cover ./tests/run.js && (coveralls < coverage/lcov.info || exit 0)", | ||
"test": "node tests/run.js" | ||
}, | ||
"keywords": [ | ||
"uri", | ||
"template", | ||
"litejs" | ||
], | ||
"readmeFilename": "README.md", | ||
"devDependencies": { | ||
@@ -33,3 +34,3 @@ "buildman": "*", | ||
"buildman": { | ||
"min.js": "index.js" | ||
"uri-template-min.js": "index.js" | ||
}, | ||
@@ -36,0 +37,0 @@ "testling": { |
@@ -7,15 +7,50 @@ [1]: https://secure.travis-ci.org/litejs/uri-template-lite.png | ||
[8]: https://ci.testling.com/litejs/uri-template-lite | ||
[rfc-6570]: http://tools.ietf.org/html/rfc6570 | ||
@version 0.0.5 | ||
@date 2014-01-06 | ||
@version 0.1.0 | ||
@date 2014-01-07 | ||
@stability 2 - Unstable | ||
uri-template – [![Build][1]][2] [![Coverage][3]][4] | ||
URI Template – [![Build][1]][2] [![Coverage][3]][4] | ||
============ | ||
URI Template [RFC 6570][rfc-6570] implementation in less than 1kb. | ||
http://tools.ietf.org/html/rfc6570 | ||
### Installation | ||
- To use it in the browser, include uri-template-min.js in your site | ||
```html | ||
<script src=uri-template-min.js></script> | ||
``` | ||
- In node.js: `npm install uri-template-lite` | ||
```javascript | ||
var URI = require("uri-template-lite").URI | ||
``` | ||
### Usage | ||
```javascript | ||
var data = {"domain":"example.com", "user":"fred", "query":"mycelium"} | ||
URI.expand("http://{domain}/~{user}/foo{?query,number}", data) | ||
// http://example.com/~fred/foo?query=mycelium | ||
``` | ||
### 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 | ||
@@ -25,1 +60,3 @@ | ||
- For IE6-9 it requires `browser-upgrade-lite` module or other ES5 shim. | ||
@@ -5,3 +5,3 @@ | ||
var uri = require("../").expand | ||
var URI = require("../").URI | ||
@@ -19,3 +19,3 @@ var test = require("testman") | ||
for (;i<len;i++) { | ||
var res = uri(arr[i][0], args) | ||
var res = URI.expand(arr[i][0], args) | ||
if (Array.isArray(arr[i][1])) { | ||
@@ -38,4 +38,3 @@ test = test.ok(function(){ | ||
test.done() | ||
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
49236
916
61