uicore-ts 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.idea/misc.xml +6 -0
- package/.idea/modules.xml +8 -0
- package/.idea/uicore.iml +9 -0
- package/.idea/vcs.xml +6 -0
- package/LICENSE +21 -0
- package/README.md +5 -0
- package/compiledScripts/UIActionIndicator.d.ts +12 -0
- package/compiledScripts/UIActionIndicator.js +54 -0
- package/compiledScripts/UIActionIndicator.js.map +1 -0
- package/compiledScripts/UIBaseButton.d.ts +52 -0
- package/compiledScripts/UIBaseButton.js +268 -0
- package/compiledScripts/UIBaseButton.js.map +1 -0
- package/compiledScripts/UIButton.d.ts +54 -0
- package/compiledScripts/UIButton.js +247 -0
- package/compiledScripts/UIButton.js.map +1 -0
- package/compiledScripts/UIColor.d.ts +41 -0
- package/compiledScripts/UIColor.js +286 -0
- package/compiledScripts/UIColor.js.map +1 -0
- package/compiledScripts/UICore.d.ts +27 -0
- package/compiledScripts/UICore.js +105 -0
- package/compiledScripts/UICore.js.map +1 -0
- package/compiledScripts/UICoreExtensions.d.ts +60 -0
- package/compiledScripts/UICoreExtensions.js +527 -0
- package/compiledScripts/UICoreExtensions.js.map +1 -0
- package/compiledScripts/UIDateTimeInput.d.ts +40 -0
- package/compiledScripts/UIDateTimeInput.js +38 -0
- package/compiledScripts/UIDateTimeInput.js.map +1 -0
- package/compiledScripts/UIDialogView.d.ts +23 -0
- package/compiledScripts/UIDialogView.js +118 -0
- package/compiledScripts/UIDialogView.js.map +1 -0
- package/compiledScripts/UIImageView.d.ts +36 -0
- package/compiledScripts/UIImageView.js +170 -0
- package/compiledScripts/UIImageView.js.map +1 -0
- package/compiledScripts/UIKeyValueStringFilter.d.ts +21 -0
- package/compiledScripts/UIKeyValueStringFilter.js +98 -0
- package/compiledScripts/UIKeyValueStringFilter.js.map +1 -0
- package/compiledScripts/UIKeyValueStringSorter.d.ts +38 -0
- package/compiledScripts/UIKeyValueStringSorter.js +117 -0
- package/compiledScripts/UIKeyValueStringSorter.js.map +1 -0
- package/compiledScripts/UILayoutGrid.d.ts +8 -0
- package/compiledScripts/UILayoutGrid.js +22 -0
- package/compiledScripts/UILayoutGrid.js.map +1 -0
- package/compiledScripts/UILink.d.ts +25 -0
- package/compiledScripts/UILink.js +81 -0
- package/compiledScripts/UILink.js.map +1 -0
- package/compiledScripts/UILinkButton.d.ts +18 -0
- package/compiledScripts/UILinkButton.js +60 -0
- package/compiledScripts/UILinkButton.js.map +1 -0
- package/compiledScripts/UINativeScrollView.d.ts +20 -0
- package/compiledScripts/UINativeScrollView.js +121 -0
- package/compiledScripts/UINativeScrollView.js.map +1 -0
- package/compiledScripts/UIObject.d.ts +69 -0
- package/compiledScripts/UIObject.js +442 -0
- package/compiledScripts/UIObject.js.map +1 -0
- package/compiledScripts/UIPoint.d.ts +18 -0
- package/compiledScripts/UIPoint.js +68 -0
- package/compiledScripts/UIPoint.js.map +1 -0
- package/compiledScripts/UIRectangle.d.ts +61 -0
- package/compiledScripts/UIRectangle.js +421 -0
- package/compiledScripts/UIRectangle.js.map +1 -0
- package/compiledScripts/UIRoute.d.ts +39 -0
- package/compiledScripts/UIRoute.js +202 -0
- package/compiledScripts/UIRoute.js.map +1 -0
- package/compiledScripts/UIScrollView.d.ts +19 -0
- package/compiledScripts/UIScrollView.js +121 -0
- package/compiledScripts/UIScrollView.js.map +1 -0
- package/compiledScripts/UISlideScrollerView.d.ts +40 -0
- package/compiledScripts/UISlideScrollerView.js +242 -0
- package/compiledScripts/UISlideScrollerView.js.map +1 -0
- package/compiledScripts/UIStringFilter.d.ts +26 -0
- package/compiledScripts/UIStringFilter.js +107 -0
- package/compiledScripts/UIStringFilter.js.map +1 -0
- package/compiledScripts/UITableView.d.ts +61 -0
- package/compiledScripts/UITableView.js +383 -0
- package/compiledScripts/UITableView.js.map +1 -0
- package/compiledScripts/UITextArea.d.ts +7 -0
- package/compiledScripts/UITextArea.js +27 -0
- package/compiledScripts/UITextArea.js.map +1 -0
- package/compiledScripts/UITextField.d.ts +44 -0
- package/compiledScripts/UITextField.js +83 -0
- package/compiledScripts/UITextField.js.map +1 -0
- package/compiledScripts/UITextView.d.ts +89 -0
- package/compiledScripts/UITextView.js +237 -0
- package/compiledScripts/UITextView.js.map +1 -0
- package/compiledScripts/UITimer.d.ts +13 -0
- package/compiledScripts/UITimer.js +45 -0
- package/compiledScripts/UITimer.js.map +1 -0
- package/compiledScripts/UIView.d.ts +330 -0
- package/compiledScripts/UIView.js +1533 -0
- package/compiledScripts/UIView.js.map +1 -0
- package/compiledScripts/UIViewController.d.ts +38 -0
- package/compiledScripts/UIViewController.js +153 -0
- package/compiledScripts/UIViewController.js.map +1 -0
- package/compiledScripts/index.d.ts +29 -0
- package/compiledScripts/index.js +46 -0
- package/compiledScripts/index.js.map +1 -0
- package/package.json +36 -0
- package/scripts/UIActionIndicator.ts +139 -0
- package/scripts/UIBaseButton.ts +563 -0
- package/scripts/UIButton.ts +552 -0
- package/scripts/UIColor.ts +427 -0
- package/scripts/UICore.ts +223 -0
- package/scripts/UICoreExtensions.ts +949 -0
- package/scripts/UIDateTimeInput.ts +109 -0
- package/scripts/UIDialogView.ts +297 -0
- package/scripts/UIImageView.ts +366 -0
- package/scripts/UIKeyValueStringFilter.ts +260 -0
- package/scripts/UIKeyValueStringSorter.ts +337 -0
- package/scripts/UILayoutGrid.ts +83 -0
- package/scripts/UILink.ts +292 -0
- package/scripts/UILinkButton.ts +238 -0
- package/scripts/UINativeScrollView.ts +254 -0
- package/scripts/UIObject.ts +827 -0
- package/scripts/UIPoint.ts +123 -0
- package/scripts/UIRectangle.ts +730 -0
- package/scripts/UIRoute.ts +391 -0
- package/scripts/UIScrollView.ts +290 -0
- package/scripts/UISlideScrollerView.ts +530 -0
- package/scripts/UIStringFilter.ts +293 -0
- package/scripts/UITableView.ts +790 -0
- package/scripts/UITextArea.ts +91 -0
- package/scripts/UITextField.ts +218 -0
- package/scripts/UITextView.ts +561 -0
- package/scripts/UITimer.ts +107 -0
- package/scripts/UIView.ts +2789 -0
- package/scripts/UIViewController.ts +304 -0
- package/scripts/index.ts +36 -0
- package/tsconfig.json +59 -0
|
@@ -0,0 +1,949 @@
|
|
|
1
|
+
import { NO, UIObject, YES } from "./UIObject"
|
|
2
|
+
|
|
3
|
+
declare global {
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
interface Array<T> {
|
|
7
|
+
|
|
8
|
+
removeElementAtIndex(index: number);
|
|
9
|
+
removeElement(element: T);
|
|
10
|
+
|
|
11
|
+
insertElementAtIndex(index: number, element: T);
|
|
12
|
+
replaceElementAtIndex(index: number, element: T);
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
contains(element: T): boolean;
|
|
16
|
+
|
|
17
|
+
groupedBy(keyFunction: (item: T) => any): { [key: string]: Array<T> } & Object;
|
|
18
|
+
|
|
19
|
+
copy(): Array<T>;
|
|
20
|
+
|
|
21
|
+
arrayByRepeating(numberOfRepetitions: number): Array<T>;
|
|
22
|
+
arrayByTrimmingToLengthIfLonger(maxLength: number): Array<T>;
|
|
23
|
+
|
|
24
|
+
anyMatch(predicate: (value: T, index: number, obj: T[]) => boolean): boolean
|
|
25
|
+
noneMatch(predicate: (value: T, index: number, obj: T[]) => boolean): boolean
|
|
26
|
+
|
|
27
|
+
allMatch(predicate: (value: T, index: number, obj: T[]) => boolean): boolean
|
|
28
|
+
|
|
29
|
+
readonly firstElement: T;
|
|
30
|
+
readonly lastElement: T;
|
|
31
|
+
readonly summedValue: T;
|
|
32
|
+
|
|
33
|
+
max(): number;
|
|
34
|
+
min(): number;
|
|
35
|
+
|
|
36
|
+
isEqualToArray(array: Array<T>, keyPath?: string): boolean;
|
|
37
|
+
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
interface String {
|
|
43
|
+
|
|
44
|
+
contains(string): boolean;
|
|
45
|
+
|
|
46
|
+
readonly numericalValue: number;
|
|
47
|
+
isAString: boolean;
|
|
48
|
+
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
interface Number {
|
|
54
|
+
|
|
55
|
+
isANumber: boolean;
|
|
56
|
+
|
|
57
|
+
readonly integerValue: number;
|
|
58
|
+
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
interface Date {
|
|
64
|
+
|
|
65
|
+
readonly dateString: string;
|
|
66
|
+
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
interface Object {
|
|
71
|
+
|
|
72
|
+
forEach(callbackFunction: (value: any, key: string) => void): void;
|
|
73
|
+
|
|
74
|
+
readonly allValues: Array<any>;
|
|
75
|
+
|
|
76
|
+
readonly allKeys: string[];
|
|
77
|
+
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export {};
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
if ("removeElementAtIndex" in Array.prototype == NO) {
|
|
87
|
+
|
|
88
|
+
(Array.prototype as any).removeElementAtIndex = function (this: Array<any>, index: number) {
|
|
89
|
+
|
|
90
|
+
// @ts-ignore
|
|
91
|
+
if (index >= 0 && index < this.length) {
|
|
92
|
+
|
|
93
|
+
this.splice(index, 1)
|
|
94
|
+
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
// interface Array<T> {
|
|
103
|
+
//
|
|
104
|
+
// removeElementAtIndex(index: number);
|
|
105
|
+
//
|
|
106
|
+
// }
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
if ("removeElement" in Array.prototype == NO) {
|
|
110
|
+
|
|
111
|
+
(Array.prototype as any).removeElement = function (this: Array<any>, element) {
|
|
112
|
+
|
|
113
|
+
this.removeElementAtIndex(this.indexOf(element))
|
|
114
|
+
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
// interface Array<T> {
|
|
121
|
+
//
|
|
122
|
+
// removeElement(element: T);
|
|
123
|
+
//
|
|
124
|
+
// }
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
if ("insertElementAtIndex" in Array.prototype == NO) {
|
|
128
|
+
|
|
129
|
+
(Array.prototype as any).insertElementAtIndex = function (this: Array<any>, index: number, element: any) {
|
|
130
|
+
|
|
131
|
+
if (index >= 0 && index <= this.length) {
|
|
132
|
+
|
|
133
|
+
this.splice(index, 0, element)
|
|
134
|
+
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
// interface Array<T> {
|
|
143
|
+
//
|
|
144
|
+
// insertElementAtIndex(index: number, element: T);
|
|
145
|
+
//
|
|
146
|
+
// }
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
if ("replaceElementAtIndex" in Array.prototype == NO) {
|
|
150
|
+
|
|
151
|
+
(Array.prototype as any).replaceElementAtIndex = function (this: Array<any>, index: number, element: any) {
|
|
152
|
+
|
|
153
|
+
this.removeElementAtIndex(index)
|
|
154
|
+
this.insertElementAtIndex(index, element)
|
|
155
|
+
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
// interface Array<T> {
|
|
162
|
+
//
|
|
163
|
+
// replaceElementAtIndex(index: number, element: T);
|
|
164
|
+
//
|
|
165
|
+
// }
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
if ("contains" in Array.prototype == NO) {
|
|
169
|
+
|
|
170
|
+
(Array.prototype as any).contains = function (this: Array<any>, element) {
|
|
171
|
+
|
|
172
|
+
const result = (this.indexOf(element) != -1)
|
|
173
|
+
return result
|
|
174
|
+
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
if ("containsAny" in Array.prototype == NO) {
|
|
180
|
+
|
|
181
|
+
(Array.prototype as any).containsAny = function (this: Array<any>, elements: any[]) {
|
|
182
|
+
|
|
183
|
+
const result = this.anyMatch(function (element, index, array) {
|
|
184
|
+
return elements.contains(element)
|
|
185
|
+
})
|
|
186
|
+
|
|
187
|
+
return result
|
|
188
|
+
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
// interface Array<T> {
|
|
195
|
+
//
|
|
196
|
+
// contains(element: T): boolean;
|
|
197
|
+
//
|
|
198
|
+
// containsAny(element: T[]): boolean;
|
|
199
|
+
//
|
|
200
|
+
// }
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
if ("anyMatch" in Array.prototype == NO) {
|
|
204
|
+
|
|
205
|
+
(Array.prototype as any).anyMatch = function (
|
|
206
|
+
this: Array<any>,
|
|
207
|
+
functionToCall: (value: any, index: number, array: any[]) => boolean
|
|
208
|
+
) {
|
|
209
|
+
|
|
210
|
+
// @ts-ignore
|
|
211
|
+
const result = (this.findIndex(functionToCall) > -1)
|
|
212
|
+
|
|
213
|
+
return result
|
|
214
|
+
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
if ("noneMatch" in Array.prototype == NO) {
|
|
220
|
+
|
|
221
|
+
(Array.prototype as any).noneMatch = function (
|
|
222
|
+
this: Array<any>,
|
|
223
|
+
functionToCall: (value: any, index: number, array: any[]) => boolean
|
|
224
|
+
) {
|
|
225
|
+
|
|
226
|
+
// @ts-ignore
|
|
227
|
+
const result = (this.findIndex(functionToCall) == -1)
|
|
228
|
+
|
|
229
|
+
return result
|
|
230
|
+
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
if ("allMatch" in Array.prototype == NO) {
|
|
236
|
+
|
|
237
|
+
(Array.prototype as any).allMatch = function (
|
|
238
|
+
this: Array<any>,
|
|
239
|
+
functionToCall: (value: any, index: number, array: any[]) => boolean
|
|
240
|
+
) {
|
|
241
|
+
|
|
242
|
+
function reversedFunction(value: any, index: number, array: any[]) {
|
|
243
|
+
return !functionToCall(value, index, array)
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// @ts-ignore
|
|
247
|
+
const result = (this.findIndex(reversedFunction) == -1)
|
|
248
|
+
|
|
249
|
+
return result
|
|
250
|
+
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
// interface Array<T> {
|
|
257
|
+
//
|
|
258
|
+
// anyMatch(predicate: (value: T, index: number, obj: T[]) => boolean): boolean
|
|
259
|
+
//
|
|
260
|
+
// noneMatch(predicate: (value: T, index: number, obj: T[]) => boolean): boolean
|
|
261
|
+
//
|
|
262
|
+
// allMatch(predicate: (value: T, index: number, obj: T[]) => boolean): boolean
|
|
263
|
+
//
|
|
264
|
+
// }
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
if ("groupedBy" in Array.prototype == NO) {
|
|
268
|
+
|
|
269
|
+
Array.prototype.groupedBy = function (this: Array<any>, funcProp) {
|
|
270
|
+
return this.reduce(function (acc, val) {
|
|
271
|
+
(acc[funcProp(val)] = acc[funcProp(val)] || []).push(val)
|
|
272
|
+
return acc
|
|
273
|
+
}, {})
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
// interface Array<T> {
|
|
280
|
+
//
|
|
281
|
+
// groupedBy(keyFunction: (item: T) => any): { [key: string]: Array<T> };
|
|
282
|
+
//
|
|
283
|
+
// }
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
if ("firstElement" in Array.prototype == NO) {
|
|
287
|
+
Object.defineProperty(Array.prototype, "firstElement", {
|
|
288
|
+
get: function firstElement(this: Array<any>) {
|
|
289
|
+
const result = this[0]
|
|
290
|
+
return result
|
|
291
|
+
},
|
|
292
|
+
set: function (this: Array<any>, element: any) {
|
|
293
|
+
if (this.length == 0) {
|
|
294
|
+
this.push(element)
|
|
295
|
+
return
|
|
296
|
+
}
|
|
297
|
+
this[0] = element
|
|
298
|
+
}
|
|
299
|
+
})
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
if ("lastElement" in Array.prototype == NO) {
|
|
303
|
+
Object.defineProperty(Array.prototype, "lastElement", {
|
|
304
|
+
get: function lastElement(this: Array<any>) {
|
|
305
|
+
const result = this[this.length - 1]
|
|
306
|
+
return result
|
|
307
|
+
},
|
|
308
|
+
set: function (this: Array<any>, element: any) {
|
|
309
|
+
if (this.length == 0) {
|
|
310
|
+
this.push(element)
|
|
311
|
+
return
|
|
312
|
+
}
|
|
313
|
+
this[this.length - 1] = element
|
|
314
|
+
}
|
|
315
|
+
})
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
if ("everyElement" in Array.prototype == NO) {
|
|
319
|
+
|
|
320
|
+
Object.defineProperty(Array.prototype, "everyElement", {
|
|
321
|
+
|
|
322
|
+
get: function everyElement(this: Array<any>) {
|
|
323
|
+
|
|
324
|
+
var valueKeys = []
|
|
325
|
+
|
|
326
|
+
const targetFunction = (objects) => {
|
|
327
|
+
|
|
328
|
+
return this.map((element, index, array) => {
|
|
329
|
+
|
|
330
|
+
var elementFunction = (UIObject.valueForKeyPath(valueKeys.join("."), element) as Function).bind(
|
|
331
|
+
element,
|
|
332
|
+
objects
|
|
333
|
+
)
|
|
334
|
+
|
|
335
|
+
return elementFunction()
|
|
336
|
+
|
|
337
|
+
});
|
|
338
|
+
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
const result = new Proxy(
|
|
342
|
+
targetFunction,
|
|
343
|
+
{
|
|
344
|
+
|
|
345
|
+
get: (target, key, receiver) => {
|
|
346
|
+
|
|
347
|
+
if (key == "UI_elementValues") {
|
|
348
|
+
|
|
349
|
+
return this.map((element, index, array) => UIObject.valueForKeyPath(
|
|
350
|
+
valueKeys.join("."),
|
|
351
|
+
element
|
|
352
|
+
));
|
|
353
|
+
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
valueKeys.push(key)
|
|
357
|
+
|
|
358
|
+
return result
|
|
359
|
+
|
|
360
|
+
},
|
|
361
|
+
set: (target, key, value, receiver) => {
|
|
362
|
+
|
|
363
|
+
valueKeys.push(key)
|
|
364
|
+
|
|
365
|
+
this.forEach((element, index, array) => {
|
|
366
|
+
|
|
367
|
+
UIObject.setValueForKeyPath(valueKeys.join("."), value, element, YES)
|
|
368
|
+
|
|
369
|
+
})
|
|
370
|
+
|
|
371
|
+
return true
|
|
372
|
+
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
}
|
|
376
|
+
)
|
|
377
|
+
|
|
378
|
+
return result
|
|
379
|
+
|
|
380
|
+
},
|
|
381
|
+
set: function (this: Array<any>, element: any) {
|
|
382
|
+
|
|
383
|
+
for (var i = 0; i < this.length; ++i) {
|
|
384
|
+
|
|
385
|
+
this[i] = element
|
|
386
|
+
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
})
|
|
392
|
+
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
|
|
396
|
+
export type UIEveryElementItem<T> = {
|
|
397
|
+
|
|
398
|
+
[P in keyof T]: UIEveryElementItem<T[P]>
|
|
399
|
+
|
|
400
|
+
} & {
|
|
401
|
+
|
|
402
|
+
UI_elementValues?: T[];
|
|
403
|
+
|
|
404
|
+
} & T
|
|
405
|
+
|
|
406
|
+
// interface Array<T> {
|
|
407
|
+
//
|
|
408
|
+
// firstElement: T;
|
|
409
|
+
// lastElement: T;
|
|
410
|
+
//
|
|
411
|
+
// everyElement: UIEveryElementItem<T>;
|
|
412
|
+
//
|
|
413
|
+
// }
|
|
414
|
+
|
|
415
|
+
|
|
416
|
+
if ("copy" in Array.prototype == NO) {
|
|
417
|
+
|
|
418
|
+
(Array.prototype as any).copy = function (this: Array<any>) {
|
|
419
|
+
|
|
420
|
+
const result = this.slice(0)
|
|
421
|
+
return result
|
|
422
|
+
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
|
|
428
|
+
// interface Array<T> {
|
|
429
|
+
//
|
|
430
|
+
// copy(): Array<T>;
|
|
431
|
+
//
|
|
432
|
+
// }
|
|
433
|
+
|
|
434
|
+
|
|
435
|
+
if ("arrayByRepeating" in Array.prototype == NO) {
|
|
436
|
+
|
|
437
|
+
(Array.prototype as any).arrayByRepeating = function (this: Array<any>, numberOfRepetitions: number) {
|
|
438
|
+
const result = []
|
|
439
|
+
for (var i = 0; i < numberOfRepetitions; i++) {
|
|
440
|
+
this.forEach(function (element, index, array) {
|
|
441
|
+
result.push(element)
|
|
442
|
+
})
|
|
443
|
+
}
|
|
444
|
+
return result
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
|
|
450
|
+
// interface Array<T> {
|
|
451
|
+
//
|
|
452
|
+
// arrayByRepeating(numberOfRepetitions: number): Array<T>;
|
|
453
|
+
//
|
|
454
|
+
// }
|
|
455
|
+
|
|
456
|
+
|
|
457
|
+
if ("arrayByTrimmingToLengthIfLonger" in Array.prototype == NO) {
|
|
458
|
+
(Array.prototype as any).arrayByTrimmingToLengthIfLonger = function (this: Array<any>, maxLength: number) {
|
|
459
|
+
const result = []
|
|
460
|
+
for (var i = 0; i < maxLength && i < this.length; i++) {
|
|
461
|
+
result.push(this[i])
|
|
462
|
+
}
|
|
463
|
+
return result
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
|
|
468
|
+
// interface Array<T> {
|
|
469
|
+
//
|
|
470
|
+
// arrayByTrimmingToLengthIfLonger(maxLength: number): Array<T>;
|
|
471
|
+
//
|
|
472
|
+
// }
|
|
473
|
+
|
|
474
|
+
|
|
475
|
+
if ("summedValue" in Array.prototype == NO) {
|
|
476
|
+
|
|
477
|
+
Object.defineProperty(Array.prototype, "summedValue", {
|
|
478
|
+
get: function summedValue(this: Array<any>) {
|
|
479
|
+
const result = this.reduce(function (a, b) {
|
|
480
|
+
return a + b
|
|
481
|
+
}, 0)
|
|
482
|
+
return result
|
|
483
|
+
}
|
|
484
|
+
})
|
|
485
|
+
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
|
|
489
|
+
// interface Array<T> {
|
|
490
|
+
//
|
|
491
|
+
// readonly summedValue: T;
|
|
492
|
+
//
|
|
493
|
+
// max(): number;
|
|
494
|
+
// min(): number;
|
|
495
|
+
//
|
|
496
|
+
//
|
|
497
|
+
// }
|
|
498
|
+
|
|
499
|
+
Array.prototype.max = function() {
|
|
500
|
+
return Math.max.apply(null, this);
|
|
501
|
+
};
|
|
502
|
+
|
|
503
|
+
Array.prototype.min = function() {
|
|
504
|
+
return Math.min.apply(null, this);
|
|
505
|
+
};
|
|
506
|
+
|
|
507
|
+
|
|
508
|
+
// interface Array<T> {
|
|
509
|
+
//
|
|
510
|
+
// isEqualToArray(array: Array<T>, keyPath?: string): boolean;
|
|
511
|
+
//
|
|
512
|
+
// }
|
|
513
|
+
|
|
514
|
+
// Warn if overriding existing method
|
|
515
|
+
if ("isEqualToArray" in Array.prototype == YES) {
|
|
516
|
+
console.warn(
|
|
517
|
+
"Overriding existing Array.prototype.isEqualToArray. Possible causes: New API defines the method, there's a framework conflict or you've got double inclusions in your code.")
|
|
518
|
+
}
|
|
519
|
+
// attach the .equals method to Array's prototype to call it on any array
|
|
520
|
+
Array.prototype.isEqualToArray = function (array: any[], keyPath?: string) {
|
|
521
|
+
|
|
522
|
+
// if the other array is a falsy value, return
|
|
523
|
+
if (!array) {
|
|
524
|
+
return false
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
// compare lengths - can save a lot of time
|
|
528
|
+
if (this.length != array.length) {
|
|
529
|
+
return false
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
var i = 0
|
|
533
|
+
const l = this.length
|
|
534
|
+
for (; i < l; i++) {
|
|
535
|
+
|
|
536
|
+
// Check if we have nested arrays
|
|
537
|
+
if (this[i] instanceof Array && array[i] instanceof Array && !keyPath) {
|
|
538
|
+
|
|
539
|
+
// recurse into the nested arrays
|
|
540
|
+
if (!this[i].isEqualToArray(array[i])) {
|
|
541
|
+
return false
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
}
|
|
545
|
+
else if (keyPath && UIObject.valueForKeyPath(keyPath, this[i]) != UIObject.valueForKeyPath(keyPath, array[i])) {
|
|
546
|
+
|
|
547
|
+
return false
|
|
548
|
+
|
|
549
|
+
}
|
|
550
|
+
else if (this[i] != array[i]) {
|
|
551
|
+
|
|
552
|
+
// Warning - two different object instances will never be equal: {x:20} != {x:20}
|
|
553
|
+
return false
|
|
554
|
+
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
return true
|
|
560
|
+
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
// Hide method from for-in loops
|
|
564
|
+
Object.defineProperty(Array.prototype, "isEqualToArray", { enumerable: false })
|
|
565
|
+
|
|
566
|
+
|
|
567
|
+
|
|
568
|
+
|
|
569
|
+
|
|
570
|
+
|
|
571
|
+
if ("forEach" in Object.prototype == NO) {
|
|
572
|
+
|
|
573
|
+
(Object.prototype as any).forEach = function (this: Object, callbackFunction: (value: any, key: string) => void) {
|
|
574
|
+
const keys = Object.keys(this)
|
|
575
|
+
keys.forEach(function (key, index, array) {
|
|
576
|
+
callbackFunction(this[key], key)
|
|
577
|
+
}.bind(this))
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
// Hide method from for-in loops
|
|
581
|
+
Object.defineProperty(Object.prototype, "forEach", { enumerable: false })
|
|
582
|
+
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
|
|
586
|
+
// interface Object {
|
|
587
|
+
//
|
|
588
|
+
// forEach(callbackFunction: (value: any, key: string) => void): void;
|
|
589
|
+
//
|
|
590
|
+
// }
|
|
591
|
+
|
|
592
|
+
|
|
593
|
+
if ("allValues" in Object.prototype == NO) {
|
|
594
|
+
Object.defineProperty(Object.prototype, "allValues", {
|
|
595
|
+
get: function (this: Object) {
|
|
596
|
+
const values = []
|
|
597
|
+
this.forEach(function (value: any) {
|
|
598
|
+
values.push(value)
|
|
599
|
+
})
|
|
600
|
+
return values
|
|
601
|
+
}
|
|
602
|
+
})
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
|
|
606
|
+
// interface Object {
|
|
607
|
+
//
|
|
608
|
+
// readonly allValues: Array<any>;
|
|
609
|
+
//
|
|
610
|
+
// }
|
|
611
|
+
|
|
612
|
+
|
|
613
|
+
if ("allKeys" in Object.prototype == NO) {
|
|
614
|
+
Object.defineProperty(Object.prototype, "allKeys", {
|
|
615
|
+
get: function (this: Object) {
|
|
616
|
+
const values = Object.keys(this)
|
|
617
|
+
return values
|
|
618
|
+
}
|
|
619
|
+
})
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
|
|
623
|
+
// interface Object {
|
|
624
|
+
//
|
|
625
|
+
// readonly allKeys: string[];
|
|
626
|
+
//
|
|
627
|
+
// }
|
|
628
|
+
|
|
629
|
+
|
|
630
|
+
if ("objectByCopyingValuesRecursivelyFromObject" in Object.prototype == NO) {
|
|
631
|
+
|
|
632
|
+
(Object.prototype as any).objectByCopyingValuesRecursivelyFromObject = function (this: Object, object: any) {
|
|
633
|
+
|
|
634
|
+
|
|
635
|
+
function isAnObject(item: any) {
|
|
636
|
+
return (item && typeof item === "object" && !Array.isArray(item))
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
function mergeRecursively(target: any, source: any) {
|
|
640
|
+
|
|
641
|
+
const output = Object.assign({}, target)
|
|
642
|
+
|
|
643
|
+
if (isAnObject(target) && isAnObject(source)) {
|
|
644
|
+
|
|
645
|
+
Object.keys(source).forEach(function (key) {
|
|
646
|
+
|
|
647
|
+
if (isAnObject(source[key])) {
|
|
648
|
+
|
|
649
|
+
// if (!(key in target)) {
|
|
650
|
+
|
|
651
|
+
// Object.assign(output, { [key]: source[key] });
|
|
652
|
+
|
|
653
|
+
// }
|
|
654
|
+
// else {
|
|
655
|
+
|
|
656
|
+
output[key] = mergeRecursively(target[key], source[key])
|
|
657
|
+
|
|
658
|
+
//}
|
|
659
|
+
|
|
660
|
+
}
|
|
661
|
+
else {
|
|
662
|
+
|
|
663
|
+
Object.assign(output, { [key]: source[key] })
|
|
664
|
+
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
})
|
|
668
|
+
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
return output
|
|
672
|
+
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
const result = mergeRecursively(this, object)
|
|
676
|
+
|
|
677
|
+
return result
|
|
678
|
+
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
// Hide method from for-in loops
|
|
682
|
+
Object.defineProperty(Object.prototype, "objectByCopyingValuesRecursivelyFromObject", { enumerable: false })
|
|
683
|
+
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
export class UICoreExtensionValueObject {
|
|
687
|
+
|
|
688
|
+
isAUICoreExtensionValueObject = YES;
|
|
689
|
+
value: any
|
|
690
|
+
|
|
691
|
+
constructor(value: any) {
|
|
692
|
+
|
|
693
|
+
this.value = value;
|
|
694
|
+
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
if ("asValueObject" in Object.prototype == NO) {
|
|
700
|
+
|
|
701
|
+
(Object.prototype as any).asValueObject = function () {
|
|
702
|
+
|
|
703
|
+
const result = new UICoreExtensionValueObject(this);
|
|
704
|
+
|
|
705
|
+
return result
|
|
706
|
+
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
// Hide method from for-in loops
|
|
710
|
+
Object.defineProperty(Object.prototype, "asValueObject", { enumerable: false })
|
|
711
|
+
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
|
|
715
|
+
// interface Object {
|
|
716
|
+
//
|
|
717
|
+
// objectByCopyingValuesRecursivelyFromObject<T>(object: T): this & T;
|
|
718
|
+
//
|
|
719
|
+
// asValueObject(): this;
|
|
720
|
+
//
|
|
721
|
+
// }
|
|
722
|
+
|
|
723
|
+
export type Unpacked<T> =
|
|
724
|
+
T extends (infer U)[]
|
|
725
|
+
? U
|
|
726
|
+
: T extends (...args: any[]) => infer U
|
|
727
|
+
? U
|
|
728
|
+
: T extends Promise<infer U>
|
|
729
|
+
? U
|
|
730
|
+
: T
|
|
731
|
+
|
|
732
|
+
export type UnpackedObject<T> = {
|
|
733
|
+
[P in keyof T]: Unpacked<T[P]>
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
export function promisedProperties<ObjectType extends object>(object: ObjectType): UnpackedObject<ObjectType> {
|
|
737
|
+
|
|
738
|
+
let promisedProperties = [];
|
|
739
|
+
const objectKeys = Object.keys(object);
|
|
740
|
+
|
|
741
|
+
objectKeys.forEach((key) => promisedProperties.push(object[key]));
|
|
742
|
+
|
|
743
|
+
// @ts-ignore
|
|
744
|
+
return Promise.all(promisedProperties)
|
|
745
|
+
.then((resolvedValues) => {
|
|
746
|
+
return resolvedValues.reduce((resolvedObject, property, index) => {
|
|
747
|
+
resolvedObject[objectKeys[index]] = property;
|
|
748
|
+
return resolvedObject;
|
|
749
|
+
}, object);
|
|
750
|
+
});
|
|
751
|
+
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
// if ("promisedProperties" in Object.prototype == NO) {
|
|
755
|
+
//
|
|
756
|
+
// (Object.prototype as any).promisedProperties = function () {
|
|
757
|
+
//
|
|
758
|
+
// const result = promisedProperties(this);
|
|
759
|
+
//
|
|
760
|
+
// return result
|
|
761
|
+
//
|
|
762
|
+
// }
|
|
763
|
+
//
|
|
764
|
+
// // Hide method from for-in loops
|
|
765
|
+
// Object.defineProperty(Object.prototype, "promisedProperties", { enumerable: false });
|
|
766
|
+
//
|
|
767
|
+
// }
|
|
768
|
+
//
|
|
769
|
+
//
|
|
770
|
+
// interface Object {
|
|
771
|
+
//
|
|
772
|
+
// readonly promisedProperties: UnpackedObject<this>;
|
|
773
|
+
//
|
|
774
|
+
// }
|
|
775
|
+
|
|
776
|
+
|
|
777
|
+
if ("contains" in String.prototype == NO) {
|
|
778
|
+
|
|
779
|
+
(String.prototype as any).contains = function (this: String, string) {
|
|
780
|
+
|
|
781
|
+
const result = (this.indexOf(string) != -1)
|
|
782
|
+
return result
|
|
783
|
+
|
|
784
|
+
}
|
|
785
|
+
|
|
786
|
+
// Hide method from for-in loops
|
|
787
|
+
Object.defineProperty(Object.prototype, "contains", { enumerable: false })
|
|
788
|
+
|
|
789
|
+
}
|
|
790
|
+
|
|
791
|
+
|
|
792
|
+
// interface String {
|
|
793
|
+
//
|
|
794
|
+
// contains(string): boolean;
|
|
795
|
+
//
|
|
796
|
+
// }
|
|
797
|
+
|
|
798
|
+
|
|
799
|
+
if ("capitalizedString" in String.prototype == NO) {
|
|
800
|
+
Object.defineProperty(Object.prototype, "capitalizedString", {
|
|
801
|
+
get: function (this: String) {
|
|
802
|
+
const result = this.charAt(0).toUpperCase() + this.slice(1).toLowerCase()
|
|
803
|
+
return result
|
|
804
|
+
}
|
|
805
|
+
})
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
|
|
809
|
+
// interface String {
|
|
810
|
+
//
|
|
811
|
+
// readonly capitalizedString: string;
|
|
812
|
+
//
|
|
813
|
+
// }
|
|
814
|
+
|
|
815
|
+
|
|
816
|
+
if ("numericalValue" in String.prototype == NO) {
|
|
817
|
+
Object.defineProperty(String.prototype, "numericalValue", {
|
|
818
|
+
get: function numericalValue(this: string) {
|
|
819
|
+
const result = Number(this)
|
|
820
|
+
return result
|
|
821
|
+
}
|
|
822
|
+
})
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
|
|
826
|
+
// interface String {
|
|
827
|
+
//
|
|
828
|
+
// readonly numericalValue: number;
|
|
829
|
+
//
|
|
830
|
+
// }
|
|
831
|
+
|
|
832
|
+
|
|
833
|
+
if ("isAString" in String.prototype == NO) {
|
|
834
|
+
|
|
835
|
+
(String.prototype as any).isAString = YES
|
|
836
|
+
|
|
837
|
+
}
|
|
838
|
+
|
|
839
|
+
|
|
840
|
+
// interface String {
|
|
841
|
+
//
|
|
842
|
+
// isAString: boolean;
|
|
843
|
+
//
|
|
844
|
+
// }
|
|
845
|
+
|
|
846
|
+
|
|
847
|
+
if ("isANumber" in Number.prototype == NO) {
|
|
848
|
+
|
|
849
|
+
(Number.prototype as any).isANumber = YES
|
|
850
|
+
|
|
851
|
+
}
|
|
852
|
+
|
|
853
|
+
|
|
854
|
+
// interface Number {
|
|
855
|
+
//
|
|
856
|
+
// isANumber: boolean;
|
|
857
|
+
//
|
|
858
|
+
// }
|
|
859
|
+
|
|
860
|
+
|
|
861
|
+
|
|
862
|
+
|
|
863
|
+
|
|
864
|
+
if ("integerValue" in Number.prototype == NO) {
|
|
865
|
+
Object.defineProperty(Number.prototype, "integerValue", {
|
|
866
|
+
get: function (this: number) {
|
|
867
|
+
const result = parseInt("" + (Math.round(this) + 0.5))
|
|
868
|
+
return result
|
|
869
|
+
}
|
|
870
|
+
})
|
|
871
|
+
}
|
|
872
|
+
|
|
873
|
+
|
|
874
|
+
// interface Number {
|
|
875
|
+
//
|
|
876
|
+
// readonly integerValue: number;
|
|
877
|
+
//
|
|
878
|
+
// }
|
|
879
|
+
|
|
880
|
+
|
|
881
|
+
|
|
882
|
+
export class PrimitiveNumber {
|
|
883
|
+
|
|
884
|
+
// @ts-ignore
|
|
885
|
+
static [Symbol.hasInstance](x) {
|
|
886
|
+
return
|
|
887
|
+
}
|
|
888
|
+
|
|
889
|
+
}
|
|
890
|
+
|
|
891
|
+
|
|
892
|
+
if ("integerValue" in Boolean.prototype == NO) {
|
|
893
|
+
|
|
894
|
+
Object.defineProperty(Boolean.prototype, "integerValue", {
|
|
895
|
+
get: function (this: boolean) {
|
|
896
|
+
|
|
897
|
+
if (this == true) {
|
|
898
|
+
|
|
899
|
+
return 1
|
|
900
|
+
|
|
901
|
+
}
|
|
902
|
+
|
|
903
|
+
return 0
|
|
904
|
+
|
|
905
|
+
}
|
|
906
|
+
})
|
|
907
|
+
|
|
908
|
+
}
|
|
909
|
+
|
|
910
|
+
|
|
911
|
+
// interface Boolean {
|
|
912
|
+
//
|
|
913
|
+
// readonly integerValue: number;
|
|
914
|
+
//
|
|
915
|
+
// }
|
|
916
|
+
|
|
917
|
+
|
|
918
|
+
if ("dateString" in Date.prototype == NO) {
|
|
919
|
+
|
|
920
|
+
Object.defineProperty(Date.prototype, "dateString", {
|
|
921
|
+
get: function dateString(this: Date) {
|
|
922
|
+
|
|
923
|
+
const result = ("0" + this.getDate()).slice(-2) + "-" + ("0" + (this.getMonth() + 1)).slice(-2) + "-" +
|
|
924
|
+
this.getFullYear() + " " + ("0" + this.getHours()).slice(-2) + ":" +
|
|
925
|
+
("0" + this.getMinutes()).slice(-2)
|
|
926
|
+
|
|
927
|
+
return result
|
|
928
|
+
|
|
929
|
+
}
|
|
930
|
+
})
|
|
931
|
+
|
|
932
|
+
|
|
933
|
+
|
|
934
|
+
}
|
|
935
|
+
|
|
936
|
+
|
|
937
|
+
// interface Date {
|
|
938
|
+
//
|
|
939
|
+
// readonly dateString: string;
|
|
940
|
+
//
|
|
941
|
+
// }
|
|
942
|
+
|
|
943
|
+
|
|
944
|
+
|
|
945
|
+
|
|
946
|
+
|
|
947
|
+
|
|
948
|
+
|
|
949
|
+
|