@hpcc-js/util 2.45.0 → 2.46.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.
Files changed (79) hide show
  1. package/LICENSE +43 -43
  2. package/dist/index.js +2290 -2289
  3. package/dist/index.js.map +1 -1
  4. package/dist/index.min.js +1 -1
  5. package/dist/index.min.js.map +1 -1
  6. package/lib-es6/__package__.js +3 -3
  7. package/lib-es6/array.js +84 -84
  8. package/lib-es6/array.js.map +1 -1
  9. package/lib-es6/cache.js +60 -60
  10. package/lib-es6/debounce.js +85 -85
  11. package/lib-es6/dictionary.js +61 -61
  12. package/lib-es6/dispatch.js +101 -101
  13. package/lib-es6/esp.js +32 -32
  14. package/lib-es6/graph.js +348 -348
  15. package/lib-es6/graph.js.map +1 -1
  16. package/lib-es6/graph2.js +603 -603
  17. package/lib-es6/graph2.js.map +1 -1
  18. package/lib-es6/hashSum.js +49 -49
  19. package/lib-es6/immutable.js +54 -54
  20. package/lib-es6/index.js +21 -21
  21. package/lib-es6/logging.js +177 -177
  22. package/lib-es6/logging.js.map +1 -1
  23. package/lib-es6/math.js +90 -90
  24. package/lib-es6/object.js +121 -121
  25. package/lib-es6/object.js.map +1 -1
  26. package/lib-es6/observer.js +79 -79
  27. package/lib-es6/platform.js +17 -17
  28. package/lib-es6/saxParser.js +125 -125
  29. package/lib-es6/stack.js +41 -41
  30. package/lib-es6/stateful.js +170 -170
  31. package/lib-es6/string.js +22 -22
  32. package/lib-es6/url.js +32 -32
  33. package/lib-es6/url.js.map +1 -1
  34. package/package.json +6 -21
  35. package/src/__package__.ts +2 -2
  36. package/src/array.ts +98 -98
  37. package/src/cache.ts +65 -65
  38. package/src/debounce.ts +88 -88
  39. package/src/dictionary.ts +69 -69
  40. package/src/dispatch.ts +119 -119
  41. package/src/esp.ts +32 -32
  42. package/src/graph.ts +353 -353
  43. package/src/graph2.ts +661 -661
  44. package/src/hashSum.ts +55 -55
  45. package/src/immutable.ts +57 -57
  46. package/src/index.ts +21 -21
  47. package/src/logging.ts +211 -211
  48. package/src/math.ts +92 -92
  49. package/src/object.ts +117 -117
  50. package/src/observer.ts +91 -91
  51. package/src/platform.ts +20 -20
  52. package/src/saxParser.ts +135 -135
  53. package/src/stack.ts +41 -41
  54. package/src/stateful.ts +178 -178
  55. package/src/string.ts +21 -21
  56. package/src/url.ts +27 -27
  57. package/types/__package__.d.ts +3 -3
  58. package/types/array.d.ts +13 -13
  59. package/types/cache.d.ts +20 -20
  60. package/types/debounce.d.ts +12 -12
  61. package/types/dictionary.d.ts +20 -20
  62. package/types/dispatch.d.ts +26 -26
  63. package/types/esp.d.ts +1 -1
  64. package/types/graph.d.ts +73 -73
  65. package/types/graph2.d.ts +111 -111
  66. package/types/hashSum.d.ts +1 -1
  67. package/types/immutable.d.ts +2 -2
  68. package/types/index.d.ts +21 -21
  69. package/types/logging.d.ts +57 -57
  70. package/types/math.d.ts +70 -70
  71. package/types/object.d.ts +48 -48
  72. package/types/observer.d.ts +18 -18
  73. package/types/platform.d.ts +5 -5
  74. package/types/saxParser.d.ts +28 -28
  75. package/types/stack.d.ts +28 -28
  76. package/types/stateful.d.ts +33 -33
  77. package/types/string.d.ts +2 -2
  78. package/types/url.d.ts +2 -2
  79. package/types-3.4/__package__.d.ts +2 -2
