@journeyapps-labs/lib-reactor-utils 0.0.0-dev-20250804204343

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 (41) hide show
  1. package/LICENSE +201 -0
  2. package/dist/@types/Disposable.d.ts +3 -0
  3. package/dist/@types/EventEmitter.d.ts +16 -0
  4. package/dist/@types/Mutex.d.ts +78 -0
  5. package/dist/@types/ReactorPath.d.ts +15 -0
  6. package/dist/@types/Validators.d.ts +3 -0
  7. package/dist/@types/async-throttle.d.ts +12 -0
  8. package/dist/@types/clipboard.d.ts +1 -0
  9. package/dist/@types/color.d.ts +23 -0
  10. package/dist/@types/dates.d.ts +41 -0
  11. package/dist/@types/file-input.d.ts +14 -0
  12. package/dist/@types/index.d.ts +12 -0
  13. package/dist/@types/retries.d.ts +1 -0
  14. package/dist/@types/string-manipulation.d.ts +10 -0
  15. package/dist/Disposable.js +3 -0
  16. package/dist/Disposable.js.map +1 -0
  17. package/dist/EventEmitter.js +44 -0
  18. package/dist/EventEmitter.js.map +1 -0
  19. package/dist/Mutex.js +274 -0
  20. package/dist/Mutex.js.map +1 -0
  21. package/dist/ReactorPath.js +61 -0
  22. package/dist/ReactorPath.js.map +1 -0
  23. package/dist/Validators.js +27 -0
  24. package/dist/Validators.js.map +1 -0
  25. package/dist/async-throttle.js +50 -0
  26. package/dist/async-throttle.js.map +1 -0
  27. package/dist/clipboard.js +17 -0
  28. package/dist/clipboard.js.map +1 -0
  29. package/dist/color.js +102 -0
  30. package/dist/color.js.map +1 -0
  31. package/dist/dates.js +95 -0
  32. package/dist/dates.js.map +1 -0
  33. package/dist/file-input.js +87 -0
  34. package/dist/file-input.js.map +1 -0
  35. package/dist/index.js +16 -0
  36. package/dist/index.js.map +1 -0
  37. package/dist/retries.js +36 -0
  38. package/dist/retries.js.map +1 -0
  39. package/dist/string-manipulation.js +25 -0
  40. package/dist/string-manipulation.js.map +1 -0
  41. package/package.json +40 -0
