@journeyapps-labs/lib-reactor-utils 1.0.0

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 (47) hide show
  1. package/LICENSE +201 -0
  2. package/dist/@types/BaseObserver.d.ts +14 -0
  3. package/dist/@types/Disposable.d.ts +3 -0
  4. package/dist/@types/EventEmitter.d.ts +16 -0
  5. package/dist/@types/Logger.d.ts +16 -0
  6. package/dist/@types/Mutex.d.ts +78 -0
  7. package/dist/@types/ReactorPath.d.ts +15 -0
  8. package/dist/@types/Validators.d.ts +3 -0
  9. package/dist/@types/async-throttle.d.ts +12 -0
  10. package/dist/@types/clipboard.d.ts +1 -0
  11. package/dist/@types/color.d.ts +23 -0
  12. package/dist/@types/dates.d.ts +41 -0
  13. package/dist/@types/file-input.d.ts +14 -0
  14. package/dist/@types/index.d.ts +14 -0
  15. package/dist/@types/retries.d.ts +1 -0
  16. package/dist/@types/string-manipulation.d.ts +10 -0
  17. package/dist/BaseObserver.js +34 -0
  18. package/dist/BaseObserver.js.map +1 -0
  19. package/dist/Disposable.js +3 -0
  20. package/dist/Disposable.js.map +1 -0
  21. package/dist/EventEmitter.js +44 -0
  22. package/dist/EventEmitter.js.map +1 -0
  23. package/dist/Logger.js +48 -0
  24. package/dist/Logger.js.map +1 -0
  25. package/dist/Mutex.js +274 -0
  26. package/dist/Mutex.js.map +1 -0
  27. package/dist/ReactorPath.js +61 -0
  28. package/dist/ReactorPath.js.map +1 -0
  29. package/dist/Validators.js +27 -0
  30. package/dist/Validators.js.map +1 -0
  31. package/dist/async-throttle.js +50 -0
  32. package/dist/async-throttle.js.map +1 -0
  33. package/dist/clipboard.js +17 -0
  34. package/dist/clipboard.js.map +1 -0
  35. package/dist/color.js +102 -0
  36. package/dist/color.js.map +1 -0
  37. package/dist/dates.js +95 -0
  38. package/dist/dates.js.map +1 -0
  39. package/dist/file-input.js +87 -0
  40. package/dist/file-input.js.map +1 -0
  41. package/dist/index.js +18 -0
  42. package/dist/index.js.map +1 -0
  43. package/dist/retries.js +34 -0
  44. package/dist/retries.js.map +1 -0
  45. package/dist/string-manipulation.js +25 -0
  46. package/dist/string-manipulation.js.map +1 -0
  47. package/package.json +39 -0
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2025 Journey Mobile, Inc.
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,14 @@
1
+ export interface BaseObserverInterface<T extends BaseListener> {
2
+ registerListener(listener: Partial<T>): () => void;
3
+ iterateListeners(cb: (listener: Partial<T>) => any): any;
4
+ }
5
+ export interface BaseListener {
6
+ }
7
+ export declare class BaseObserver<T extends BaseListener> implements BaseObserverInterface<T> {
8
+ protected listeners: Map<string, Partial<T>>;
9
+ constructor();
10
+ get _listenerSize(): number;
11
+ registerListener(listener: Partial<T>): () => void;
12
+ iterateListeners(cb: (listener: Partial<T>) => any): void;
13
+ iterateAsyncListeners(cb: (listener: Partial<T>) => Promise<any>): Promise<void>;
14
+ }
@@ -0,0 +1,3 @@
1
+ export interface Disposable {
2
+ dispose(): any;
3
+ }
@@ -0,0 +1,16 @@
1
+ import { Disposable } from './Disposable';
2
+ export type SubscriberCallback<E> = (event: E) => void;
3
+ export type Subscriber<E> = {
4
+ id: string;
5
+ handler: SubscriberCallback<E>;
6
+ };
7
+ /**
8
+ * Not to be confused with node's EventEmitter. This is a typed emitter
9
+ */
10
+ export declare class EventEmitter<E> implements Disposable {
11
+ subscribers: Subscriber<E>[];
12
+ private unsubscribe;
13
+ subscribe(handler: SubscriberCallback<E>): Disposable;
14
+ emit(event: E): void;
15
+ dispose(): void;
16
+ }
@@ -0,0 +1,16 @@
1
+ export declare enum LogLevel {
2
+ INFO = "info",
3
+ DEBUG = "debug",
4
+ ERROR = "error",
5
+ WARN = "warn"
6
+ }
7
+ export declare class Logger {
8
+ name: string;
9
+ constructor(name: string);
10
+ protected log(level: LogLevel, d: any[]): void;
11
+ debug(...args: any): void;
12
+ info(...args: any): void;
13
+ error(...args: any): void;
14
+ warn(...args: any): void;
15
+ }
16
+ export declare const createLogger: (name: string) => Logger;
@@ -0,0 +1,78 @@
1
+ export type PromiseFunction<T> = (context: MutexContext) => Promise<T>;
2
+ export type SharedPromiseFunction<T> = (context: SharedMutexContext) => Promise<T>;
3
+ export interface SharedMutexContext {
4
+ sharedLock<T>(promiseFn: SharedPromiseFunction<T>): Promise<T>;
5
+ }
6
+ export interface MutexContext extends SharedMutexContext {
7
+ exclusiveLock<T>(promiseFn: PromiseFunction<T>): Promise<T>;
8
+ }
9
+ /**
10
+ * Mutex maintains a queue of Promise-returning functions that
11
+ * are executed sequentially (whereas normally they would execute their async code concurrently).
12
+ */
13
+ export declare class Mutex implements MutexContext {
14
+ private queue;
15
+ private sharedCount;
16
+ private exclusiveLocked;
17
+ private emptyQueuePromise;
18
+ private emptyQueueResolve?;
19
+ constructor();
20
+ /**
21
+ * Returns true if no locks are held: the queue is empty, and no tasks are being executed.
22
+ */
23
+ isFree(): boolean;
24
+ /**
25
+ * Resolves when no lock is being held: the queue is empty, and no tasks are being executed.
26
+ */
27
+ waitUntilFree(): Promise<void>;
28
+ /**
29
+ * Place a function on the queue.
30
+ * The function may either return a Promise or a value.
31
+ * Return a Promise that is resolved with the result of the function.
32
+ */
33
+ exclusiveLock<T>(promiseFn: PromiseFunction<T>): Promise<T>;
34
+ /**
35
+ * Place a function on the queue.
36
+ * This function may execute in parallel with other "multi" functions, but not with other functions on the exclusive
37
+ * queue.
38
+ */
39
+ sharedLock<T>(promiseFn: SharedPromiseFunction<T>): Promise<T>;
40
+ private lock;
41
+ /**
42
+ * Convert a normal Promise-returning function into one that is automatically enqueued.
43
+ * The signature of the function stays the same - only the execution is potentially delayed.
44
+ * The only exception is that if the function would have returned a scalar value, it now
45
+ * returns a Promise.
46
+ */
47
+ qu<T extends (...args: any[]) => Promise<any>>(fn: T): T;
48
+ /**
49
+ * Like qu, but ensures there is never more than one function on
50
+ * the queue. Note that there may be one running as well as one
51
+ * on the queue.
52
+ *
53
+ * If a call to this function would result in a second item on
54
+ * the queue, the last promise this returned. In that case, any
55
+ * arguments passed to the function are ignored.
56
+ */
57
+ quOnce<T extends (...args: any[]) => Promise<any>>(fn: T): T;
58
+ /**
59
+ * Transform a function into a queued batch processor.
60
+ *
61
+ * @param process The processing function. It takes a batch of items, and must return the same number of results.
62
+ * @param options.limit An optional limit to the number of items passed to a single batch.
63
+ * @param options.debounce Specify to add a delay between queuing a batch and processing the batch.
64
+ */
65
+ batched<T, R>(process: (items: T[]) => Promise<R[]>, options?: {
66
+ limit?: number;
67
+ debounce?: number;
68
+ }): (items: T[]) => Promise<R[]>;
69
+ /**
70
+ * Wait until we are ready to execute the next task on the queue.
71
+ *
72
+ * This places a "Task" marker on the queue, and waits until we get to it.
73
+ *
74
+ * @param exclusive
75
+ */
76
+ private _lockNext;
77
+ private _tryNext;
78
+ }
@@ -0,0 +1,15 @@
1
+ import * as _ from 'lodash';
2
+ export declare class ReactorPath {
3
+ static IMAGE_EXTENSIONS: string[];
4
+ static isImage: ((filename: string) => boolean) & _.MemoizedFunction;
5
+ static isBinary: ((filename: string) => boolean) & _.MemoizedFunction;
6
+ static normalize: ((directory: string) => string) & _.MemoizedFunction;
7
+ static join(...parts: string[]): string;
8
+ static startsWith: ((base: string, check: string) => boolean) & _.MemoizedFunction;
9
+ /**
10
+ *
11
+ */
12
+ static split: ((directory: string) => string[]) & _.MemoizedFunction;
13
+ static equals(...paths: string[]): boolean;
14
+ static matches(path: string, glob: string): boolean;
15
+ }
@@ -0,0 +1,3 @@
1
+ export declare function validateEmail(input: string): boolean;
2
+ export declare function getEmailDomain(e: string): string;
3
+ export declare function emailDomainsMatch(a: string, b: string): boolean;
@@ -0,0 +1,12 @@
1
+ export type ThrottleOptions = {
2
+ wait_ms?: number;
3
+ leading?: boolean;
4
+ };
5
+ export type IFunc<I extends any[], O> = (...args: I) => Promise<O>;
6
+ /**
7
+ * Given an execution function, return a throttled execution function which executes a maximum of
8
+ * once every `wait_ms`.
9
+ *
10
+ * This is conceptually the same as _.throttle except this handles promises correctly
11
+ */
12
+ export declare const throttle: <I extends any[], O>(func: IFunc<I, O>, options?: ThrottleOptions) => IFunc<I, O>;
@@ -0,0 +1 @@
1
+ export declare const copyTextToClipboard: (str: string) => boolean;
@@ -0,0 +1,23 @@
1
+ import * as _ from 'lodash';
2
+ export declare const asColor: ((color: any) => import("color").ColorInstance) & _.MemoizedFunction;
3
+ export declare const isColor: ((color: any) => boolean) & _.MemoizedFunction;
4
+ export declare const normalizeColorToHex: ((color: string) => string) & _.MemoizedFunction;
5
+ export declare const getTransparentColor: ((color: any, transparency: any) => any) & _.MemoizedFunction;
6
+ export declare const getDarkenedColor: ((color: any, ratio: number) => any) & _.MemoizedFunction;
7
+ export declare const getColorWithAlphaOptions: (options: {
8
+ color: string;
9
+ alphaValueIfNotPresent: number;
10
+ }) => any;
11
+ /**
12
+ * #11223344 => rgba(17, 34, 51, 0.27)
13
+ */
14
+ export declare const aHexToRgba: ((hex: string) => string) & _.MemoizedFunction;
15
+ /**
16
+ * rgba(17, 34, 51, 0.27) => #11223344
17
+ */
18
+ export declare const rgbaToAHex: ((str: any) => string) & _.MemoizedFunction;
19
+ export declare const colorToHex: ((str: string) => string) & _.MemoizedFunction;
20
+ /**
21
+ * same as rgbaToAHex, but can also work with colour names like 'mediumpurple'
22
+ */
23
+ export declare const colorToAHex: ((str: string) => string) & _.MemoizedFunction;
@@ -0,0 +1,41 @@
1
+ import { DateTime } from 'luxon';
2
+ export type ReactorDateType = Date | DateTime | string;
3
+ export declare const parseDateTypesToLuxon: (date: ReactorDateType) => DateTime<boolean>;
4
+ /**
5
+ * Takes any date as accepted by new Date(x) where x is the date
6
+ * and returns the date as a string in the format yyyy-mm-dd hh:mm:ss
7
+ *
8
+ * @deprecated use displayDateTime instead
9
+ */
10
+ export declare const simpleDateTime: (date: ReactorDateType, _debugLocale?: boolean) => string;
11
+ export declare enum ReactorDateFormats {
12
+ /**
13
+ * @example 2025-06-12 13:02:46
14
+ */
15
+ SIMPLE = "simple",
16
+ /**
17
+ * @example 2025-06-12T19:02:46.925Z
18
+ */
19
+ ISO = "iso",
20
+ /**
21
+ * 6/12/2025, 7:02 PM
22
+ */
23
+ LOCAL = "local"
24
+ }
25
+ export interface ComputeDateTimePartsOptions {
26
+ date: ReactorDateType;
27
+ local: boolean;
28
+ format: ReactorDateFormats;
29
+ _debugLocale?: boolean;
30
+ }
31
+ export declare const computeDateTimeParts: (options: ComputeDateTimePartsOptions) => {
32
+ display: string;
33
+ display_time: string;
34
+ display_date: string;
35
+ zone: string;
36
+ datetime: DateTime<boolean>;
37
+ };
38
+ export declare const displayDateTime: (options: ComputeDateTimePartsOptions & {
39
+ zone?: boolean;
40
+ }) => string;
41
+ export declare const toRelative: (date: ReactorDateType, now?: ReactorDateType) => string;
@@ -0,0 +1,14 @@
1
+ export declare enum MimeTypes {
2
+ A_JSON = "application/json",
3
+ T_JSON = "text/json",
4
+ VSIX = "application/vsix"
5
+ }
6
+ export interface FileSelectionParams {
7
+ mimeTypes?: string[];
8
+ single?: boolean;
9
+ }
10
+ export declare const selectFiles: (options?: FileSelectionParams) => Promise<File[]>;
11
+ export declare const selectFile: (options?: FileSelectionParams) => Promise<File | null>;
12
+ export declare const saveFile: (content: BlobPart, fileName: string) => void;
13
+ export declare const readFileAsText: (file: File) => Promise<string | null>;
14
+ export declare const readFileAsArrayBuffer: (file: File) => Promise<ArrayBuffer | null>;
@@ -0,0 +1,14 @@
1
+ export * from './clipboard';
2
+ export * from './color';
3
+ export * from './file-input';
4
+ export * from './string-manipulation';
5
+ export * from './ReactorPath';
6
+ export * from './Mutex';
7
+ export * from './EventEmitter';
8
+ export * from './Disposable';
9
+ export * from './Logger';
10
+ export * from './Validators';
11
+ export * from './retries';
12
+ export * from './async-throttle';
13
+ export * from './BaseObserver';
14
+ export * from './dates';
@@ -0,0 +1 @@
1
+ export declare const retryWithBackoff: <T>(handler: () => Promise<T>, attempts?: number, hint?: string) => Promise<T>;
@@ -0,0 +1,10 @@
1
+ import * as _ from 'lodash';
2
+ /**
3
+ * If the provided string is longer than the
4
+ * maximum length, the string is returned with an ellipse
5
+ * @param str
6
+ * @param maxLength
7
+ */
8
+ export declare const trimString: (str: string, maxLength: number) => string;
9
+ export declare const getIntlNumberFormatter: ((maximumFractionDigits?: number) => Intl.NumberFormat) & _.MemoizedFunction;
10
+ export declare const formatNumber: (number: number, maximumFractionDigits?: number) => string;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BaseObserver = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const uuid_1 = require("uuid");
6
+ class BaseObserver {
7
+ constructor() {
8
+ this.listeners = new Map();
9
+ }
10
+ get _listenerSize() {
11
+ return this.listeners.size;
12
+ }
13
+ registerListener(listener) {
14
+ const id = (0, uuid_1.v1)();
15
+ this.listeners.set(id, listener);
16
+ return () => {
17
+ this.listeners.delete(id);
18
+ };
19
+ }
20
+ iterateListeners(cb) {
21
+ for (let i of this.listeners.values()) {
22
+ cb(i);
23
+ }
24
+ }
25
+ iterateAsyncListeners(cb) {
26
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
27
+ for (let i of this.listeners.values()) {
28
+ yield cb(i);
29
+ }
30
+ });
31
+ }
32
+ }
33
+ exports.BaseObserver = BaseObserver;
34
+ //# sourceMappingURL=BaseObserver.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BaseObserver.js","sourceRoot":"","sources":["../src/BaseObserver.ts"],"names":[],"mappings":";;;;AAAA,+BAA0B;AAS1B,MAAa,YAAY;IAGvB;QACE,IAAI,CAAC,SAAS,GAAG,IAAI,GAAG,EAAE,CAAC;IAC7B,CAAC;IAED,IAAI,aAAa;QACf,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;IAC7B,CAAC;IAED,gBAAgB,CAAC,QAAoB;QACnC,MAAM,EAAE,GAAG,IAAA,SAAE,GAAE,CAAC;QAChB,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,EAAE,QAAQ,CAAC,CAAC;QACjC,OAAO,GAAG,EAAE;YACV,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QAC5B,CAAC,CAAC;IACJ,CAAC;IAED,gBAAgB,CAAC,EAAiC;QAChD,KAAK,IAAI,CAAC,IAAI,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,EAAE,CAAC;YACtC,EAAE,CAAC,CAAC,CAAC,CAAC;QACR,CAAC;IACH,CAAC;IAEK,qBAAqB,CAAC,EAA0C;;YACpE,KAAK,IAAI,CAAC,IAAI,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,EAAE,CAAC;gBACtC,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC;YACd,CAAC;QACH,CAAC;KAAA;CACF;AA9BD,oCA8BC"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=Disposable.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Disposable.js","sourceRoot":"","sources":["../src/Disposable.ts"],"names":[],"mappings":""}
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EventEmitter = void 0;
4
+ const uuid = require("uuid");
5
+ /**
6
+ * Not to be confused with node's EventEmitter. This is a typed emitter
7
+ */
8
+ class EventEmitter {
9
+ constructor() {
10
+ this.subscribers = [];
11
+ }
12
+ unsubscribe(id) {
13
+ this.subscribers = this.subscribers.filter((subscriber) => {
14
+ return subscriber.id !== id;
15
+ });
16
+ }
17
+ subscribe(handler) {
18
+ const id = uuid.v4();
19
+ this.subscribers.push({
20
+ id: id,
21
+ handler: handler
22
+ });
23
+ return {
24
+ dispose: () => {
25
+ this.unsubscribe(id);
26
+ }
27
+ };
28
+ }
29
+ emit(event) {
30
+ this.subscribers.forEach((subscriber) => {
31
+ try {
32
+ subscriber.handler(event);
33
+ }
34
+ catch (err) {
35
+ console.error(err);
36
+ }
37
+ });
38
+ }
39
+ dispose() {
40
+ this.subscribers = [];
41
+ }
42
+ }
43
+ exports.EventEmitter = EventEmitter;
44
+ //# sourceMappingURL=EventEmitter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EventEmitter.js","sourceRoot":"","sources":["../src/EventEmitter.ts"],"names":[],"mappings":";;;AACA,6BAA6B;AAQ7B;;GAEG;AACH,MAAa,YAAY;IAAzB;QACE,gBAAW,GAAoB,EAAE,CAAC;IAmCpC,CAAC;IAjCS,WAAW,CAAC,EAAU;QAC5B,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,UAAU,EAAE,EAAE;YACxD,OAAO,UAAU,CAAC,EAAE,KAAK,EAAE,CAAC;QAC9B,CAAC,CAAC,CAAC;IACL,CAAC;IAED,SAAS,CAAC,OAA8B;QACtC,MAAM,EAAE,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC;QACrB,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;YACpB,EAAE,EAAE,EAAE;YACN,OAAO,EAAE,OAAO;SACjB,CAAC,CAAC;QAEH,OAAO;YACL,OAAO,EAAE,GAAG,EAAE;gBACZ,IAAI,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC;YACvB,CAAC;SACF,CAAC;IACJ,CAAC;IAED,IAAI,CAAC,KAAQ;QACX,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,UAAU,EAAE,EAAE;YACtC,IAAI,CAAC;gBACH,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;YAC5B,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YACrB,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;IAED,OAAO;QACL,IAAI,CAAC,WAAW,GAAG,EAAE,CAAC;IACxB,CAAC;CACF;AApCD,oCAoCC"}
package/dist/Logger.js ADDED
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createLogger = exports.Logger = exports.LogLevel = void 0;
4
+ var LogLevel;
5
+ (function (LogLevel) {
6
+ LogLevel["INFO"] = "info";
7
+ LogLevel["DEBUG"] = "debug";
8
+ LogLevel["ERROR"] = "error";
9
+ LogLevel["WARN"] = "warn";
10
+ })(LogLevel || (exports.LogLevel = LogLevel = {}));
11
+ class Logger {
12
+ constructor(name) {
13
+ this.name = name;
14
+ }
15
+ log(level, d) {
16
+ let payload = [`[${this.name}]`, ...d];
17
+ if (level === LogLevel.DEBUG) {
18
+ console.debug(...payload);
19
+ }
20
+ else if (level === LogLevel.ERROR) {
21
+ console.error(...payload);
22
+ }
23
+ else if (level === LogLevel.WARN) {
24
+ console.warn(...payload);
25
+ }
26
+ else {
27
+ console.log(...payload);
28
+ }
29
+ }
30
+ debug(...args) {
31
+ this.log(LogLevel.DEBUG, args);
32
+ }
33
+ info(...args) {
34
+ this.log(LogLevel.INFO, args);
35
+ }
36
+ error(...args) {
37
+ this.log(LogLevel.ERROR, args);
38
+ }
39
+ warn(...args) {
40
+ this.log(LogLevel.WARN, args);
41
+ }
42
+ }
43
+ exports.Logger = Logger;
44
+ const createLogger = (name) => {
45
+ return new Logger(name);
46
+ };
47
+ exports.createLogger = createLogger;
48
+ //# sourceMappingURL=Logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Logger.js","sourceRoot":"","sources":["../src/Logger.ts"],"names":[],"mappings":";;;AAAA,IAAY,QAKX;AALD,WAAY,QAAQ;IAClB,yBAAa,CAAA;IACb,2BAAe,CAAA;IACf,2BAAe,CAAA;IACf,yBAAa,CAAA;AACf,CAAC,EALW,QAAQ,wBAAR,QAAQ,QAKnB;AAED,MAAa,MAAM;IACjB,YAAmB,IAAY;QAAZ,SAAI,GAAJ,IAAI,CAAQ;IAAG,CAAC;IAEzB,GAAG,CAAC,KAAe,EAAE,CAAQ;QACrC,IAAI,OAAO,GAAG,CAAC,IAAI,IAAI,CAAC,IAAI,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;QACvC,IAAI,KAAK,KAAK,QAAQ,CAAC,KAAK,EAAE,CAAC;YAC7B,OAAO,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,CAAC;QAC5B,CAAC;aAAM,IAAI,KAAK,KAAK,QAAQ,CAAC,KAAK,EAAE,CAAC;YACpC,OAAO,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,CAAC;QAC5B,CAAC;aAAM,IAAI,KAAK,KAAK,QAAQ,CAAC,IAAI,EAAE,CAAC;YACnC,OAAO,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC;QAC3B,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,CAAC;QAC1B,CAAC;IACH,CAAC;IAED,KAAK,CAAC,GAAG,IAAS;QAChB,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IACjC,CAAC;IAED,IAAI,CAAC,GAAG,IAAS;QACf,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAChC,CAAC;IAED,KAAK,CAAC,GAAG,IAAS;QAChB,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IACjC,CAAC;IAED,IAAI,CAAC,GAAG,IAAS;QACf,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAChC,CAAC;CACF;AA/BD,wBA+BC;AAEM,MAAM,YAAY,GAA6B,CAAC,IAAY,EAAE,EAAE;IACrE,OAAO,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC,CAAC;AAFW,QAAA,YAAY,gBAEvB"}