uritemplate
Advanced tools
Comparing version 0.1.3 to 0.2.0
{ | ||
"name" : "uritemplate", | ||
"description" : "An UriTemplate implementation of rfc 6570", | ||
"homepage" : "https://www.github.com/fxa/uritemplate-js", | ||
"keywords" : ["util", "uri", "template", "rfc6570"], | ||
"author" : "Franz Antesberger", | ||
"contributors" : [], | ||
"dependencies" : [], | ||
"main" : "src/uritemplate.js", | ||
"licenses": [{ | ||
"type": "MIT", | ||
"url": "http://www.opensource.org/licenses/mit-license.php" | ||
}], | ||
"name": "uritemplate", | ||
"description": "An UriTemplate implementation of rfc 6570", | ||
"homepage": "https://www.github.com/fxa/uritemplate-js", | ||
"keywords": [ | ||
"util", | ||
"uri", | ||
"template", | ||
"rfc6570" | ||
], | ||
"author": "Franz Antesberger", | ||
"contributors": [], | ||
"dependencies": {}, | ||
"main": "bin/uritemplate.js", | ||
"licenses": [ | ||
{ | ||
"type": "MIT", | ||
"url": "http://www.opensource.org/licenses/mit-license.php" | ||
} | ||
], | ||
"files": [ | ||
"src/uritemplate.js", | ||
"src", | ||
"test", | ||
"bin", | ||
"Jakefile.js", | ||
"own-testcases.json", | ||
"demo.html", | ||
"test.js", | ||
"demo_AMD.html", | ||
"README.md", | ||
"reqire.js", | ||
".gitmodules", | ||
@@ -26,3 +38,11 @@ "uritemplate-test/extended-tests.json", | ||
], | ||
"version" : "0.1.3" | ||
} | ||
"version": "0.2.0", | ||
"readmeFilename": "README.md", | ||
"gitHead": "901b85201a821427dfb4591b56aea3a70d45c67c", | ||
"devDependencies": {}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/fxa/uritemplate-js.git" | ||
}, | ||
"license": "MIT" | ||
} |
@@ -25,3 +25,3 @@ URI Template JS | ||
template; | ||
template = UriTemplate.parse('{?query*}'; | ||
template = UriTemplate.parse('{?query*})'; | ||
template.expand({query: {first: 1, second: 2}}); | ||
@@ -37,20 +37,27 @@ --> "?first=1&second=2" | ||
Build | ||
----- | ||
jake clean release | ||
Tests | ||
----- | ||
The tests are taken from https://github.com/uri-templates/uritemplate-test as a submodule. | ||
Run the tests with | ||
The integration tests are taken from https://github.com/uri-templates/uritemplate-test as a submodule. | ||
The tests are integrated in the Jakefile. | ||
node test.js | ||
Comming soon | ||
------------ | ||
* A new method extract(uri), which tries to extract the variables from a given uri | ||
* Support of javascript's Date class | ||
License | ||
------- | ||
Copyright 2012 Franz Antesberger | ||
Copyright 2013 Franz Antesberger | ||
MIT License, see http://mit-license.org/ | ||
Release Notes | ||
------------- | ||
0.2.0 heavy project refactoring, splitting source files, introducing jshint (preparation of next steps) | ||
Next Steps | ||
---------- | ||
* Implementing unit tests (now only dummy test implemented) | ||
* Updating uritemplate-test (mnot added some new tests and removed some wrong. At the moment I cannot update, because the new tests will not pass) | ||
* A new method extract(uri), which tries to extract the variables from a given uri. | ||
This is harder, than you might think |
@@ -1,5 +0,5 @@ | ||
(function (exportCallback) { | ||
"use strict"; | ||
// http://blog.sangupta.com/2010/05/encodeuricomponent-and.html | ||
// | ||
@@ -35,12 +35,2 @@ // helpers | ||
} | ||
function arrayAll(array, predicate) { | ||
var index; | ||
for (index = 0; index < array.length; index += 1) { | ||
if (!predicate(array[index], index, array)) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
@@ -56,4 +46,4 @@ function reduce(arrayOrObject, callback, initialValue) { | ||
* * the empty string is defined | ||
* * an array is defined, if it contains at least one defined element | ||
* * an object is defined, if it contains at least one defined property | ||
* * an array ("list") is defined, if it contains at least one defined element | ||
* * an object ("map") is defined, if it contains at least one defined property | ||
* @param object | ||
@@ -102,6 +92,55 @@ * @return {Boolean} | ||
function isPctEncoded(chr) { | ||
return chr.length === 3 && chr.charAt(0) === '%' && isHexDigit(chr.charAt(1) && isHexDigit(chr.charAt(2))); | ||
} | ||
var pctEncoder = (function () { | ||
// see http://ecmanaut.blogspot.de/2006/07/encoding-decoding-utf8-in-javascript.html | ||
function toUtf8 (s) { | ||
return unescape(encodeURIComponent(s)); | ||
} | ||
function encode(chr) { | ||
var | ||
result = '', | ||
octets = toUtf8(chr), | ||
octet, | ||
index; | ||
for (index = 0; index < octets.length; index += 1) { | ||
octet = octets.charCodeAt(index); | ||
result += '%' + octet.toString(16).toUpperCase(); | ||
} | ||
return result; | ||
} | ||
function isPctEncoded (chr) { | ||
if (chr.length < 3) { | ||
return false; | ||
} | ||
for (var index = 0; index < chr.length; index += 3) { | ||
if (chr.charAt(index) !== '%' || !isHexDigit(chr.charAt(index + 1) || !isHexDigit(chr.charAt(index + 2)))) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
function pctCharAt(text, startIndex) { | ||
var chr = text.charAt(startIndex); | ||
if (chr !== '%') { | ||
return chr; | ||
} | ||
chr = text.substr(startIndex, 3); | ||
if (!isPctEncoded(chr)) { | ||
return '%'; | ||
} | ||
return chr; | ||
} | ||
return { | ||
encodeCharacter: encode, | ||
decodeCharacter: decodeURIComponent, | ||
isPctEncoded: isPctEncoded, | ||
pctCharAt: pctCharAt | ||
}; | ||
}()); | ||
/** | ||
@@ -113,3 +152,3 @@ * Returns if an character is an varchar character according 2.3 of rfc 6570 | ||
function isVarchar(chr) { | ||
return isAlpha(chr) || isDigit(chr) || chr === '_' || isPctEncoded(chr); | ||
return isAlpha(chr) || isDigit(chr) || chr === '_' || pctEncoder.isPctEncoded(chr); | ||
} | ||
@@ -136,6 +175,2 @@ | ||
function pctEncode(chr) { | ||
return '%' + chr.charCodeAt(0).toString(16).toUpperCase(); | ||
} | ||
function encode(text, passReserved) { | ||
@@ -145,19 +180,13 @@ var | ||
index, | ||
chr; | ||
chr = ''; | ||
if (typeof text === "number" || typeof text === "boolean") { | ||
text = text.toString(); | ||
} | ||
for (index = 0; index < text.length; index += 1) { | ||
chr = text.charAt(index); | ||
if (chr === '%') { | ||
if (isHexDigit(text.charAt(index+1)) && isHexDigit(text.charAt(index+2))) { | ||
// pass three chars to the result | ||
result += text.substr(index, 3); | ||
index += 2; | ||
} else { | ||
result += '%25'; | ||
} | ||
for (index = 0; index < text.length; index += chr.length) { | ||
chr = pctEncoder.pctCharAt(text, index); | ||
if (chr.length > 1) { | ||
result += chr; | ||
} | ||
else { | ||
result += isUnreserved(chr) || (passReserved && isReserved(chr)) ? chr : pctEncode(chr); | ||
result += isUnreserved(chr) || (passReserved && isReserved(chr)) ? chr : pctEncoder.encodeCharacter(chr); | ||
} | ||
@@ -208,3 +237,3 @@ } | ||
this.templateText = templateText; | ||
this.experssions = expressions; | ||
this.expressions = expressions; | ||
} | ||
@@ -220,4 +249,4 @@ | ||
result = ''; | ||
for (index = 0; index < this.experssions.length; index += 1) { | ||
result += this.experssions[index].expand(variables); | ||
for (index = 0; index < this.expressions.length; index += 1) { | ||
result += this.expressions[index].expand(variables); | ||
} | ||
@@ -231,16 +260,10 @@ return result; | ||
index, | ||
chr; | ||
for (index = 0; index < literal.length; index += 1) { | ||
chr = literal.charAt(index); | ||
if (chr === '%') { | ||
if (isHexDigit(literal.charAt(index + 1)) && isHexDigit(literal.charAt(index + 2))) { | ||
result += literal.substr(index, 3); | ||
index += 2; | ||
} | ||
else { | ||
throw new Error('illegal % found at position ' + index); | ||
} | ||
chr = ''; | ||
for (index = 0; index < literal.length; index += chr.length) { | ||
chr = pctEncoder.pctCharAt(literal, index); | ||
if (chr.length > 0) { | ||
result += chr; | ||
} | ||
else { | ||
result += isReserved(chr) || isUnreserved(chr) ? chr : pctEncode(chr); | ||
result += isReserved(chr) || isUnreserved(chr) ? chr : pctEncoder.encodeCharacter(chr); | ||
} | ||
@@ -395,5 +418,7 @@ } | ||
} | ||
// remove outer {} | ||
text = outerText.substr(1, outerText.length - 2); | ||
for (index = 0; index < text.length; index += chr.length) { | ||
chr = text[index]; | ||
chr = pctEncoder.pctCharAt(text, index); | ||
if (index === 0) { | ||
@@ -410,9 +435,3 @@ operator = operators.valueOf(chr); | ||
if (varnameStart !== null) { | ||
// Within varnames pct encoded values are allowed. looks strange to me. | ||
if (chr === '%') { | ||
if (index > text.length - 2 || !isDigit(text[index + 1] || !isDigit(text[index + 2]))) { | ||
throw new Error('illegal char "%" at position ' + index); | ||
} | ||
chr += text[index + 1] + text[index + 2]; | ||
} | ||
// the spec says: varname = varchar *( ["."] varchar ) | ||
@@ -497,6 +516,2 @@ // so a dot is allowed except for the first char | ||
} | ||
// TODO if (chr === ';') | ||
// In a regular URI a colon is only allowed as separator after a uri scheme (e.g. 'http:') and between host and port | ||
// (e.g. 'example.com:443'). So the only slash allowed in front of a colon is the '//' after the scheme separator | ||
// throw new Error('":" not allowed after a "/" in a regular uri'); | ||
continue; | ||
@@ -538,2 +553,7 @@ } | ||
module.exports = UriTemplate; | ||
} | ||
else if (typeof define !== "undefined") { | ||
define([],function() { | ||
return UriTemplate; | ||
}); | ||
} | ||
@@ -540,0 +560,0 @@ else if (typeof window !== "undefined") { |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
99541
30
2239
62
3
2