Commit 6f190e92 authored by fxa's avatar fxa

fix packaging for npm

parent 98e97e9a
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
"author" : "Franz Antesberger", "author" : "Franz Antesberger",
"contributors" : [], "contributors" : [],
"dependencies" : [], "dependencies" : [],
"repository" : {"type": "git", "url": "git://github.com/fxa/uritemplate-js.git"}, "repository" : {"type": "git", "url": "https://github.com/fxa/uritemplate-js.git"},
"main" : "src/uritemplate.js", "main" : "src/uritemplate.js",
"version" : "0.1.0" "version" : "0.1.0"
} }
\ No newline at end of file
...@@ -131,6 +131,9 @@ ...@@ -131,6 +131,9 @@
result = '', result = '',
index, index,
chr; chr;
if (typeof text === "number" || typeof text === "boolean") {
text = text.toString();
}
for (index = 0; index < text.length; index += 1) { for (index = 0; index < text.length; index += 1) {
chr = text.charAt(index); chr = text.charAt(index);
if (chr === '%') { if (chr === '%') {
...@@ -267,11 +270,6 @@ ...@@ -267,11 +270,6 @@
VariableExpression.prototype.toString = function () { VariableExpression.prototype.toString = function () {
return this.templateText; return this.templateText;
}; };
// makes numbers an booleans to strings (Date will follow...)
function normalizeValue(value) {
return (typeof value === 'number' || typeof value === 'boolean') ? value.toString() : value;
}
VariableExpression.prototype.expand = function expandExpression(variables) { VariableExpression.prototype.expand = function expandExpression(variables) {
var var
...@@ -292,7 +290,7 @@ ...@@ -292,7 +290,7 @@
if (!valueIsArr) { if (!valueIsArr) {
result += operator.encode(currentKey) + ','; result += operator.encode(currentKey) + ',';
} }
result += operator.encode(normalizeValue(currentValue)); result += operator.encode(currentValue);
} }
return result; return result;
} }
...@@ -303,7 +301,7 @@ ...@@ -303,7 +301,7 @@
result += operator.separator(); result += operator.separator();
} }
result += (valueIsArr) ? operator.encode(varspec.varname) : operator.encode(currentKey); result += (valueIsArr) ? operator.encode(varspec.varname) : operator.encode(currentKey);
result += '=' + operator.encode(normalizeValue(currentValue)); result += '=' + operator.encode(currentValue);
} }
return result; return result;
} }
...@@ -316,7 +314,7 @@ ...@@ -316,7 +314,7 @@
if (!valueIsArr) { if (!valueIsArr) {
result += operator.encode(currentKey) + '='; result += operator.encode(currentKey) + '=';
} }
result += operator.encode(normalizeValue(currentValue)); result += operator.encode(currentValue);
} }
return result; return result;
} }
...@@ -324,7 +322,7 @@ ...@@ -324,7 +322,7 @@
// expand each varspec and join with operator's separator // expand each varspec and join with operator's separator
for (index = 0; index < this.varspecs.length; index += 1) { for (index = 0; index < this.varspecs.length; index += 1) {
varspec = this.varspecs[index]; varspec = this.varspecs[index];
value = normalizeValue(variables[varspec.varname]); value = variables[varspec.varname];
if (!isDefined(value)) { if (!isDefined(value)) {
continue; continue;
} }
...@@ -336,12 +334,12 @@ ...@@ -336,12 +334,12 @@
result += this.operator.separator(); result += this.operator.separator();
} }
valueIsArr = isArray(value); valueIsArr = isArray(value);
if (typeof value === 'string') { if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
value = value.toString();
if (this.operator.named()) { if (this.operator.named()) {
result += varspec.varname; result += varspec.varname;
if (value === '') { if (value === '') {
result += this.operator.ifEmpty(); result += this.operator.ifEmpty();
// "and skip to the next varspec" (appendix A of the rfc)
continue; continue;
} }
else { else {
...@@ -362,7 +360,6 @@ ...@@ -362,7 +360,6 @@
result += varspec.varname; result += varspec.varname;
if (!isDefined(value)) { if (!isDefined(value)) {
result += this.operator.ifEmpty(); result += this.operator.ifEmpty();
// "and skip to the next varspec" (appendix a of the rfc
continue; continue;
} }
else { else {
...@@ -541,10 +538,10 @@ ...@@ -541,10 +538,10 @@
}(function (UriTemplate) { }(function (UriTemplate) {
"use strict"; "use strict";
// export UriTemplate, when module is present, or pass it to window or global // export UriTemplate, when module is present, or pass it to window or global
if (typeof(module) !== "undefined") { if (typeof module !== "undefined") {
module.exports = UriTemplate; module.exports = UriTemplate;
} }
else if (typeof(window) !== "undefined") { else if (typeof window !== "undefined") {
window.UriTemplate = UriTemplate; window.UriTemplate = UriTemplate;
} }
else { else {
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
var var
assert = require('assert'), assert = require('assert'),
fs = require('fs'), fs = require('fs'),
UriTemplate = require('./src/uri-template.js'), UriTemplate = require('./src/uritemplate.js'),
numTestsPassed = 0; numTestsPassed = 0;
function assertMatches(template, variables, expected, chapterName) { function assertMatches(template, variables, expected, chapterName) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment