-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvrep.js
53 lines (41 loc) · 1.41 KB
/
vrep.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/* global module */
(function () {
var format = create("{", "}"), output;
function id (v) {
return v;
}
//
// Creates a format function using `left` as the left delimiter, `right` as the right
// delimiter. If `filter` is supplied, every value inserted into the input template is run
// through this `filter` function. This can be used to add HTML escaping and similar things.
//
function create (left, right, escape) {
if (typeof left !== "string" || typeof right !== "string") {
throw new Error("Arguments left and right must be strings.");
}
escape = (typeof escape === "function" ? escape : id);
return function (text, values) {
if (Array.isArray(values)) {
values.forEach(function (value, i) {
text = text.split(left + (i + 1) + right).join(escape(value));
});
}
else {
Object.keys(values).forEach(function (key) {
text = text.split(left + key + right).join(escape(values[key]));
});
}
return text;
};
}
output = {
create: create,
format: format
};
if (typeof require === "function") {
module.exports = output;
}
else {
window.VREP = output;
}
}());