Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80724 views
1
"use strict";
2
/*jshint -W004 */
3
var escape = {
4
"&": "&",
5
"<": "&lt;",
6
">": "&gt;",
7
'"': "&quot;",
8
"'": "&#x27;",
9
"`": "&#x60;"
10
};
11
12
var badChars = /[&<>"'`]/g;
13
var possible = /[&<>"'`]/;
14
15
function escapeChar(chr) {
16
return escape[chr];
17
}
18
19
function extend(obj /* , ...source */) {
20
for (var i = 1; i < arguments.length; i++) {
21
for (var key in arguments[i]) {
22
if (Object.prototype.hasOwnProperty.call(arguments[i], key)) {
23
obj[key] = arguments[i][key];
24
}
25
}
26
}
27
28
return obj;
29
}
30
31
exports.extend = extend;var toString = Object.prototype.toString;
32
exports.toString = toString;
33
// Sourced from lodash
34
// https://github.com/bestiejs/lodash/blob/master/LICENSE.txt
35
var isFunction = function(value) {
36
return typeof value === 'function';
37
};
38
// fallback for older versions of Chrome and Safari
39
/* istanbul ignore next */
40
if (isFunction(/x/)) {
41
isFunction = function(value) {
42
return typeof value === 'function' && toString.call(value) === '[object Function]';
43
};
44
}
45
var isFunction;
46
exports.isFunction = isFunction;
47
/* istanbul ignore next */
48
var isArray = Array.isArray || function(value) {
49
return (value && typeof value === 'object') ? toString.call(value) === '[object Array]' : false;
50
};
51
exports.isArray = isArray;
52
// Older IE versions do not directly support indexOf so we must implement our own, sadly.
53
function indexOf(array, value) {
54
for (var i = 0, len = array.length; i < len; i++) {
55
if (array[i] === value) {
56
return i;
57
}
58
}
59
return -1;
60
}
61
62
exports.indexOf = indexOf;
63
function escapeExpression(string) {
64
// don't escape SafeStrings, since they're already safe
65
if (string && string.toHTML) {
66
return string.toHTML();
67
} else if (string == null) {
68
return "";
69
} else if (!string) {
70
return string + '';
71
}
72
73
// Force a string conversion as this will be done by the append regardless and
74
// the regex test will do this transparently behind the scenes, causing issues if
75
// an object's to string has escaped characters in it.
76
string = "" + string;
77
78
if(!possible.test(string)) { return string; }
79
return string.replace(badChars, escapeChar);
80
}
81
82
exports.escapeExpression = escapeExpression;function isEmpty(value) {
83
if (!value && value !== 0) {
84
return true;
85
} else if (isArray(value) && value.length === 0) {
86
return true;
87
} else {
88
return false;
89
}
90
}
91
92
exports.isEmpty = isEmpty;function blockParams(params, ids) {
93
params.path = ids;
94
return params;
95
}
96
97
exports.blockParams = blockParams;function appendContextPath(contextPath, id) {
98
return (contextPath ? contextPath + '.' : '') + id;
99
}
100
101
exports.appendContextPath = appendContextPath;
102