package/src/debounce.ts CHANGED
@@ -1,88 +1,88 @@
1
- import { hashSum } from "./hashSum";
2
-
3
- export function debounce<R extends Promise<any>>(fn: () => R, timeout?: number): () => R;
4
- export function debounce<P1, R extends Promise<any>>(fn: (param1: P1) => R, timeout?: number): (param1: P1) => R;
5
- export function debounce<P1, P2, R extends Promise<any>>(fn: (param1: P1, param2: P2) => R, timeout?: number): (param1: P1, param2: P2) => R;
6
- export function debounce<P1, P2, P3, R extends Promise<any>>(fn: (param1: P1, param2: P2, param3: P3) => R, timeout?: number): (param1: P1, param2: P2, param3: P3) => R;
7
- export function debounce<P1, P2, P3, P4, R extends Promise<any>>(fn: (param1: P1, param2: P2, param3: P3, param4: P4) => R, timeout?: number): (param1: P1, param2: P2, param3: P3, param4: P4) => R;
8
- export function debounce<TParam, R extends Promise<any>>(fn: (...params: TParam[]) => R, timeout?: number): (...params: TParam[]) => R {
9
- const promises: { [key: string]: { promise: R, clockStart: number } | null } = {};
10
-
11
- return (...params) => {
12
- const hash = hashSum(params);
13
- if (!promises[hash]) {
14
- promises[hash] = {
15
- clockStart: Date.now(),
16
- promise: fn(...params).then(response => {
17
- if (timeout === undefined) {
18
- promises[hash] = null;
19
- } else {
20
- setTimeout(() => {
21
- promises[hash] = null;
22
- }, Math.max(timeout - (Date.now() - promises[hash]!.clockStart), 0));
23
- }
24
- return response;
25
- }).catch(e => {
26
- promises[hash] = null;
27
- throw e;
28
- }) as R
29
- };
30
- }
31
- return promises[hash]!.promise;
32
- };
33
- }
34
-
35
- export function promiseTimeout<T>(ms: number, promise: Promise<T>): Promise<T> {
36
- let id: number;
37
- const timeout = new Promise((resolve, reject) => {
38
- id = setTimeout(() => {
39
- clearTimeout(id);
40
- reject("Timed out in " + ms + "ms.");
41
- }, ms);
42
- });
43
-
44
- return Promise.race([
45
- promise,
46
- timeout
47
- ]).then((response: T) => {
48
- clearTimeout(id);
49
- return response;
50
- }).catch(e => {
51
- clearTimeout(id);
52
- throw e;
53
- });
54
- }
55
-
56
- export class AsyncOrderedQueue {
57
- private _q: Array<Promise<any>> = [];
58
-
59
- private isTop(p: Promise<any>): boolean {
60
- return this._q[0] === p;
61
- }
62
-
63
- push<T>(p: Promise<T>): Promise<T> {
64
- const retVal = p.then(response => {
65
- if (this.isTop(retVal)) {
66
- this._q.shift();
67
- return response;
68
- }
69
- return new Promise<T>((resolve, reject) => {
70
- const intervalHandler = setInterval(() => {
71
- if (this.isTop(retVal)) {
72
- clearInterval(intervalHandler);
73
- this._q.shift();
74
- resolve(response);
75
- }
76
- }, 20);
77
- });
78
- });
79
- this._q.push(retVal);
80
- return retVal;
81
- }
82
- }
83
-
84
- export function sleep(ms: number): Promise<void> {
85
- return new Promise(resolve => {
86
- setTimeout(() => resolve(), ms);
87
- });
88
- }
1
+ import { hashSum } from "./hashSum";
2
+
3
+ export function debounce<R extends Promise<any>>(fn: () => R, timeout?: number): () => R;
4
+ export function debounce<P1, R extends Promise<any>>(fn: (param1: P1) => R, timeout?: number): (param1: P1) => R;
5
+ export function debounce<P1, P2, R extends Promise<any>>(fn: (param1: P1, param2: P2) => R, timeout?: number): (param1: P1, param2: P2) => R;
6
+ export function debounce<P1, P2, P3, R extends Promise<any>>(fn: (param1: P1, param2: P2, param3: P3) => R, timeout?: number): (param1: P1, param2: P2, param3: P3) => R;
7
+ export function debounce<P1, P2, P3, P4, R extends Promise<any>>(fn: (param1: P1, param2: P2, param3: P3, param4: P4) => R, timeout?: number): (param1: P1, param2: P2, param3: P3, param4: P4) => R;
8
+ export function debounce<TParam, R extends Promise<any>>(fn: (...params: TParam[]) => R, timeout?: number): (...params: TParam[]) => R {
9
+ const promises: { [key: string]: { promise: R, clockStart: number } | null } = {};
10
+
11
+ return (...params) => {
12
+ const hash = hashSum(params);
13
+ if (!promises[hash]) {
14
+ promises[hash] = {
15
+ clockStart: Date.now(),
16
+ promise: fn(...params).then(response => {
17
+ if (timeout === undefined) {
18
+ promises[hash] = null;
19
+ } else {
20
+ setTimeout(() => {
21
+ promises[hash] = null;
22
+ }, Math.max(timeout - (Date.now() - promises[hash]!.clockStart), 0));
23
+ }
24
+ return response;
25
+ }).catch(e => {
26
+ promises[hash] = null;
27
+ throw e;
28
+ }) as R
29
+ };
30
+ }
31
+ return promises[hash]!.promise;
32
+ };
33
+ }
34
+
35
+ export function promiseTimeout<T>(ms: number, promise: Promise<T>): Promise<T> {
36
+ let id: number;
37
+ const timeout = new Promise((resolve, reject) => {
38
+ id = setTimeout(() => {
39
+ clearTimeout(id);
40
+ reject("Timed out in " + ms + "ms.");
41
+ }, ms);
42
+ });
43
+
44
+ return Promise.race([
45
+ promise,
46
+ timeout
47
+ ]).then((response: T) => {
48
+ clearTimeout(id);
49
+ return response;
50
+ }).catch(e => {
51
+ clearTimeout(id);
52
+ throw e;
53
+ });
54
+ }
55
+
56
+ export class AsyncOrderedQueue {
57
+ private _q: Array<Promise<any>> = [];
58
+
59
+ private isTop(p: Promise<any>): boolean {
60
+ return this._q[0] === p;
61
+ }
62
+
63
+ push<T>(p: Promise<T>): Promise<T> {
64
+ const retVal = p.then(response => {
65
+ if (this.isTop(retVal)) {
66
+ this._q.shift();
67
+ return response;
68
+ }
69
+ return new Promise<T>((resolve, reject) => {
70
+ const intervalHandler = setInterval(() => {
71
+ if (this.isTop(retVal)) {
72
+ clearInterval(intervalHandler);
73
+ this._q.shift();
74
+ resolve(response);
75
+ }
76
+ }, 20);
77
+ });
78
+ });
79
+ this._q.push(retVal);
80
+ return retVal;
81
+ }
82
+ }
83
+
84
+ export function sleep(ms: number): Promise<void> {
85
+ return new Promise(resolve => {
86
+ setTimeout(() => resolve(), ms);
87
+ });
88
+ }
package/src/dictionary.ts CHANGED
@@ -1,69 +1,69 @@
1
- export type StringAnyMap = { [key: string]: any };
2
-
3
- export class Dictionary<T> {
4
- private store: { [key: string]: T } = {};
5
-
6
- constructor(attrs?: StringAnyMap) {
7
- if (attrs) {
8
- for (const key in attrs) {
9
- this.set(key, attrs[key]);
10
- }
11
- }
12
- }
13
-
14
- set(key: string, value: T): T {
15
- const retVal: T = this.store[key];
16
- this.store[key] = value;
17
- return retVal;
18
- }
19
-
20
- get(key: string): T {
21
- return this.store[key];
22
- }
23
-
24
- has(key: string) {
25
- return this.store[key] !== undefined;
26
- }
27
-
28
- remove(key: string) {
29
- delete this.store[key];
30
- }
31
-
32
- keys(): string[] {
33
- const retVal: string[] = [];
34
- for (const key in this.store) {
35
- retVal.push(key);
36
- }
37
- return retVal;
38
- }
39
-
40
- values(): T[] {
41
- const retVal: T[] = [];
42
- for (const key in this.store) {
43
- retVal.push(this.store[key]);
44
- }
45
- return retVal;
46
- }
47
- }
48
-
49
- export class DictionaryNoCase<T> extends Dictionary<T> {
50
- constructor(attrs?: StringAnyMap) {
51
- super(attrs);
52
- }
53
-
54
- set(key: string, value: T): T {
55
- return super.set(key.toLowerCase(), value);
56
- }
57
-
58
- get(key: string): T {
59
- return super.get(key.toLowerCase());
60
- }
61
-
62
- has(key: string) {
63
- return super.has(key.toLowerCase());
64
- }
65
-
66
- remove(key: string) {
67
- return super.remove(key.toLowerCase());
68
- }
69
- }
1
+ export type StringAnyMap = { [key: string]: any };
2
+
3
+ export class Dictionary<T> {
4
+ private store: { [key: string]: T } = {};
5
+
6
+ constructor(attrs?: StringAnyMap) {
7
+ if (attrs) {
8
+ for (const key in attrs) {
9
+ this.set(key, attrs[key]);
10
+ }
11
+ }
12
+ }
13
+
14
+ set(key: string, value: T): T {
15
+ const retVal: T = this.store[key];
16
+ this.store[key] = value;
17
+ return retVal;
18
+ }
19
+
20
+ get(key: string): T {
21
+ return this.store[key];
22
+ }
23
+
24
+ has(key: string) {
25
+ return this.store[key] !== undefined;
26
+ }
27
+
28
+ remove(key: string) {
29
+ delete this.store[key];
30
+ }
31
+
32
+ keys(): string[] {
33
+ const retVal: string[] = [];
34
+ for (const key in this.store) {
35
+ retVal.push(key);
36
+ }
37
+ return retVal;
38
+ }
39
+
40
+ values(): T[] {
41
+ const retVal: T[] = [];
42
+ for (const key in this.store) {
43
+ retVal.push(this.store[key]);
44
+ }
45
+ return retVal;
46
+ }
47
+ }
48
+
49
+ export class DictionaryNoCase<T> extends Dictionary<T> {
50
+ constructor(attrs?: StringAnyMap) {
51
+ super(attrs);
52
+ }
53
+
54
+ set(key: string, value: T): T {
55
+ return super.set(key.toLowerCase(), value);
56
+ }
57
+
58
+ get(key: string): T {
59
+ return super.get(key.toLowerCase());
60
+ }
61
+
62
+ has(key: string) {
63
+ return super.has(key.toLowerCase());
64
+ }
65
+
66
+ remove(key: string) {
67
+ return super.remove(key.toLowerCase());
68
+ }
69
+ }
package/src/dispatch.ts CHANGED
@@ -1,119 +1,119 @@
1
- import { IObserverHandle } from "./observer";
2
- import { root } from "./platform";
3
-
4
- export type RquestAnimationFrame = (callback: FrameRequestCallback) => number | undefined;
5
- export type CancelAnimationFrame = (handle: number) => void | undefined;
6
-
7
- let requestAnimationFrame: RquestAnimationFrame;
8
- // let cancelAnimationFrame: CancelAnimationFrame;
9
-
10
- (function () {
11
- if (root.requestAnimationFrame) {
12
- requestAnimationFrame = root.requestAnimationFrame;
13
- // cancelAnimationFrame = root.cancelAnimationFrame;
14
- } else {
15
- let lastTime = 0;
16
- requestAnimationFrame = function (callback: FrameRequestCallback): number {
17
- const currTime = new Date().getTime();
18
- const timeToCall = Math.max(0, 16 - (currTime - lastTime));
19
- const id = setTimeout(() => callback(currTime + timeToCall), timeToCall);
20
- lastTime = currTime + timeToCall;
21
- return id;
22
- };
23
- // cancelAnimationFrame = function (handle: number): void {
24
- // clearTimeout(handle);
25
- // };
26
- }
27
- })();
28
-
29
- export class Message {
30
-
31
- get canConflate(): boolean { return false; }
32
- conflate(other: Message): boolean {
33
- return false;
34
- }
35
-
36
- void(): boolean {
37
- return false;
38
- }
39
- }
40
- type MessageConstructor<T extends Message> = new (...args: any[]) => T;
41
-
42
- export type Callback<T extends Message> = (messages: T[]) => void;
43
- export { IObserverHandle };
44
-
45
- type ObserverAdapter<T extends Message = Message> = {
46
- id: number;
47
- type?: MessageConstructor<T>;
48
- callback: Callback<T>;
49
- };
50
-
51
- export class Dispatch<T extends Message = Message> {
52
-
53
- private _observerID: number = 0;
54
- private _observers: ObserverAdapter[] = [];
55
- private _messageBuffer: T[] = [];
56
-
57
- constructor() {
58
- }
59
-
60
- private observers(): ObserverAdapter[] {
61
- return this._observers;
62
- }
63
-
64
- private messages(): T[] {
65
- const retVal: T[] = [];
66
- this._messageBuffer.forEach(msg => {
67
- if (!retVal.some(msg2 => msg2.canConflate && msg2.conflate(msg))) {
68
- retVal.push(msg);
69
- }
70
- });
71
- return retVal;
72
- }
73
-
74
- private dispatchAll() {
75
- this.dispatch(this.messages());
76
- this.flush();
77
- }
78
-
79
- private dispatch(messages: T[]) {
80
- if (messages.length === 0) return;
81
- this.observers().forEach(o => {
82
- const msgs = messages.filter(m => !m.void() && (o.type === undefined || m instanceof o.type));
83
- if (msgs.length) {
84
- o.callback(msgs);
85
- }
86
- });
87
- }
88
-
89
- hasObserver(): boolean {
90
- return this._observers.length > 0;
91
- }
92
-
93
- flush() {
94
- this._messageBuffer = [];
95
- }
96
-
97
- send(msg: T) {
98
- this.dispatch([msg]);
99
- }
100
-
101
- post(msg: T) {
102
- this._messageBuffer.push(msg);
103
- requestAnimationFrame(() => this.dispatchAll());
104
- }
105
-
106
- attach(callback: Callback<T>, type?: MessageConstructor<T>): IObserverHandle {
107
- const context = this;
108
- const id = ++this._observerID;
109
- this._observers.push({ id, type, callback });
110
- return {
111
- release() {
112
- context._observers = context._observers.filter(o => o.id !== id);
113
- },
114
- unwatch() {
115
- this.release();
116
- }
117
- };
118
- }
119
- }
1
+ import { IObserverHandle } from "./observer";
2
+ import { root } from "./platform";
3
+
4
+ export type RquestAnimationFrame = (callback: FrameRequestCallback) => number | undefined;
5
+ export type CancelAnimationFrame = (handle: number) => void | undefined;
6
+
7
+ let requestAnimationFrame: RquestAnimationFrame;
8
+ // let cancelAnimationFrame: CancelAnimationFrame;
9
+
10
+ (function () {
11
+ if (root.requestAnimationFrame) {
12
+ requestAnimationFrame = root.requestAnimationFrame;
13
+ // cancelAnimationFrame = root.cancelAnimationFrame;
14
+ } else {
15
+ let lastTime = 0;
16
+ requestAnimationFrame = function (callback: FrameRequestCallback): number {
17
+ const currTime = new Date().getTime();
18
+ const timeToCall = Math.max(0, 16 - (currTime - lastTime));
19
+ const id = setTimeout(() => callback(currTime + timeToCall), timeToCall);
20
+ lastTime = currTime + timeToCall;
21
+ return id;
22
+ };
23
+ // cancelAnimationFrame = function (handle: number): void {
24
+ // clearTimeout(handle);
25
+ // };
26
+ }
27
+ })();
28
+
29
+ export class Message {
30
+
31
+ get canConflate(): boolean { return false; }
32
+ conflate(other: Message): boolean {
33
+ return false;
34
+ }
35
+
36
+ void(): boolean {
37
+ return false;
38
+ }
39
+ }
40
+ type MessageConstructor<T extends Message> = new (...args: any[]) => T;
41
+
42
+ export type Callback<T extends Message> = (messages: T[]) => void;
43
+ export { IObserverHandle };
44
+
45
+ type ObserverAdapter<T extends Message = Message> = {
46
+ id: number;
47
+ type?: MessageConstructor<T>;
48
+ callback: Callback<T>;
49
+ };
50
+
51
+ export class Dispatch<T extends Message = Message> {
52
+
53
+ private _observerID: number = 0;
54
+ private _observers: ObserverAdapter[] = [];
55
+ private _messageBuffer: T[] = [];
56
+
57
+ constructor() {
58
+ }
59
+
60
+ private observers(): ObserverAdapter[] {
61
+ return this._observers;
62
+ }
63
+
64
+ private messages(): T[] {
65
+ const retVal: T[] = [];
66
+ this._messageBuffer.forEach(msg => {
67
+ if (!retVal.some(msg2 => msg2.canConflate && msg2.conflate(msg))) {
68
+ retVal.push(msg);
69
+ }
70
+ });
71
+ return retVal;
72
+ }
73
+
74
+ private dispatchAll() {
75
+ this.dispatch(this.messages());
76
+ this.flush();
77
+ }
78
+
79
+ private dispatch(messages: T[]) {
80
+ if (messages.length === 0) return;
81
+ this.observers().forEach(o => {
82
+ const msgs = messages.filter(m => !m.void() && (o.type === undefined || m instanceof o.type));
83
+ if (msgs.length) {
84
+ o.callback(msgs);
85
+ }
86
+ });
87
+ }
88
+
89
+ hasObserver(): boolean {
90
+ return this._observers.length > 0;
91
+ }
92
+
93
+ flush() {
94
+ this._messageBuffer = [];
95
+ }
96
+
97
+ send(msg: T) {
98
+ this.dispatch([msg]);
99
+ }
100
+
101
+ post(msg: T) {
102
+ this._messageBuffer.push(msg);
103
+ requestAnimationFrame(() => this.dispatchAll());
104
+ }
105
+
106
+ attach(callback: Callback<T>, type?: MessageConstructor<T>): IObserverHandle {
107
+ const context = this;
108
+ const id = ++this._observerID;
109
+ this._observers.push({ id, type, callback });
110
+ return {
111
+ release() {
112
+ context._observers = context._observers.filter(o => o.id !== id);
113
+ },
114
+ unwatch() {
115
+ this.release();
116
+ }
117
+ };
118
+ }
119
+ }
package/src/esp.ts CHANGED
@@ -1,32 +1,32 @@
1
- export function espTime2Seconds(duration: string): number {
2
- if (!duration) {
3
- return 0;
4
- } else {
5
- if (!isNaN(Number(duration))) {
6
- return Number(duration);
7
- }
8
- }
9
- // GH: <n>ns or <m>ms or <s>s or [<d> days ][<h>:][<m>:]<s>[.<ms>]
10
- const nsIndex = duration.indexOf("ns");
11
- if (nsIndex !== -1) {
12
- return parseFloat(duration.substr(0, nsIndex)) / 1000000000;
13
- }
14
- const msIndex = duration.indexOf("ms");
15
- if (msIndex !== -1) {
16
- return parseFloat(duration.substr(0, msIndex)) / 1000;
17
- }
18
- const sIndex = duration.indexOf("s");
19
- if (sIndex !== -1 && duration.indexOf("days") === -1) {
20
- return parseFloat(duration.substr(0, sIndex));
21
- }
22
-
23
- const dayTimeParts = duration.split(" days ");
24
- const days: number = dayTimeParts.length > 1 ? parseFloat(dayTimeParts[0]) : 0.0;
25
- const time: string = dayTimeParts.length > 1 ? dayTimeParts[1] : dayTimeParts[0];
26
- let secs = 0.0;
27
- const timeParts = time.split(":").reverse();
28
- for (let j = 0; j < timeParts.length; ++j) {
29
- secs += parseFloat(timeParts[j]) * Math.pow(60, j);
30
- }
31
- return (days * 24 * 60 * 60) + secs;
32
- }
1
+ export function espTime2Seconds(duration: string): number {
2
+ if (!duration) {
3
+ return 0;
4
+ } else {
5
+ if (!isNaN(Number(duration))) {
6
+ return Number(duration);
7
+ }
8
+ }
9
+ // GH: <n>ns or <m>ms or <s>s or [<d> days ][<h>:][<m>:]<s>[.<ms>]
10
+ const nsIndex = duration.indexOf("ns");
11
+ if (nsIndex !== -1) {
12
+ return parseFloat(duration.substr(0, nsIndex)) / 1000000000;
13
+ }
14
+ const msIndex = duration.indexOf("ms");
15
+ if (msIndex !== -1) {
16
+ return parseFloat(duration.substr(0, msIndex)) / 1000;
17
+ }
18
+ const sIndex = duration.indexOf("s");
19
+ if (sIndex !== -1 && duration.indexOf("days") === -1) {
20
+ return parseFloat(duration.substr(0, sIndex));
21
+ }
22
+
23
+ const dayTimeParts = duration.split(" days ");
24
+ const days: number = dayTimeParts.length > 1 ? parseFloat(dayTimeParts[0]) : 0.0;
25
+ const time: string = dayTimeParts.length > 1 ? dayTimeParts[1] : dayTimeParts[0];
26
+ let secs = 0.0;
27
+ const timeParts = time.split(":").reverse();
28
+ for (let j = 0; j < timeParts.length; ++j) {
29
+ secs += parseFloat(timeParts[j]) * Math.pow(60, j);
30
+ }
31
+ return (days * 24 * 60 * 60) + secs;
32
+ }