-
Notifications
You must be signed in to change notification settings - Fork 7
/
util.ts
765 lines (701 loc) · 22.6 KB
/
util.ts
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
/*
* Philip Crotwell
* University of South Carolina, 2019
* https://www.seis.sc.edu
*/
import {version } from './version';
import { DateTime, Duration, Interval, FixedOffsetZone } from "luxon";
export const XML_MIME = "application/xml";
export const JSON_MIME = "application/json";
export const JSONAPI_MIME = "application/vnd.api+json";
export const SVG_MIME = "image/svg+xml";
export const TEXT_MIME = "text/plain";
export const BINARY_MIME = "application/octet-stream";
export const UTC_OPTIONS = { zone: FixedOffsetZone.utcInstance };
export function hasArgs(value: unknown): boolean {
return arguments.length !== 0 && typeof value !== "undefined";
}
export function hasNoArgs(value: unknown): boolean {
return arguments.length === 0 || typeof value === "undefined";
}
export function isStringArg(value: unknown): value is string {
return (
arguments.length !== 0 &&
(typeof value === "string" || (isObject(value) && value instanceof String))
);
}
export function isNumArg(value: unknown): value is number {
return (
arguments.length !== 0 &&
(typeof value === "number" || (isObject(value) && value instanceof Number))
);
}
export function isNonEmptyStringArg(value: unknown): value is string {
return arguments.length !== 0 && isStringArg(value) && value.length !== 0;
}
export function isObject(obj: unknown): obj is object {
return obj !== null && typeof obj === "object";
}
//export function isDef(v: unknown): boolean {
// return typeof v !== "undefined" && v !== null;
//}
export function isDef<Value>(value: Value | undefined | null): value is Value {
return value !== null && value !== undefined;
}
export function reErrorWithMessage(err: unknown, message: string): Error {
let out: Error;
if (!isDef(err)) {
out = new Error(`${message}`);
} else if (typeof err === "string") {
out = new Error(`${message} ${err}`);
} else if (err instanceof Error) {
err.message = `${message} ${err.message}`;
out = err;
} else {
out = new Error(`${message} ${stringify(err)}`);
}
return out;
}
export interface StringDictionary {
[index: string]: unknown;
}
export function asStringDictionary(inobj: unknown): StringDictionary {
if (typeof inobj !== 'object') {
throw new Error(`Expect obj to be object, but was ${stringify(inobj)}`);
}
const obj = inobj as StringDictionary;
return obj;
}
export function doStringGetterSetter(
inobj: unknown,
field: string,
value?: string,
) {
const hiddenField = `_${field}`;
const obj = asStringDictionary(inobj);
if (hasNoArgs(value) || value === null) {
// passing no args or null effectively unsets field
obj[hiddenField] = undefined;
} else if (isStringArg(value)) {
obj[hiddenField] = value;
} else {
throw new Error(
`${field} value argument is optional or string, but was type ${typeof value}, '${value}' `,
);
}
return inobj;
}
export function doBoolGetterSetter(
inobj: unknown,
field: string,
value?: boolean,
) {
const hiddenField = `_${field}`;
const obj = asStringDictionary(inobj);
if (hasNoArgs(value) || value === null) {
// passing no args or null effectively unsets field
obj[hiddenField] = undefined;
} else if (value === true || value === false) {
obj[hiddenField] = value;
} else {
throw new Error(
`${field} value argument is optional or boolean, but was type ${typeof value}, '${value}' `,
);
}
return inobj;
}
export function doIntGetterSetter(
inobj: unknown,
field: string,
value?: number,
) {
const hiddenField = `_${field}`;
const obj = asStringDictionary(inobj);
if (hasNoArgs(value) || value === null) {
// passing no args or null effectively unsets field
obj[hiddenField] = undefined;
} else if (isNumArg(value)) {
obj[hiddenField] = value;
} else if (isStringArg(value) && Number.isFinite(Number(value))) {
obj[hiddenField] = parseInt(value);
} else {
throw new Error(
`${field} value argument is optional or number, but was type ${typeof value}, '${value}' `,
);
}
return inobj;
}
export function doFloatGetterSetter(
inobj: unknown,
field: string,
value?: number,
) {
const hiddenField = `_${field}`;
const obj = asStringDictionary(inobj);
if (hasNoArgs(value) || value === null) {
// passing no args or null effectively unsets field
obj[hiddenField] = undefined;
} else if (isNumArg(value)) {
obj[hiddenField] = value;
} else if (isStringArg(value) && Number.isFinite(Number(value))) {
obj[hiddenField] = parseFloat(value);
} else {
throw new Error(
`value argument is optional or number, but was type ${typeof value}, '${value}' `,
);
}
return obj;
}
export function doMomentGetterSetter(
inobj: unknown,
field: string,
value?: DateTime | string,
) {
const hiddenField = `_${field}`;
const obj = asStringDictionary(inobj);
if (hasNoArgs(value) || value === null) {
// passing no args or null effectively unsets field
obj[hiddenField] = undefined;
} else if (isDef(value) && isObject(value) && DateTime.isDateTime(value)) {
obj[hiddenField] = value;
} else if (isDef(value) && DateTime.isDateTime(checkStringOrDate(value))) {
obj[hiddenField] = checkStringOrDate(value);
} else {
throw new Error(
`${field} value argument is optional, DateTime, date or date string, but was type ${typeof value}, '${stringify(
value,
)}' `,
);
}
return obj;
}
/**
* Converts entire DataView to a string as utf-8.
*
* @param dataView bytes to convert
* @returns the string
*/
export function dataViewToString(dataView: DataView): string {
let out = "";
for (let i = 0; i < dataView.byteLength; i++) {
out += String.fromCharCode(dataView.getUint8(i));
}
return out;
}
/**
* Log a message to the console. Put here to limit lint console errors
* for the times we really do want to use console.log. Will also append a
* p tag to a div#debug if it exists.
*
* @param msg the message to log
*/
export function log(msg: string): void {
// eslint-disable-next-line no-console
if (console) {
// eslint-disable-next-line no-console
console.log(`${stringify(msg)}`);
}
if (typeof document !== "undefined" && document !== null) {
const p = document.createElement("p");
p.textContent = `${stringify(msg)}`;
const divDebug = (document.querySelector("div#debug") as HTMLInputElement);
if (isDef(divDebug)) {
divDebug.appendChild(p);
}
}
}
/**
* typescript-y check if Error.
*
* @param error object that might be an Error
* @returns true if Error object
*/
export function isError(error: unknown): error is Error {
return (
typeof error === 'object' &&
error !== null &&
error instanceof Error
);
}
/**
* typescript-y convert errors.
*
* @param maybeError obejct that might be an Error object
* @returns an Error object
*/
export function toError(maybeError: unknown): Error {
if (isError(maybeError)) return maybeError;
try {
return new Error(JSON.stringify(maybeError));
} catch {
// fallback in case there's an error stringifying the maybeError
// like with circular references for example.
return new Error(String(maybeError));
}
}
/**
* Log a warning message to the console. Put here to limit lint console errors
* for the times we really do want to use console.log. Will also append a
* p tag to a div#debug if it exists.
*
* @param msg the message to log
*/
export function warn(msg: string): void {
// eslint-disable-next-line no-console
if (console) {
// eslint-disable-next-line no-console
console.assert(false, `${stringify(msg)}`);
}
if (typeof document !== "undefined" && document !== null) {
const p = document.createElement("p");
p.textContent = `${stringify(msg)}`;
(document.querySelector("div#debug") as HTMLInputElement)
.appendChild(p);
}
}
/**
* String representation of input. This is kind of dumb but makes
* flow happier.
*
* @param value any kind of thing that can be turned into a string
* @returns a string
*/
export function stringify(value: unknown): string {
if (typeof value === "string") {
return value;
} else if (typeof value === "number") {
return value.toString();
} else if (typeof value === "boolean") {
return value ? "true" : "false";
} else if (typeof value === "undefined") {
return "undefined";
} else if (typeof value === "function") {
return "function " + value.name;
} else if (typeof value === "object") {
if (value) {
if (DateTime.isDateTime(value)) {
const dateTimeValue = (value as unknown) as DateTime;
// typescript null check
const s = dateTimeValue.toISO();
return (dateTimeValue.isValid && s) ? s : `Invalid DateTime: ${dateTimeValue.invalidReason}: ${dateTimeValue.invalidExplanation}`;
} else {
return `${value?.constructor?.name} ${String(value)}`;
}
//} else if (typeof value === 'symbol') {
// return value.toString();
} else {
return `${value}`;
}
} else {
return "<unknown" + typeof value + "???>";
}
}
export function isoToDateTime(val: string): DateTime {
if (val.toLowerCase() === "now") {
return DateTime.utc();
}
return DateTime.fromISO(val, UTC_OPTIONS);
}
/**
* Create a luxon Interval from a start and end.
*
* @param start start of the interval as iso string or DateTime
* @param end end of the interval as string or DateTime
* @returns the interval
*/
export function startEnd(start: string | DateTime,
end: string | DateTime): Interval {
if (isStringArg(start)) {
start = isoToDateTime(start);
}
if (isStringArg(end)) {
end = isoToDateTime(end);
}
return Interval.fromDateTimes(start, end);
}
/**
* Create a luxon Interval from a start and a duration. If the duration is negative, the
* start time will become the end time. This differs from luxon Interval.after which
* will return an invalid Interval instead.
*
* @param start start of the interval as iso string or DateTime
* @param duration duration of the interval as iso string, number of seconds, or Duration
* @returns the interval
*/
export function startDuration(start: string | DateTime,
duration: string | Duration | number): Interval {
if (isStringArg(start)) {
start = isoToDateTime(start);
}
if (isStringArg(duration)) {
duration = Duration.fromISO(duration);
} else if (isNumArg(duration)) {
duration = Duration.fromMillis(1000 * duration);
}
if (duration.valueOf() < 0) {
return Interval.before(start, duration.negate());
} else {
return Interval.after(start, duration);
}
}
/**
* Create a luxon Interval from a duration and a end. If the duration is negative, the
* end time will become the start time. This differs from luxon Interval.before which
* will return an invalid Interval instead.
*
* @param duration duration of the interval as iso string, number of seconds, or Duration
* @param end end of the interval as string or DateTime
* @returns the interval
*/
export function durationEnd(duration: string | Duration | number,
end: string | DateTime): Interval {
if (isStringArg(end)) {
end = isoToDateTime(end);
}
if (isStringArg(duration)) {
duration = Duration.fromISO(duration);
} else if (isNumArg(duration)) {
duration = Duration.fromMillis(1000 * duration);
}
if (duration.valueOf() < 0) {
return Interval.after(end, duration.negate());
} else {
return Interval.before(end, duration);
}
}
/**
* Calculates offset of remote server versus local time. It is assumed that the
* argument was acquired as close in time to calling this as possible.
*
* @param serverTimeUTC now as reported by remote server
* @returns offset in seconds to now on local machine
*/
export function calcClockOffset(serverTimeUTC: DateTime): number {
return DateTime.utc().diff(serverTimeUTC).toMillis() * 1000.0;
}
export const WAY_FUTURE: DateTime = DateTime.fromISO("2500-01-01T00:00:00Z");
/**
* converts the input value is a DateTime, throws Error if not
* a string, Date or DateTime. Zero length string or "now" return
* current time.
*
* @param d 'now', string time, Date, number of milliseconds since epoch, or DateTime
* @returns DateTime created from argument
*/
export function checkStringOrDate(d: string | Date | DateTime): DateTime {
if (DateTime.isDateTime(d)) {
return d;
} else if (d instanceof Date) {
return DateTime.fromJSDate(d, UTC_OPTIONS);
} else if (isNumArg(d)) {
return DateTime.fromMillis(d, UTC_OPTIONS);
} else if (isNonEmptyStringArg(d)) {
const lc = d.toLowerCase();
if (d.length === 0 || lc === "now") {
return DateTime.utc();
} else {
return isoToDateTime(d);
}
}
throw new Error(`unknown date type: ${stringify(d)} ${typeof d}`);
}
/**
* Converts name and value into a html query parameter, with appending ampersand.
*
* @param name parameter name
* @param val parameter value
* @returns formated query parameter
*/
export function makeParam(name: string, val: unknown): string {
return `${name}=${encodeURIComponent(stringify(val))}&`;
}
/**
* Converts name and value into a parameter line, with appending newline,
* for including in POST body.
*
* @param name parameter name
* @param val parameter value
* @returns formated query parameter
*/
export function makePostParam(name: string, val: unknown): string {
return name + "=" + stringify(val) + "\n";
}
/**
* converts to ISO8601 but removes the trailing Z as FDSN web services
* do not allow that.
*
* @param date DateTime to convert to string
* @returns ISO8601 without timezone Z
*/
export function toIsoWoZ(date: DateTime): string {
if (date.isValid) {
let out = date.toISO();
if (out == null) { throw new Error(`Bad date: ${stringify(date)}`); }
if (out.endsWith('Z')) {
out = out.substring(0, out.length - 1);
}
return out;
} else {
throw new Error(`${date.invalidReason}: ${date.invalidExplanation}`);
}
}
/**
* Extracts a valid starting DateTime from interval.
* Throws Error if interval is not valid.
* @param interval luxon Interval
* @returns start DateTime
*/
export function validStartTime(interval: Interval): DateTime {
const d = interval.start;
if (d == null) { throw new Error(`Bad interval: ${stringify(interval)}`); }
return d;
}
/**
* Extracts a valid ending DateTime from interval.
* Throws Error if interval is not valid.
* @param interval luxon Interval
* @returns end DateTime
*/
export function validEndTime(interval: Interval): DateTime {
const d = interval.end;
if (d == null) { throw new Error(`Bad interval: ${stringify(interval)}`); }
return d;
}
/**
* Converts a luxon DateTime to a Javascript Date, checking for null,
* undefined and isValid first. Throws Error in that case.
*
* @param d luxon DateTime
* @returns Javascript Date
*/
export function toJSDate(d: DateTime | null | undefined) {
if (!d) {
throw new Error(`Null/undef DateTime: ${d}`);
}
if (!d.isValid) {
throw new Error(`${d.invalidReason}: ${d.invalidExplanation}`);
}
return d.toJSDate();
}
/**
* Check a Luxon DateTime, Interval or Duration for valid.
* Throws Error if not. THis is to avoid globally setting
* luxon's Settings.throwOnInvalid = true;
* but still throw/catch on invalid dates.
* @param d luxon object
* @param msg optional message to add to error
* @returns passed in object if valid
*/
export function checkLuxonValid(d: null | DateTime | Interval | Duration, msg?: string) {
if (d == null) {
const m = msg ? msg : "";
throw new Error(`Null luxon value: ${d} ${m}`);
}
if (!d.isValid) {
const m = msg ? msg : "";
throw new Error(`Invalid Luxon: ${typeof d} ${d.constructor.name} ${d.invalidReason}: ${d.invalidExplanation} ${m}`);
}
return d;
}
/**
* @returns the protocol, http: or https: for the document if possible.
* Note this includes the colon.
*/
export function checkProtocol(): string {
let _protocol = "http:";
if (
typeof document !== "undefined" &&
document !== null &&
"location" in document &&
"protocol" in document.location &&
"https:" === document.location.protocol
) {
_protocol = "https:";
}
return _protocol;
}
export interface FetchInitObject {
cache: string;
redirect: string;
mode: string;
referrer: string;
// [index: string]: string | Record<string, string>;
headers: Record<string, string>;
signal?: AbortSignal;
}
/**
* Create default fetch init object with the given mimeType. Sets
* no-cache, follow redirects, cors mode, referrer as seisplotjs and
* mimetype as a header. Note that redirect with POST may fail due to
* POST being changed to GET on a 301. Fetching with POST may wish
* to use redirect: "manual" to handle the 301 correctly by POSTing to
* the new URL.
*
*
* @param mimeType requested mime type
* @returns object with fetch configuration parameters
*/
export function defaultFetchInitObj(mimeType?: string): RequestInit {
const headers: Record<string, string> = {};
if (isStringArg(mimeType)) {
headers.Accept = mimeType;
}
return {
cache: "no-cache",
redirect: "follow",
mode: "cors",
referrer: "seisplotjs",
headers: headers,
};
}
export function cloneFetchInitObj(fetchInit: RequestInit): RequestInit {
const out = {};
if (fetchInit) {
for (const [key, value] of Object.entries(fetchInit)) {
if (Array.isArray(value)) {
// @ts-expect-error
out[key] = value.slice();
} else {
// @ts-expect-error
out[key] = value;
}
}
}
return out;
}
/**
* Does a fetch, but times out if it takes too long.
*
* @param url url to retrieve
* @param fetchInit fetch configuration, initialization
* @param timeoutSec maximum time to wait in seconds
* @returns promise to the result
* @throws Error if time out or other failure
*/
export function doFetchWithTimeout(
url: string | URL,
fetchInit?: RequestInit,
timeoutSec?: number,
): Promise<Response> {
const controller = new AbortController();
const signal = controller.signal;
let internalFetchInit = isDef(fetchInit) ? fetchInit : defaultFetchInitObj();
internalFetchInit = cloneFetchInitObj(internalFetchInit);
if (internalFetchInit.redirect === "follow" && internalFetchInit.method === "POST") {
// follow on POST is dangerous if the server returns 301, handle it ourselves
// note this is assuming that the redirect is a simple http -> https.
internalFetchInit.redirect = "manual";
}
if (!isDef(timeoutSec)) {
timeoutSec = 30;
}
setTimeout(() => controller.abort(), timeoutSec * 1000);
internalFetchInit.signal = signal;
let absoluteUrl: URL;
if (url instanceof URL) {
absoluteUrl = url;
} else if (isStringArg(url)) {
if (url.startsWith("http://") || url.startsWith("https://")) {
absoluteUrl = new URL(url);
} else {
absoluteUrl = new URL(url, document.URL);
}
} else {
throw new Error(`url must be string or URL, ${stringify(url)}`);
}
log(
`attempt to fetch ${internalFetchInit.method ? internalFetchInit.method : ""} ${stringify(
absoluteUrl,
)}`,
);
return fetch(absoluteUrl.href, internalFetchInit)
.catch(err => {
log("fetch failed, possible CORS or PrivacyBadger or NoScript?");
throw err;
})
.then(function(response) {
if (response.ok || response.status === 404) {
return response;
} else if (response.status >= 300 && response.status <= 399) {
if (checkProtocol() === 'http:' && absoluteUrl.href.startsWith("http://")) {
// maybe try https just in case
const httpsUrl = new URL(`https://${absoluteUrl.href.slice(7)}`);
const method = internalFetchInit.method ? internalFetchInit.method : "";
log(`attempt fetch redirect ${response.status} ${method} to ${stringify(httpsUrl)}`);
return fetch(httpsUrl.href, internalFetchInit).then(httpsResponse => {
if (httpsResponse.ok || httpsResponse.status === 404) {
return httpsResponse;
} else {
return response.text().then(text => {
throw new Error(
`fetch response was redirect for http and failed for https. ${response.ok} ${response.status}, ${httpsResponse.ok} ${httpsResponse.status} \n${text}`,
);
});
}
});
}
}
return response.text().then(text => {
throw new Error(
`fetch response was not ok. ${response.ok} ${response.status}\n${text}`,
);
});
});
}
/**
* Allows downloading of in memory data, as ArrayBuffer, to file as if
* the user clicked a download link.
*
* @param data ArrayBuffer to download
* @param filename default filename
* @param mimeType mimeType, default application/octet-stream
*/
export function downloadBlobAsFile(data: ArrayBuffer, filename: string, mimeType = 'application/octet-stream') {
if (!data) {
throw new Error("data is empty");
}
if (!filename) filename = 'filetodownload.txt';
const blob = new Blob([data], { type: mimeType });
const e = document.createEvent('MouseEvents');
const a = document.createElement('a');
a.download = filename;
a.href = window.URL.createObjectURL(blob);
a.dataset.downloadurl = [mimeType, a.download, a.href].join(':');
e.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
a.dispatchEvent(e);
}
/**
* Recursively calculates the mean of a slice of an array. This helps with
* very long seismograms to equally weight each sample point without overflowing.
*
* @param dataSlice slice of a seismogram
* @param totalPts number of points in the original seismogram
* @returns sum of slice data points divided by totalPts
*/
export function meanOfSlice(
dataSlice: Int32Array | Float32Array | Float64Array,
totalPts: number,
): number {
if (dataSlice.length < 8) {
// @ts-expect-error
return dataSlice.reduce(function(acc: number, val: number): number {
return acc + val;
}, 0) / totalPts;
} else {
const byTwo = Math.floor(dataSlice.length / 2);
return (
meanOfSlice(dataSlice.slice(0, byTwo), totalPts) +
meanOfSlice(dataSlice.slice(byTwo, dataSlice.length), totalPts)
);
}
}
export const SVG_NS = "http://www.w3.org/2000/svg";
export const XHTML_NS = "http://www.w3.org/1999/xhtml";
export function createSVGElement(name: string): SVGElement {
return document.createElementNS(SVG_NS, name);
}
export function updateVersionText(selector = "#sp-version") {
document.querySelectorAll(selector).forEach( el => {
el.textContent = version;
});
}