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