package/dist/Mutex.js ADDED
@@ -0,0 +1,274 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Mutex = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const DEBUG_MUTEX = false;
6
+ class ExclusiveContext {
7
+ constructor(mutex) {
8
+ this.mutex = mutex;
9
+ }
10
+ exclusiveLock(promiseFn) {
11
+ return promiseFn(this);
12
+ }
13
+ sharedLock(promiseFn) {
14
+ return promiseFn(this);
15
+ }
16
+ }
17
+ class SharedContext {
18
+ constructor(mutex) {
19
+ this.mutex = mutex;
20
+ }
21
+ exclusiveLock(promiseFn) {
22
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
23
+ throw new Error('Cannot upgrade a shared lock to an exclusive lock.');
24
+ });
25
+ }
26
+ sharedLock(promiseFn) {
27
+ return promiseFn(this);
28
+ }
29
+ }
30
+ /**
31
+ * Mutex maintains a queue of Promise-returning functions that
32
+ * are executed sequentially (whereas normally they would execute their async code concurrently).
33
+ */
34
+ class Mutex {
35
+ constructor() {
36
+ this.queue = [];
37
+ this.sharedCount = 0;
38
+ this.exclusiveLocked = false;
39
+ }
40
+ /**
41
+ * Returns true if no locks are held: the queue is empty, and no tasks are being executed.
42
+ */
43
+ isFree() {
44
+ if (this.queue.length > 0) {
45
+ return false;
46
+ }
47
+ if (this.exclusiveLocked) {
48
+ return false;
49
+ }
50
+ if (this.sharedCount > 0) {
51
+ return false;
52
+ }
53
+ return true;
54
+ }
55
+ /**
56
+ * Resolves when no lock is being held: the queue is empty, and no tasks are being executed.
57
+ */
58
+ waitUntilFree() {
59
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
60
+ if (this.isFree()) {
61
+ return;
62
+ }
63
+ if (this.emptyQueueResolve == null) {
64
+ this.emptyQueuePromise = new Promise((resolve) => {
65
+ this.emptyQueueResolve = resolve;
66
+ });
67
+ }
68
+ yield this.emptyQueuePromise.finally(() => {
69
+ this.emptyQueuePromise = null;
70
+ this.emptyQueueResolve = null;
71
+ });
72
+ });
73
+ }
74
+ /**
75
+ * Place a function on the queue.
76
+ * The function may either return a Promise or a value.
77
+ * Return a Promise that is resolved with the result of the function.
78
+ */
79
+ exclusiveLock(promiseFn) {
80
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
81
+ return this.lock(promiseFn, true);
82
+ });
83
+ }
84
+ /**
85
+ * Place a function on the queue.
86
+ * This function may execute in parallel with other "multi" functions, but not with other functions on the exclusive
87
+ * queue.
88
+ */
89
+ sharedLock(promiseFn) {
90
+ return this.lock(promiseFn, false);
91
+ }
92
+ lock(promiseFn, exclusive) {
93
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
94
+ const context = yield this._lockNext(exclusive);
95
+ let timeout;
96
+ try {
97
+ if (DEBUG_MUTEX) {
98
+ const stack = new Error().stack;
99
+ timeout = setTimeout(() => {
100
+ console.warn('Mutex not released in 10 seconds\n', stack);
101
+ }, 10000);
102
+ }
103
+ return yield promiseFn(context);
104
+ }
105
+ finally {
106
+ if (DEBUG_MUTEX) {
107
+ clearTimeout(timeout);
108
+ }
109
+ if (!exclusive) {
110
+ this.sharedCount -= 1;
111
+ }
112
+ else {
113
+ this.exclusiveLocked = false;
114
+ }
115
+ this._tryNext();
116
+ }
117
+ });
118
+ }
119
+ /**
120
+ * Convert a normal Promise-returning function into one that is automatically enqueued.
121
+ * The signature of the function stays the same - only the execution is potentially delayed.
122
+ * The only exception is that if the function would have returned a scalar value, it now
123
+ * returns a Promise.
124
+ */
125
+ qu(fn) {
126
+ const self = this;
127
+ return function (...args) {
128
+ return self.exclusiveLock(() => {
129
+ return fn.apply(this, args);
130
+ });
131
+ };
132
+ }
133
+ /**
134
+ * Like qu, but ensures there is never more than one function on
135
+ * the queue. Note that there may be one running as well as one
136
+ * on the queue.
137
+ *
138
+ * If a call to this function would result in a second item on
139
+ * the queue, the last promise this returned. In that case, any
140
+ * arguments passed to the function are ignored.
141
+ */
142
+ quOnce(fn) {
143
+ let queueSize = 0;
144
+ const self = this;
145
+ let lastPromise = null;
146
+ return function (...args) {
147
+ if (queueSize >= 1) {
148
+ return lastPromise;
149
+ }
150
+ queueSize += 1;
151
+ lastPromise = self.exclusiveLock(() => {
152
+ queueSize -= 1;
153
+ return fn.apply(this, args);
154
+ });
155
+ return lastPromise;
156
+ };
157
+ }
158
+ /**
159
+ * Transform a function into a queued batch processor.
160
+ *
161
+ * @param process The processing function. It takes a batch of items, and must return the same number of results.
162
+ * @param options.limit An optional limit to the number of items passed to a single batch.
163
+ * @param options.debounce Specify to add a delay between queuing a batch and processing the batch.
164
+ */
165
+ batched(process, options) {
166
+ // Configure defaults
167
+ options = Object.assign({ limit: null, debounce: null }, options);
168
+ const limit = options.limit;
169
+ const debounce = options.debounce;
170
+ // The batch queue will currently always contain less entries than the number of queued "process" functions.
171
+ // This may change if we start splitting batches.
172
+ let queue = [];
173
+ return (items) => tslib_1.__awaiter(this, void 0, void 0, function* () {
174
+ // Batch entry for this set of items.
175
+ // It may be an unique entry for these items, or it may be shared with others.
176
+ let entry;
177
+ if (queue.length > 0 && (limit == null || queue[queue.length - 1].items.length + items.length <= limit)) {
178
+ // Add to last batch
179
+ entry = queue[queue.length - 1];
180
+ }
181
+ else {
182
+ // Add to queue
183
+ entry = { items: [], results: [], processed: false };
184
+ queue.push(entry);
185
+ }
186
+ const resultOffset = entry.items.length;
187
+ entry.items.push(...items);
188
+ yield this.exclusiveLock(() => tslib_1.__awaiter(this, void 0, void 0, function* () {
189
+ if (entry.processed) {
190
+ return;
191
+ }
192
+ if (debounce && queue.length == 1) {
193
+ // Add a debounce delay, during which time more items may be added to the batch.
194
+ // Only do this if the queue only contains a single batch.
195
+ yield new Promise((resolve) => setTimeout(resolve, debounce));
196
+ }
197
+ const batch = queue.shift();
198
+ try {
199
+ if (batch == null) {
200
+ // This should be caught by the `entry.processed` check above.
201
+ throw new Error('Internal error: No remaining batch to process');
202
+ }
203
+ if (batch !== entry) {
204
+ // This should be caught by the `entry.processed` check above.
205
+ // We should not be processing a batch without our own items in the current design.
206
+ // This may change if we start splitting batches.
207
+ throw new Error('Internal error: Batch mismatch');
208
+ }
209
+ const results = yield process(batch.items);
210
+ if (results == null || results.length != batch.items.length) {
211
+ throw new Error(`Expected ${batch.items.length} results, got ${results ? results.length : results}`);
212
+ }
213
+ batch.results.push(...results);
214
+ }
215
+ catch (error) {
216
+ batch.error = error;
217
+ }
218
+ finally {
219
+ batch.processed = true;
220
+ }
221
+ }));
222
+ if (entry.error) {
223
+ throw entry.error;
224
+ }
225
+ return entry.results.slice(resultOffset, resultOffset + items.length);
226
+ });
227
+ }
228
+ /**
229
+ * Wait until we are ready to execute the next task on the queue.
230
+ *
231
+ * This places a "Task" marker on the queue, and waits until we get to it.
232
+ *
233
+ * @param exclusive
234
+ */
235
+ _lockNext(exclusive) {
236
+ var self = this;
237
+ return new Promise(function (resolve, reject) {
238
+ const task = {
239
+ execute: resolve,
240
+ exclusive
241
+ };
242
+ self.queue.push(task);
243
+ self._tryNext();
244
+ });
245
+ }
246
+ _tryNext() {
247
+ if (this.queue.length == 0) {
248
+ if (this.emptyQueueResolve && this.isFree()) {
249
+ this.emptyQueueResolve();
250
+ }
251
+ return false;
252
+ }
253
+ if (this.exclusiveLocked) {
254
+ return false;
255
+ }
256
+ var task = this.queue[0];
257
+ if (!task.exclusive) {
258
+ this.sharedCount += 1;
259
+ this.queue.shift();
260
+ task.execute(new SharedContext(this));
261
+ }
262
+ else if (this.sharedCount == 0) {
263
+ this.exclusiveLocked = true;
264
+ this.queue.shift();
265
+ task.execute(new ExclusiveContext(this));
266
+ }
267
+ else {
268
+ return false;
269
+ }
270
+ return true;
271
+ }
272
+ }
273
+ exports.Mutex = Mutex;
274
+ //# sourceMappingURL=Mutex.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Mutex.js","sourceRoot":"","sources":["../src/Mutex.ts"],"names":[],"mappings":";;;;AAGA,MAAM,WAAW,GAAG,KAAK,CAAC;AAe1B,MAAM,gBAAgB;IACpB,YAAoB,KAAY;QAAZ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ClB,CAAC,CAAC,CAAC;IACL,CAAC;IAEO,QAAQ;QACd,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,IAAI,CAAC,EAAE,CAAC;YAC3B,IAAI,IAAI,CAAC,iBAAiB,IAAI,IAAI,CAAC,MAAM,EAAE,EAAE,CAAC;gBAC5C,IAAI,CAAC,iBAAiB,EAAE,CAAC;YAC3B,CAAC;YACD,OAAO,KAAK,CAAC;QACf,CAAC;QAED,IAAI,IAAI,CAAC,eAAe,EAAE,CAAC;YACzB,OAAO,KAAK,CAAC;QACf,CAAC;QAED,IAAI,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QACzB,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC;YACpB,IAAI,CAAC,WAAW,IAAI,CAAC,CAAC;YACtB,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;YACnB,IAAI,CAAC,OAAO,CAAC,IAAI,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC;QACxC,CAAC;aAAM,IAAI,IAAI,CAAC,WAAW,IAAI,CAAC,EAAE,CAAC;YACjC,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC;YAC5B,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;YACnB,IAAI,CAAC,OAAO,CAAC,IAAI,gBAAgB,CAAC,IAAI,CAAC,CAAC,CAAC;QAC3C,CAAC;aAAM,CAAC;YACN,OAAO,KAAK,CAAC;QACf,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AA5QD,sBA4QC"}
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ReactorPath = void 0;
4
+ const path = require("path");
5
+ const _ = require("lodash");
6
+ const minimatch_1 = require("minimatch");
7
+ class ReactorPath {
8
+ static join(...parts) {
9
+ if (parts.length === 0) {
10
+ return '';
11
+ }
12
+ return ReactorPath.normalize(parts.join('/'));
13
+ }
14
+ static equals(...paths) {
15
+ if (paths.length <= 1) {
16
+ throw new Error('need 2 or more paths to perform match');
17
+ }
18
+ paths = paths.map((p) => ReactorPath.normalize(p));
19
+ for (let i = 0; i < paths.length - 1; i++) {
20
+ if (paths[i] !== paths[i + 1]) {
21
+ return false;
22
+ }
23
+ }
24
+ return true;
25
+ }
26
+ static matches(path, glob) {
27
+ return (0, minimatch_1.minimatch)(ReactorPath.normalize(path), glob);
28
+ }
29
+ }
30
+ exports.ReactorPath = ReactorPath;
31
+ ReactorPath.IMAGE_EXTENSIONS = ['.png', '.jpeg', '.jpg', '.svg', '.gif'];
32
+ ReactorPath.isImage = _.memoize((filename) => {
33
+ const extension = path.extname(filename).toLowerCase();
34
+ return ReactorPath.IMAGE_EXTENSIONS.indexOf(extension) !== -1;
35
+ });
36
+ ReactorPath.isBinary = _.memoize((filename) => {
37
+ return ReactorPath.isImage(filename);
38
+ });
39
+ ReactorPath.normalize = _.memoize((directory) => {
40
+ directory = _.trim(directory, '/');
41
+ if (directory === '') {
42
+ return '';
43
+ }
44
+ return path.normalize(directory);
45
+ });
46
+ ReactorPath.startsWith = _.memoize((base, check) => {
47
+ return ReactorPath.normalize(base).startsWith(ReactorPath.normalize(check));
48
+ }, (base, check) => {
49
+ return `${base}:${check}`;
50
+ });
51
+ /**
52
+ *
53
+ */
54
+ ReactorPath.split = _.memoize((directory) => {
55
+ directory = ReactorPath.normalize(directory);
56
+ if (directory == '') {
57
+ return [];
58
+ }
59
+ return directory.split('/');
60
+ });
61
+ //# sourceMappingURL=ReactorPath.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ReactorPath.js","sourceRoot":"","sources":["../src/ReactorPath.ts"],"names":[],"mappings":";;;AAAA,6BAA6B;AAC7B,4BAA4B;AAC5B,yCAAsC;AAEtC,MAAa,WAAW;IAoBtB,MAAM,CAAC,IAAI,CAAC,GAAG,KAAe;QAC5B,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACvB,OAAO,EAA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G,CAAC,CAAC,OAAO,CAAC,CAAC,QAAgB,EAAE,EAAE;IAC/C,OAAO,WAAW,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;AACvC,CAAC,CAAC,CAAC;AAEI,qBAAS,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,SAAiB,EAAE,EAAE;IACjD,SAAS,GAAG,CAAC,CAAC,IAAI,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC;IACnC,IAAI,SAAS,KAAK,EAAE,EAAE,CAAC;QACrB,OAAO,EAAE,CAAC;IACZ,CAAC;IACD,OAAO,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;AACnC,CAAC,CAAC,CAAC;AASI,sBAAU,GAAG,CAAC,CAAC,OAAO,CAC3B,CAAC,IAAY,EAAE,KAAa,EAAE,EAAE;IAC9B,OAAO,WAAW,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,UAAU,CAAC,WAAW,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC;AAC9E,CAAC,EACD,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;IACd,OAAO,GAAG,IAAI,IAAI,KAAK,EAAE,CAAC;AAC5B,CAAC,CACF,CAAC;AAEF;;GAEG;AACI,iBAAK,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,SAAiB,EAAE,EAAE;IAC7C,SAAS,GAAG,WAAW,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;IAC7C,IAAI,SAAS,IAAI,EAAE,EAAE,CAAC;QACpB,OAAO,EAAE,CAAC;IACZ,CAAC;IACD,OAAO,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;AAC9B,CAAC,CAAC,CAAC"}
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateEmail = validateEmail;
4
+ exports.getEmailDomain = getEmailDomain;
5
+ exports.emailDomainsMatch = emailDomainsMatch;
6
+ const _ = require("lodash");
7
+ // Not 100% RFC 5322 compliant, but should match any email addresses in use.
8
+ // Source: http://www.regular-expressions.info/email.html
9
+ const emailRegEx = new RegExp("^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$", 'i');
10
+ function validateEmail(input) {
11
+ return emailRegEx.test(input);
12
+ }
13
+ // i know this doesnt work for all emails, but people with multiple '@' signs in their
14
+ // email addresses are wrong
15
+ function getEmailDomain(e) {
16
+ if (!e) {
17
+ return null;
18
+ }
19
+ return _.last(e.split('@')).trim();
20
+ }
21
+ function emailDomainsMatch(a, b) {
22
+ if (!validateEmail(a) || !validateEmail(b)) {
23
+ return false;
24
+ }
25
+ return getEmailDomain(a) === getEmailDomain(b);
26
+ }
27
+ //# sourceMappingURL=Validators.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Validators.js","sourceRoot":"","sources":["../src/Validators.ts"],"names":[],"mappings":";;AASA,sCAEC;AAID,wCAKC;AAED,8CAKC;AA3BD,4BAA4B;AAE5B,4EAA4E;AAC5E,yDAAyD;AACzD,MAAM,UAAU,GAAG,IAAI,MAAM,CAC3B,2IAA2I,EAC3I,GAAG,CACJ,CAAC;AAEF,SAAgB,aAAa,CAAC,KAAa;IACzC,OAAO,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAChC,CAAC;AAED,sFAAsF;AACtF,4BAA4B;AAC5B,SAAgB,cAAc,CAAC,CAAS;IACtC,IAAI,CAAC,CAAC,EAAE,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;AACrC,CAAC;AAED,SAAgB,iBAAiB,CAAC,CAAS,EAAE,CAAS;IACpD,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,CAAC;QAC3C,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OAAO,cAAc,CAAC,CAAC,CAAC,KAAK,cAAc,CAAC,CAAC,CAAC,CAAC;AACjD,CAAC"}
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.throttle = void 0;
4
+ const tslib_1 = require("tslib");
5
+ /**
6
+ * Given an execution function, return a throttled execution function which executes a maximum of
7
+ * once every `wait_ms`.
8
+ *
9
+ * This is conceptually the same as _.throttle except this handles promises correctly
10
+ */
11
+ const throttle = (func, options) => {
12
+ let pending_executions = [];
13
+ let leading = false;
14
+ let i;
15
+ const execute = () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
16
+ i = undefined;
17
+ const executions = pending_executions;
18
+ pending_executions = [];
19
+ const latest = executions[executions.length - 1];
20
+ try {
21
+ let res = yield func(...latest.args);
22
+ for (const execution of executions) {
23
+ execution.resolve(res);
24
+ }
25
+ }
26
+ catch (err) {
27
+ for (const execution of executions) {
28
+ execution.reject(err);
29
+ }
30
+ }
31
+ });
32
+ return (...args) => {
33
+ return new Promise((resolve, reject) => {
34
+ pending_executions.push({
35
+ args: args,
36
+ resolve: resolve,
37
+ reject: reject
38
+ });
39
+ if ((options === null || options === void 0 ? void 0 : options.leading) && !leading) {
40
+ leading = true;
41
+ execute();
42
+ }
43
+ if (i == null) {
44
+ i = setTimeout(execute, (options === null || options === void 0 ? void 0 : options.wait_ms) || 100);
45
+ }
46
+ });
47
+ };
48
+ };
49
+ exports.throttle = throttle;
50
+ //# sourceMappingURL=async-throttle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"async-throttle.js","sourceRoot":"","sources":["../src/async-throttle.ts"],"names":[],"mappings":";;;;AAaA;;;;;GAKG;AACI,MAAM,QAAQ,GAAG,CAAqB,IAAiB,EAAE,OAAyB,EAAe,EAAE;IACxG,IAAI,k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AAC;YACnD,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC,CAAC;AA3CW,QAAA,QAAQ,YA2CnB"}
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.copyTextToClipboard = void 0;
4
+ const copyTextToClipboard = (str) => {
5
+ // Note: navigator.clipboard works only secure contexts, i.e. when using https.
6
+ // This will not work when developing locally with http
7
+ try {
8
+ navigator.clipboard.writeText(str);
9
+ return true;
10
+ }
11
+ catch (ex) {
12
+ console.log('This only shows up in local dev mode dont worry: ', str);
13
+ return false;
14
+ }
15
+ };
16
+ exports.copyTextToClipboard = copyTextToClipboard;
17
+ //# sourceMappingURL=clipboard.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"clipboard.js","sourceRoot":"","sources":["../src/clipboard.ts"],"names":[],"mappings":";;;AAAO,MAAM,mBAAmB,GAAG,CAAC,GAAW,EAAE,EAAE;IACjD,+EAA+E;IAC/E,uDAAuD;IACvD,IAAI,CAAC;QACH,SAAS,CAAC,SAAS,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;QACnC,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,OAAO,EAAE,EAAE,CAAC;QACZ,OAAO,CAAC,GAAG,CAAC,mDAAmD,EAAE,GAAG,CAAC,CAAC;QACtE,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC,CAAC;AAVW,QAAA,mBAAmB,uBAU9B"}
package/dist/color.js ADDED
@@ -0,0 +1,102 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.colorToAHex = exports.colorToHex = exports.rgbaToAHex = exports.aHexToRgba = exports.getColorWithAlphaOptions = exports.getDarkenedColor = exports.getTransparentColor = exports.normalizeColorToHex = exports.isColor = exports.asColor = void 0;
4
+ // @ts-ignore
5
+ const hexToRgba = require("hex-to-rgba");
6
+ const color_1 = require("color");
7
+ const _ = require("lodash");
8
+ const hexOpacity = require("hex-opacity");
9
+ exports.asColor = _.memoize((color) => {
10
+ try {
11
+ return new color_1.default(color);
12
+ }
13
+ catch (ex) {
14
+ return null;
15
+ }
16
+ });
17
+ exports.isColor = _.memoize((color) => {
18
+ if (!color) {
19
+ return false;
20
+ }
21
+ return !!(0, exports.asColor)(color);
22
+ });
23
+ exports.normalizeColorToHex = _.memoize((color) => {
24
+ if (color.startsWith('#')) {
25
+ return color;
26
+ }
27
+ if ((0, exports.isColor)(color)) {
28
+ return (0, exports.asColor)(color).hex();
29
+ }
30
+ return (0, exports.colorToHex)(color);
31
+ });
32
+ const _isGradient = (color) => {
33
+ return color.indexOf('linear-gradient') !== -1;
34
+ };
35
+ exports.getTransparentColor = _.memoize((color, transparency) => {
36
+ if (_isGradient(color)) {
37
+ return color;
38
+ }
39
+ return new color_1.default(color).alpha(transparency).toString();
40
+ }, (a, b) => `${a}${b}`);
41
+ exports.getDarkenedColor = _.memoize((color, ratio) => {
42
+ if (_isGradient(color)) {
43
+ return color;
44
+ }
45
+ return new color_1.default(color).darken(ratio).toString();
46
+ }, (a, b) => `${a}${b}`);
47
+ const getColorWithAlphaOptions = (options) => {
48
+ const color = (0, exports.asColor)(options.color);
49
+ if (color.alpha() < 1) {
50
+ return color.toString();
51
+ }
52
+ return (0, exports.getTransparentColor)(options.color.toString(), options.alphaValueIfNotPresent);
53
+ };
54
+ exports.getColorWithAlphaOptions = getColorWithAlphaOptions;
55
+ /**
56
+ * #11223344 => rgba(17, 34, 51, 0.27)
57
+ */
58
+ exports.aHexToRgba = _.memoize((hex) => {
59
+ if (!hex) {
60
+ return null;
61
+ }
62
+ return hexToRgba(hex);
63
+ });
64
+ /**
65
+ * rgba(17, 34, 51, 0.27) => #11223344
66
+ */
67
+ exports.rgbaToAHex = _.memoize((str) => {
68
+ try {
69
+ let c = new color_1.default(str);
70
+ return hexOpacity.create(c.hex(), c.alpha());
71
+ }
72
+ catch (ex) { }
73
+ return null;
74
+ });
75
+ exports.colorToHex = _.memoize((str) => {
76
+ if (!str) {
77
+ return null;
78
+ }
79
+ const c = (0, exports.asColor)(str);
80
+ if (c) {
81
+ return c.hex();
82
+ }
83
+ const ctx = document.createElement('canvas').getContext('2d');
84
+ ctx.fillStyle = str;
85
+ return (0, exports.rgbaToAHex)(ctx.fillStyle) || '';
86
+ });
87
+ /**
88
+ * same as rgbaToAHex, but can also work with colour names like 'mediumpurple'
89
+ */
90
+ exports.colorToAHex = _.memoize((str) => {
91
+ if (!str) {
92
+ return null;
93
+ }
94
+ const c = (0, exports.rgbaToAHex)(str);
95
+ if (c) {
96
+ return c;
97
+ }
98
+ const ctx = document.createElement('canvas').getContext('2d');
99
+ ctx.fillStyle = str;
100
+ return (0, exports.rgbaToAHex)(ctx.fillStyle) || '';
101
+ });
102
+ //# sourceMappingURL=color.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"color.js","sourceRoot":"","sources":["../src/color.ts"],"names":[],"mappings":";;;AAAA,aAAa;AACb,yCAAyC;AACzC,iCAA0B;AAC1B,4BAA4B;AAC5B,0CAA0C;AAE7B,QAAA,OAAO,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE;IACzC,IAAI,CAAC;QACH,OAAO,IAAI,eAAK,CAAC,KAAK,CAAC,CAAC;IAC1B,CAAC;IAAC,OAAO,EAAE,EAAE,CAAC;QACZ,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC,CAAC,CAAC;AAEU,QAAA,OAAO,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE;IACzC,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OAAO,CAAC,CAAC,IAAA,eAAO,EAAC,KAAK,CAAC,CAAC;AAC1B,CAAC,CAAC,CAAC;AAEU,QAAA,mBAAmB,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,KAAa,EAAE,EAAE;IAC7D,IAAI,KAAK,CAAC,UAAU,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Q,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;IAC9D,GAAG,CAAC,SAAS,GAAG,GAAG,CAAC;IACpB,OAAO,IAAA,kBAAU,EAAC,GAAG,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC;AACzC,CAAC,CAAC,CAAC;AAEH;;GAEG;AACU,QAAA,WAAW,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,GAAW,EAAU,EAAE;IAC3D,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,CAAC,GAAG,IAAA,kBAAU,EAAC,GAAG,CAAC,CAAC;IAC1B,IAAI,CAAC,EAAE,CAAC;QACN,OAAO,CAAC,CAAC;IACX,CAAC;IAED,MAAM,GAAG,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;IAC9D,GAAG,CAAC,SAAS,GAAG,GAAG,CAAC;IACpB,OAAO,IAAA,kBAAU,EAAC,GAAG,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC;AACzC,CAAC,CAAC,CAAC"}
package/dist/dates.js ADDED
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toRelative = exports.displayDateTime = exports.computeDateTimeParts = exports.ReactorDateFormats = exports.simpleDateTime = exports.parseDateTypesToLuxon = void 0;
4
+ const _ = require("lodash");
5
+ const luxon_1 = require("luxon");
6
+ const parseDateTypesToLuxon = (date) => {
7
+ if (_.isString(date)) {
8
+ return luxon_1.DateTime.fromISO(date);
9
+ }
10
+ if (luxon_1.DateTime.isDateTime(date)) {
11
+ return date;
12
+ }
13
+ if (date instanceof Date) {
14
+ return luxon_1.DateTime.fromJSDate(date);
15
+ }
16
+ throw new Error('Invalid date type');
17
+ };
18
+ exports.parseDateTypesToLuxon = parseDateTypesToLuxon;
19
+ /**
20
+ * Takes any date as accepted by new Date(x) where x is the date
21
+ * and returns the date as a string in the format yyyy-mm-dd hh:mm:ss
22
+ *
23
+ * @deprecated use displayDateTime instead
24
+ */
25
+ const simpleDateTime = (date, _debugLocale = false) => {
26
+ return (0, exports.displayDateTime)({
27
+ format: ReactorDateFormats.SIMPLE,
28
+ local: true,
29
+ date,
30
+ _debugLocale
31
+ });
32
+ };
33
+ exports.simpleDateTime = simpleDateTime;
34
+ var ReactorDateFormats;
35
+ (function (ReactorDateFormats) {
36
+ /**
37
+ * @example 2025-06-12 13:02:46
38
+ */
39
+ ReactorDateFormats["SIMPLE"] = "simple";
40
+ /**
41
+ * @example 2025-06-12T19:02:46.925Z
42
+ */
43
+ ReactorDateFormats["ISO"] = "iso";
44
+ /**
45
+ * 6/12/2025, 7:02 PM
46
+ */
47
+ ReactorDateFormats["LOCAL"] = "local";
48
+ })(ReactorDateFormats || (exports.ReactorDateFormats = ReactorDateFormats = {}));
49
+ const computeDateTimeParts = (options) => {
50
+ const { date, local, format, _debugLocale } = options;
51
+ let object = (0, exports.parseDateTypesToLuxon)(date);
52
+ if (local) {
53
+ object = object.toLocal();
54
+ if (_debugLocale) {
55
+ object = object.setLocale('en-US');
56
+ object = object.setZone('America/New_York');
57
+ }
58
+ }
59
+ else {
60
+ object = object.toUTC();
61
+ }
62
+ let display_time = object.toFormat('HH:mm:ss');
63
+ let display_date = object.toISODate();
64
+ let display = `${display_date} ${display_time}`;
65
+ if (format === ReactorDateFormats.ISO) {
66
+ display = object.toISO();
67
+ }
68
+ else if (format === ReactorDateFormats.LOCAL) {
69
+ display = object.toLocaleString(luxon_1.DateTime.DATETIME_SHORT).replace('\u202f', ' ');
70
+ display_date = object.toLocaleString(luxon_1.DateTime.DATE_SHORT);
71
+ display_time = object.toLocaleString(luxon_1.DateTime.DATETIME_SHORT);
72
+ }
73
+ return {
74
+ display: display,
75
+ display_time,
76
+ display_date,
77
+ zone: object.zoneName,
78
+ datetime: object
79
+ };
80
+ };
81
+ exports.computeDateTimeParts = computeDateTimeParts;
82
+ const displayDateTime = (options) => {
83
+ let { display, zone } = (0, exports.computeDateTimeParts)(options);
84
+ if (options.zone) {
85
+ return `${display} (${zone})`;
86
+ }
87
+ return display;
88
+ };
89
+ exports.displayDateTime = displayDateTime;
90
+ const toRelative = (date, now) => {
91
+ let time = (0, exports.parseDateTypesToLuxon)(date);
92
+ return time.toRelative({ base: now ? (0, exports.parseDateTypesToLuxon)(now) : undefined });
93
+ };
94
+ exports.toRelative = toRelative;
95
+ //# sourceMappingURL=dates.js.map