forked from DerivcoIpswich/dsharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMisc.js
More file actions
157 lines (134 loc) · 3.5 KB
/
Copy pathMisc.js
File metadata and controls
157 lines (134 loc) · 3.5 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
// Various Helpers/Utilities
function _nop() {
}
function isValue(o) {
return (o !== null) && (o !== undefined);
}
function _value(args) {
for (var i = 2, l = args.length; i < l; i++) {
if (isValue(args[i])) {
return args[i];
}
}
return null;
}
function value(a, b) {
return isValue(a) ? a : isValue(b) ? b : _value(arguments);
}
var extend = Object.assign;
function extendType(o, items) {
for (var n in items) {
if (startsWith(n, "$get_")) {
createPropertyGet(o, n.slice(5), items[n]);
}
else if (startsWith(n, "$set_")) {
createPropertySet(o, n.slice(5), items[n]);
}
else {
o[n] = items[n];
}
}
return o;
}
function parseBoolean(s) {
return (s.toLowerCase() == 'true');
}
function parseRegExp(s) {
if (s[0] == '/') {
var endSlashIndex = s.lastIndexOf('/');
if (endSlashIndex > 1) {
var expression = s.substring(1, endSlashIndex);
var flags = s.substr(endSlashIndex + 1);
return new RegExp(expression, flags);
}
}
return null;
}
function parseNumber(s) {
if (!s || !s.length) {
return 0;
}
if ((s.indexOf('.') >= 0) || (s.indexOf('e') >= 0) ||
endsWith(s, 'f') || endsWith(s, 'F')) {
return parseFloat(s);
}
return parseInt(s, 10);
}
function parseDate(s) {
var t = Date.parse(s);
return isNaN(t) ? undefined : new Date(t);
}
function truncate(n) {
return (n >= 0) ? Math.floor(n) : Math.ceil(n);
}
function now() {
return new Date();
}
function today() {
var d = new Date();
return new Date(d.getFullYear(), d.getMonth(), d.getDate());
}
function compareDates(d1, d2) {
return (d1 === d2) ? true : ((isValue(d1) && isValue(d2)) ? (d1.getTime() == d2.getTime()) : false);
}
function _popStackFrame(e) {
if (!isValue(e.stack) ||
!isValue(e.fileName) ||
!isValue(e.lineNumber)) {
return;
}
var stackFrames = e.stack.split('\n');
var currentFrame = stackFrames[0];
var pattern = e.fileName + ':' + e.lineNumber;
while (isValue(currentFrame) && currentFrame.indexOf(pattern) === -1) {
stackFrames.shift();
currentFrame = stackFrames[0];
}
var nextFrame = stackFrames[1];
if (!isValue(nextFrame)) {
return;
}
var nextFrameParts = nextFrame.match(/@(.*):(\d+)$/);
if (!isValue(nextFrameParts)) {
return;
}
stackFrames.shift();
e.stack = stackFrames.join('\n');
e.fileName = nextFrameParts[1];
e.lineNumber = parseInt(nextFrameParts[2], 10);
}
function error(message, errorInfo, innerException) {
var e = new Error(message);
if (errorInfo) {
for (var v in errorInfo) {
e[v] = errorInfo[v];
}
}
if (innerException) {
Object.defineProperty(e, "innerException", {
value: innerException
});
}
_popStackFrame(e);
return e;
}
function fail(message) {
console.assert(false, message);
if (self.navigator) {
eval('debugger;');
}
}
function paramsGenerator(n, f) {
return function () {
var slice = Array.prototype.slice;
var args = slice.call(arguments, 0, n);
if (arguments.length == n + 1 && Array.isArray(arguments[n])) {
args.push(arguments[n]);
}
else {
var unnamed = slice.call(arguments, n);
args.push(unnamed);
}
return f.apply(this, args);
}
}