Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
U
uritemplate-js
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Jérome Perrin
uritemplate-js
Commits
19aa9f17
Commit
19aa9f17
authored
May 18, 2013
by
fxa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed
https://github.com/fxa/uritemplate-js/issues/11
(Problems in older IEs. Thanks to anozaki!)
parent
819db320
Changes
11
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
83 additions
and
18 deletions
+83
-18
README.md
README.md
+1
-0
bin/uritemplate-min.js
bin/uritemplate-min.js
+1
-1
bin/uritemplate.js
bin/uritemplate.js
+23
-6
demo.html
demo.html
+4
-3
package.json
package.json
+1
-1
src/VariableExpression.js
src/VariableExpression.js
+6
-3
src/objectHelper.js
src/objectHelper.js
+15
-0
src/pctEncoder.js
src/pctEncoder.js
+2
-2
src/pre.txt
src/pre.txt
+0
-1
test/integration/testRfcSamples.js
test/integration/testRfcSamples.js
+1
-1
test/unit/testVariableExpression.js
test/unit/testVariableExpression.js
+29
-0
No files found.
README.md
View file @
19aa9f17
...
...
@@ -62,6 +62,7 @@ MIT License, see http://mit-license.org/
Release Notes
-------------
*
0.3.2 fixed https://github.com/fxa/uritemplate-js/issues/11 Problems with older IE versions. Thanks to anozaki!
*
0.3.1 fixed https://github.com/fxa/uritemplate-js/issues/10 thank you, Paul-Martin!
*
0.3.0 introduced UriTemplateError as exception, so the interface changed from string to UriTemplateError (as the rfc suggested)
*
0.2.4 fixed double encoding according [RubenVerborgh] and some Prefix modifiers bugs
...
...
bin/uritemplate-min.js
View file @
19aa9f17
This diff is collapsed.
Click to expand it.
bin/uritemplate.js
View file @
19aa9f17
/*jshint */
/*global unescape, module, define, window, global*/
/*
...
...
@@ -32,6 +31,18 @@ var objectHelper = (function () {
return
Object
.
prototype
.
toString
.
apply
(
value
)
===
'
[object Array]
'
;
}
function
isString
(
value
)
{
return
Object
.
prototype
.
toString
.
apply
(
value
)
===
'
[object String]
'
;
}
function
isNumber
(
value
)
{
return
Object
.
prototype
.
toString
.
apply
(
value
)
===
'
[object Number]
'
;
}
function
isBoolean
(
value
)
{
return
Object
.
prototype
.
toString
.
apply
(
value
)
===
'
[object Boolean]
'
;
}
function
join
(
arr
,
separator
)
{
var
result
=
''
,
...
...
@@ -99,6 +110,9 @@ var objectHelper = (function () {
return
{
isArray
:
isArray
,
isString
:
isString
,
isNumber
:
isNumber
,
isBoolean
:
isBoolean
,
join
:
join
,
map
:
map
,
filter
:
filter
,
...
...
@@ -179,7 +193,7 @@ var pctEncoder = (function () {
* @return {boolean|*|*}
*/
function
isPercentDigitDigit
(
text
,
start
)
{
return
text
[
start
]
===
'
%
'
&&
charHelper
.
isHexDigit
(
text
[
start
+
1
])
&&
charHelper
.
isHexDigit
(
text
[
start
+
2
]
);
return
text
.
charAt
(
start
)
===
'
%
'
&&
charHelper
.
isHexDigit
(
text
.
charAt
(
start
+
1
))
&&
charHelper
.
isHexDigit
(
text
.
charAt
(
start
+
2
)
);
}
/**
...
...
@@ -221,7 +235,7 @@ var pctEncoder = (function () {
* @return the character or pct-string of the text at startIndex
*/
function
pctCharAt
(
text
,
startIndex
)
{
var
chr
=
text
[
startIndex
]
;
var
chr
=
text
.
charAt
(
startIndex
)
;
if
(
!
isPercentDigitDigit
(
text
,
startIndex
))
{
return
chr
;
}
...
...
@@ -609,15 +623,18 @@ var parse = (function () {
var
VariableExpression
=
(
function
()
{
// helper function if JSON is not available
function
prettyPrint
(
value
)
{
return
JSON
?
JSON
.
stringify
(
value
)
:
value
;
return
(
JSON
&&
JSON
.
stringify
)
?
JSON
.
stringify
(
value
)
:
value
;
}
function
isEmpty
(
value
)
{
if
(
!
isDefined
(
value
))
{
return
true
;
}
if
(
value
===
''
)
{
return
true
;
if
(
objectHelper
.
isString
(
value
))
{
return
value
===
''
;
}
if
(
objectHelper
.
isNumber
(
value
)
||
objectHelper
.
isBoolean
(
value
))
{
return
false
;
}
if
(
objectHelper
.
isArray
(
value
))
{
return
value
.
length
===
0
;
...
...
demo.html
View file @
19aa9f17
...
...
@@ -16,12 +16,13 @@
first
:
"
1
"
,
second
:
2
}
};
},
expanded
=
UriTemplate
.
parse
(
templateText
).
expand
(
variables
);
document
.
getElementById
(
'
id
'
).
innerHTML
=
"
<p>When you have a template of the form</p><p><code>var templateText =
\"
"
+
templateText
+
"
\"
;</code></p><p>and params of the form </p><p><code>var variables =
"
+
JSON
.
stringify
(
variables
)
+
"
\"
;</code></p><p>and params of the form </p><p><code>var variables =
{query: {first:
\"
1
\"
, second: 2}}
"
+
"
;</code></p><p>, you can use </p><p><code>UriTemplate.parse(templateText).expand(variables); </code></p><p>to produce </p><p><code>
"
+
UriTemplate
.
parse
(
templateText
).
expand
(
variables
)
+
expanded
+
"
</code></p><p> Look at the source code of this page!</p>
"
;
}());
</script>
...
...
package.json
View file @
19aa9f17
...
...
@@ -33,7 +33,7 @@
"uritemplate-test/spec-examples-by-sections.json"
,
"uritemplate-test/spec-examples.json"
],
"version"
:
"0.3.
1
"
,
"version"
:
"0.3.
2
"
,
"readmeFilename"
:
"README.md"
,
"gitHead"
:
"901b85201a821427dfb4591b56aea3a70d45c67c"
,
"devDependencies"
:
{
...
...
src/VariableExpression.js
View file @
19aa9f17
...
...
@@ -4,15 +4,18 @@ var VariableExpression = (function () {
"
use strict
"
;
// helper function if JSON is not available
function
prettyPrint
(
value
)
{
return
JSON
?
JSON
.
stringify
(
value
)
:
value
;
return
(
JSON
&&
JSON
.
stringify
)
?
JSON
.
stringify
(
value
)
:
value
;
}
function
isEmpty
(
value
)
{
if
(
!
isDefined
(
value
))
{
return
true
;
}
if
(
value
===
''
)
{
return
true
;
if
(
objectHelper
.
isString
(
value
))
{
return
value
===
''
;
}
if
(
objectHelper
.
isNumber
(
value
)
||
objectHelper
.
isBoolean
(
value
))
{
return
false
;
}
if
(
objectHelper
.
isArray
(
value
))
{
return
value
.
length
===
0
;
...
...
src/objectHelper.js
View file @
19aa9f17
...
...
@@ -5,6 +5,18 @@ var objectHelper = (function () {
return
Object
.
prototype
.
toString
.
apply
(
value
)
===
'
[object Array]
'
;
}
function
isString
(
value
)
{
return
Object
.
prototype
.
toString
.
apply
(
value
)
===
'
[object String]
'
;
}
function
isNumber
(
value
)
{
return
Object
.
prototype
.
toString
.
apply
(
value
)
===
'
[object Number]
'
;
}
function
isBoolean
(
value
)
{
return
Object
.
prototype
.
toString
.
apply
(
value
)
===
'
[object Boolean]
'
;
}
function
join
(
arr
,
separator
)
{
var
result
=
''
,
...
...
@@ -72,6 +84,9 @@ var objectHelper = (function () {
return
{
isArray
:
isArray
,
isString
:
isString
,
isNumber
:
isNumber
,
isBoolean
:
isBoolean
,
join
:
join
,
map
:
map
,
filter
:
filter
,
...
...
src/pctEncoder.js
View file @
19aa9f17
...
...
@@ -53,7 +53,7 @@ var pctEncoder = (function () {
* @return {boolean|*|*}
*/
function
isPercentDigitDigit
(
text
,
start
)
{
return
text
[
start
]
===
'
%
'
&&
charHelper
.
isHexDigit
(
text
[
start
+
1
])
&&
charHelper
.
isHexDigit
(
text
[
start
+
2
]
);
return
text
.
charAt
(
start
)
===
'
%
'
&&
charHelper
.
isHexDigit
(
text
.
charAt
(
start
+
1
))
&&
charHelper
.
isHexDigit
(
text
.
charAt
(
start
+
2
)
);
}
/**
...
...
@@ -95,7 +95,7 @@ var pctEncoder = (function () {
* @return the character or pct-string of the text at startIndex
*/
function
pctCharAt
(
text
,
startIndex
)
{
var
chr
=
text
[
startIndex
]
;
var
chr
=
text
.
charAt
(
startIndex
)
;
if
(
!
isPercentDigitDigit
(
text
,
startIndex
))
{
return
chr
;
}
...
...
src/pre.txt
View file @
19aa9f17
/*jshint */
/*global unescape, module, define, window, global*/
/*
...
...
test/integration/testRfcSamples.js
View file @
19aa9f17
...
...
@@ -106,7 +106,7 @@ module.exports = (function () {
test
.
done
();
}
var
SPEC_HOME
=
'
../
uritemplate-test
'
;
var
SPEC_HOME
=
'
uritemplate-test
'
;
return
{
'
spec examples
'
:
function
(
test
)
{
...
...
test/unit/testVariableExpression.js
View file @
19aa9f17
...
...
@@ -58,12 +58,41 @@ module.exports = (function () {
test
.
equal
(
ve
.
expand
({
keys
:
{
a
:
'
a
'
,
b
:
'
b
'
,
c
:
'
c
'
}}),
'
a=a,b=b,c=c
'
);
test
.
done
();
},
'
a map works with numbers
'
:
function
(
test
)
{
var
ve
=
new
VariableExpression
(
"
{keys*}
"
,
operators
.
valueOf
(
''
),
[
{
varname
:
'
keys
'
,
exploded
:
true
,
maxLength
:
null
}
]);
test
.
equal
(
ve
.
expand
({
keys
:
{
a
:
'
a
'
,
two
:
2
}}),
'
a=a,two=2
'
);
test
.
done
();
},
'
a map works with booleans
'
:
function
(
test
)
{
var
ve
=
new
VariableExpression
(
"
{keys*}
"
,
operators
.
valueOf
(
''
),
[
{
varname
:
'
keys
'
,
exploded
:
true
,
maxLength
:
null
}
]);
test
.
equal
(
ve
.
expand
({
keys
:
{
a
:
'
a
'
,
true
:
true
}}),
'
a=a,true=true
'
);
test
.
done
();
},
'
a empty map prints no operator
'
:
function
(
test
)
{
var
ve
=
new
VariableExpression
(
"
{.empty_map*}
"
,
operators
.
valueOf
(
'
.
'
),
[
{
varname
:
'
empty_map
'
,
exploded
:
true
,
maxLength
:
null
}
]);
test
.
equal
(
ve
.
expand
({
empty_map
:
{}}),
''
);
test
.
done
();
},
'
empty elements have the name and =
'
:
function
(
test
)
{
var
ve
=
new
VariableExpression
(
"
{?map*}
"
,
operators
.
valueOf
(
'
?
'
),
[
{
varname
:
'
map
'
,
exploded
:
true
,
maxLength
:
null
}
]);
test
.
equal
(
ve
.
expand
({
map
:
{
a
:
'
a
'
,
empty
:
''
}}),
'
?a=a&empty=
'
);
test
.
done
();
},
'
empty elements have the name and no =, if the operator has no ifemp
'
:
function
(
test
)
{
var
ve
=
new
VariableExpression
(
"
{;map*}
"
,
operators
.
valueOf
(
'
;
'
),
[
{
varname
:
'
map
'
,
exploded
:
true
,
maxLength
:
null
}
]);
test
.
equal
(
ve
.
expand
({
map
:
{
a
:
'
a
'
,
empty
:
''
}}),
'
;a=a;empty
'
);
test
.
done
();
}
},
'
named
'
:
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment