@dynamic-labs/utils 0.19.0-alpha.6 → 0.19.0-alpha.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,4 +1,27 @@
1
1
 
2
+ ## [0.19.0-alpha.7](https://github.com/dynamic-labs/DynamicAuth/compare/v0.19.0-alpha.6...v0.19.0-alpha.7) (2023-08-31)
3
+
4
+
5
+ ### Features
6
+
7
+ * include deepLinkPreference option for wallet connect deep linking mode ([#3174](https://github.com/dynamic-labs/DynamicAuth/issues/3174)) ([f715948](https://github.com/dynamic-labs/DynamicAuth/commit/f715948050ddab52373ab742ea47cfc0879842ae))
8
+ * add option to disable the locked wallet view ([#3184](https://github.com/dynamic-labs/DynamicAuth/issues/3184)) ([d9a1290](https://github.com/dynamic-labs/DynamicAuth/commit/d9a1290214b7f86337abb544acd96f65ffe37759))
9
+ * migrate starknet version to v5 ([#3153](https://github.com/dynamic-labs/DynamicAuth/issues/3153)) ([b674011](https://github.com/dynamic-labs/DynamicAuth/commit/b67401133bf75d416118b51be11e3f099d2e2cda))
10
+ * add editable text with react i18next ([#3170](https://github.com/dynamic-labs/DynamicAuth/issues/3170)) ([a46b2ca](https://github.com/dynamic-labs/DynamicAuth/commit/a46b2ca880a4e14356024d2936920f72c8bc447e))
11
+
12
+
13
+ ### Bug Fixes
14
+
15
+ * allow to select L2 wallet after changing L1 network ([#3158](https://github.com/dynamic-labs/DynamicAuth/issues/3158)) ([cf68472](https://github.com/dynamic-labs/DynamicAuth/commit/cf6847270181f7fd33537ac1ff2a03e70b67daf2))
16
+ * allow user to cancel magic login to choose another email ([#3123](https://github.com/dynamic-labs/DynamicAuth/issues/3123)) ([cd73d6d](https://github.com/dynamic-labs/DynamicAuth/commit/cd73d6d0500c313dda01bca6245c52d2d8fca93a))
17
+ * verify email OTP when email is updated ([#3168](https://github.com/dynamic-labs/DynamicAuth/issues/3168)) ([641eeb6](https://github.com/dynamic-labs/DynamicAuth/commit/641eeb685b0c9d77cc72912f29b137c699c192f0))
18
+ * end connector session when unlinking in bridge ([#3120](https://github.com/dynamic-labs/DynamicAuth/issues/3120)) ([4c15da2](https://github.com/dynamic-labs/DynamicAuth/commit/4c15da27646c7bd176f6080dee6d76833e30f8a1))
19
+ * improves loading the sdk setting once per session ([#3189](https://github.com/dynamic-labs/DynamicAuth/issues/3189)) ([c9b0241](https://github.com/dynamic-labs/DynamicAuth/commit/c9b0241da28d2a73c90fd7643280c8632772c90b))
20
+ * update wallet address when switching network on bridge ([#3171](https://github.com/dynamic-labs/DynamicAuth/issues/3171)) ([f35f35e](https://github.com/dynamic-labs/DynamicAuth/commit/f35f35e632bcf88794884b66e0466cdf2e924812))
21
+ * updates the user email when updateUserWithModal method is used ([#3186](https://github.com/dynamic-labs/DynamicAuth/issues/3186)) ([8c71863](https://github.com/dynamic-labs/DynamicAuth/commit/8c718632cef0165328b929c27b6eef313641458d))
22
+ * sign message for embedded wallet when auth mode is connect only ([#3185](https://github.com/dynamic-labs/DynamicAuth/issues/3185)) ([0e3859c](https://github.com/dynamic-labs/DynamicAuth/commit/0e3859cfc738d3ecf8f19976e5cdaebc0c4f01c9))
23
+ * sync wagmi with wallet connector ([#3149](https://github.com/dynamic-labs/DynamicAuth/issues/3149)) ([3216e15](https://github.com/dynamic-labs/DynamicAuth/commit/3216e1570ac12ded6b3ce50b7efb762fe6814815))
24
+
2
25
  ## [0.19.0-alpha.6](https://github.com/dynamic-labs/DynamicAuth/compare/v0.19.0-alpha.5...v0.19.0-alpha.6) (2023-08-25)
3
26
 
4
27
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dynamic-labs/utils",
3
- "version": "0.19.0-alpha.6",
3
+ "version": "0.19.0-alpha.7",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/dynamic-labs/DynamicAuth.git",
@@ -26,7 +26,8 @@
26
26
  "./package.json": "./package.json"
27
27
  },
28
28
  "dependencies": {
29
- "@dynamic-labs/types": "0.19.0-alpha.6"
29
+ "@dynamic-labs/logger": "0.19.0-alpha.7",
30
+ "@dynamic-labs/types": "0.19.0-alpha.7"
30
31
  },
31
32
  "peerDependencies": {}
32
33
  }
@@ -2,32 +2,134 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
+ var logger = require('../logger/logger.cjs');
6
+
7
+ /* eslint-disable multiline-comment-style */
8
+ const defaultCancel = () => {
9
+ logger.logger.error("Tried to cancel CancellablePromise without ever assigning it's '_cancel' method");
10
+ };
11
+ /** An extension of Promise that allows you to explicitly cancel a promise with an external reference to it.
12
+ * Cancelling CancellablePromise causes it to reject with reason set to the parameter passed to the cancel method.
13
+ * When CancellablePromise rejects, it provides a boolean to indicate whether it was cancelled, alongside the reason.
14
+ *
15
+ * @example
16
+ * // Cancelling this promise
17
+ * const promise = new CancellablePromise(() => {}).onCancel(console.log)
18
+ * promise.cancel('User cancelled')
19
+ *
20
+ * // Setting up listeners for resolve, cancel and reject
21
+ * // (notice calling catch after onCancel prevents catch from being called by cancellation)
22
+ * new CancellablePromise(() => {})
23
+ * .then(() => console.log('Promise resolved'))
24
+ * .onCancel(() => console.log('Promise was cancelled'))
25
+ * .catch(() => console.log('Promise was rejected but NOT cancelled'))
26
+ *
27
+ * // Telling whether catch was cause of cancel or not
28
+ * new CancellablePromise(() => {})
29
+ * .then(() => console.log('Promise resolved'))
30
+ * .catch(({ reason, wasCancelled }) => console.log('Promise was rejected. Cancelled: ' + wasCancelled))
31
+ */
5
32
  class CancellablePromise extends Promise {
33
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
34
+ internalCancel(reason) {
35
+ defaultCancel();
36
+ }
6
37
  constructor(executor) {
38
+ let superReject = defaultCancel;
39
+ let superResolve = () => { };
7
40
  super((resolve, reject) => {
8
- executor((val) => {
9
- if (this.isCancelled)
10
- return;
11
- resolve(val);
12
- }, (err) => {
13
- if (this.isCancelled)
14
- return;
15
- reject(err);
16
- });
41
+ superReject = reject;
42
+ superResolve = resolve;
43
+ });
44
+ this.internalIsCancelled = false;
45
+ this.isSettled = false;
46
+ executor((value) => {
47
+ if (!this.isCancelled && !this.isSettled)
48
+ superResolve(value);
49
+ this.isSettled = true;
50
+ }, (reason) => {
51
+ if (!this.isCancelled && !this.isSettled)
52
+ superReject(reason);
53
+ this.isSettled = true;
17
54
  });
18
- this._controller = new AbortController();
55
+ this.internalCancel = superReject;
19
56
  }
57
+ /** Whether this CancellablePromise was cancelled. */
20
58
  get isCancelled() {
21
- return this._controller.signal.aborted;
59
+ return this.internalIsCancelled;
22
60
  }
23
- cancel() {
24
- this._controller.abort();
61
+ /** Cancels the promise. This causes the promise to reject with { wasCancelled: true, reason: reason }
62
+ * where the reason is the provided argument.
63
+ * @returns The cancelled promise.
64
+ */
65
+ cancel(reason) {
66
+ if (this.isSettled)
67
+ return this;
68
+ this.internalIsCancelled = true;
69
+ this.internalCancel(reason);
70
+ this.isSettled = true;
71
+ return this;
25
72
  }
26
- static fromPromise(promise) {
27
- return new CancellablePromise((resolve, reject) => {
28
- promise.then(resolve).catch(reject);
73
+ internalOnCancel(listener, options) {
74
+ const newPromise = new CancellablePromise((resolve, reject) => {
75
+ this.internalThen(resolve, ({ wasCancelled, reason }) => {
76
+ if (wasCancelled)
77
+ resolve(listener(reason));
78
+ else
79
+ reject(reason);
80
+ }, { ignoreOnCancel: true });
81
+ });
82
+ /** Tie the new promise's cancel to this promise's cancel */
83
+ if (!(options === null || options === void 0 ? void 0 : options.ignoreOnCancel)) {
84
+ newPromise.internalOnCancel((reason) => {
85
+ this.cancel(reason);
86
+ }, { ignoreOnCancel: true });
87
+ }
88
+ return newPromise;
89
+ }
90
+ /** Allows reacting to this CancellablePromise being cancelled */
91
+ onCancel(listener) {
92
+ return this.internalOnCancel(listener);
93
+ }
94
+ internalThen(onFulfilled, onRejected, options) {
95
+ /** Create a catch handler that is undefined if the received callback is undefined */
96
+ const catchHandler = onRejected
97
+ ? (reason) => onRejected({ reason, wasCancelled: this.isCancelled })
98
+ : onRejected;
99
+ // /** Create the CancellablePromise we will returned, associated to the then promise */
100
+ const newPromise = CancellablePromise.fromPromise(super.then(onFulfilled, catchHandler));
101
+ /** Tie the new promise's cancel to this promise's cancel */
102
+ if (!(options === null || options === void 0 ? void 0 : options.ignoreOnCancel)) {
103
+ newPromise.internalOnCancel((reason) => {
104
+ this.cancel(reason);
105
+ }, { ignoreOnCancel: true });
106
+ }
107
+ return newPromise;
108
+ }
109
+ then(onFulfilled, onRejected) {
110
+ return this.internalThen(onFulfilled, onRejected);
111
+ }
112
+ catch(onRejected) {
113
+ return this.then(undefined, onRejected);
114
+ }
115
+ finally(onFinally) {
116
+ return this.then((value) => {
117
+ onFinally === null || onFinally === void 0 ? void 0 : onFinally();
118
+ return value;
119
+ }, (reason) => {
120
+ onFinally === null || onFinally === void 0 ? void 0 : onFinally();
121
+ throw reason;
29
122
  });
30
123
  }
124
+ /** Generates a CancellablePromise from a Promise. If a CancellablePromise is passed, it's returned unscathed.
125
+ * WARNING: unless you attach a method to reject the original Promise with the "onCancel" param.
126
+ * cancelling the resulting CancellablePromise does NOT affect the original Promise. */
127
+ static fromPromise(promise) {
128
+ if ('internalIsCancelled' in promise)
129
+ return promise;
130
+ const newPromise = new CancellablePromise((resolve, reject) => promise.then(resolve, reject));
131
+ return newPromise;
132
+ }
31
133
  }
32
134
 
33
135
  exports.CancellablePromise = CancellablePromise;
@@ -1,9 +1,54 @@
1
1
  type Executor<T> = (resolve: (value: T | PromiseLike<T>) => void, reject: (reason?: unknown) => void) => void;
2
+ type CancelListener<TResult = never> = (reason?: unknown) => TResult;
3
+ /** An extension of Promise that allows you to explicitly cancel a promise with an external reference to it.
4
+ * Cancelling CancellablePromise causes it to reject with reason set to the parameter passed to the cancel method.
5
+ * When CancellablePromise rejects, it provides a boolean to indicate whether it was cancelled, alongside the reason.
6
+ *
7
+ * @example
8
+ * // Cancelling this promise
9
+ * const promise = new CancellablePromise(() => {}).onCancel(console.log)
10
+ * promise.cancel('User cancelled')
11
+ *
12
+ * // Setting up listeners for resolve, cancel and reject
13
+ * // (notice calling catch after onCancel prevents catch from being called by cancellation)
14
+ * new CancellablePromise(() => {})
15
+ * .then(() => console.log('Promise resolved'))
16
+ * .onCancel(() => console.log('Promise was cancelled'))
17
+ * .catch(() => console.log('Promise was rejected but NOT cancelled'))
18
+ *
19
+ * // Telling whether catch was cause of cancel or not
20
+ * new CancellablePromise(() => {})
21
+ * .then(() => console.log('Promise resolved'))
22
+ * .catch(({ reason, wasCancelled }) => console.log('Promise was rejected. Cancelled: ' + wasCancelled))
23
+ */
2
24
  export declare class CancellablePromise<T> extends Promise<T> {
3
- _controller: AbortController;
25
+ private internalIsCancelled;
26
+ private isSettled;
27
+ private internalCancel;
4
28
  constructor(executor: Executor<T>);
29
+ /** Whether this CancellablePromise was cancelled. */
5
30
  get isCancelled(): boolean;
6
- cancel(): void;
7
- static fromPromise<T>(promise: Promise<T>): CancellablePromise<T>;
31
+ /** Cancels the promise. This causes the promise to reject with { wasCancelled: true, reason: reason }
32
+ * where the reason is the provided argument.
33
+ * @returns The cancelled promise.
34
+ */
35
+ cancel(reason?: unknown): this;
36
+ private internalOnCancel;
37
+ /** Allows reacting to this CancellablePromise being cancelled */
38
+ onCancel<TResult = never>(listener: CancelListener<TResult>): CancellablePromise<T | TResult>;
39
+ private internalThen;
40
+ then<TResult1 = T, TResult2 = never>(onFulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null, onRejected?: ((reason: {
41
+ reason: unknown;
42
+ wasCancelled: boolean;
43
+ }) => TResult2 | PromiseLike<TResult2>) | null): CancellablePromise<TResult1 | TResult2>;
44
+ catch<TResult = never>(onRejected?: ((reason: {
45
+ reason: unknown;
46
+ wasCancelled: boolean;
47
+ }) => TResult | PromiseLike<TResult>) | null): CancellablePromise<T | TResult>;
48
+ finally(onFinally?: (() => void) | null): CancellablePromise<T>;
49
+ /** Generates a CancellablePromise from a Promise. If a CancellablePromise is passed, it's returned unscathed.
50
+ * WARNING: unless you attach a method to reject the original Promise with the "onCancel" param.
51
+ * cancelling the resulting CancellablePromise does NOT affect the original Promise. */
52
+ static fromPromise<T>(promise: Promise<T> | CancellablePromise<T>): CancellablePromise<T>;
8
53
  }
9
54
  export {};
@@ -1,29 +1,131 @@
1
+ import { logger } from '../logger/logger.js';
2
+
3
+ /* eslint-disable multiline-comment-style */
4
+ const defaultCancel = () => {
5
+ logger.error("Tried to cancel CancellablePromise without ever assigning it's '_cancel' method");
6
+ };
7
+ /** An extension of Promise that allows you to explicitly cancel a promise with an external reference to it.
8
+ * Cancelling CancellablePromise causes it to reject with reason set to the parameter passed to the cancel method.
9
+ * When CancellablePromise rejects, it provides a boolean to indicate whether it was cancelled, alongside the reason.
10
+ *
11
+ * @example
12
+ * // Cancelling this promise
13
+ * const promise = new CancellablePromise(() => {}).onCancel(console.log)
14
+ * promise.cancel('User cancelled')
15
+ *
16
+ * // Setting up listeners for resolve, cancel and reject
17
+ * // (notice calling catch after onCancel prevents catch from being called by cancellation)
18
+ * new CancellablePromise(() => {})
19
+ * .then(() => console.log('Promise resolved'))
20
+ * .onCancel(() => console.log('Promise was cancelled'))
21
+ * .catch(() => console.log('Promise was rejected but NOT cancelled'))
22
+ *
23
+ * // Telling whether catch was cause of cancel or not
24
+ * new CancellablePromise(() => {})
25
+ * .then(() => console.log('Promise resolved'))
26
+ * .catch(({ reason, wasCancelled }) => console.log('Promise was rejected. Cancelled: ' + wasCancelled))
27
+ */
1
28
  class CancellablePromise extends Promise {
29
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
30
+ internalCancel(reason) {
31
+ defaultCancel();
32
+ }
2
33
  constructor(executor) {
34
+ let superReject = defaultCancel;
35
+ let superResolve = () => { };
3
36
  super((resolve, reject) => {
4
- executor((val) => {
5
- if (this.isCancelled)
6
- return;
7
- resolve(val);
8
- }, (err) => {
9
- if (this.isCancelled)
10
- return;
11
- reject(err);
12
- });
37
+ superReject = reject;
38
+ superResolve = resolve;
39
+ });
40
+ this.internalIsCancelled = false;
41
+ this.isSettled = false;
42
+ executor((value) => {
43
+ if (!this.isCancelled && !this.isSettled)
44
+ superResolve(value);
45
+ this.isSettled = true;
46
+ }, (reason) => {
47
+ if (!this.isCancelled && !this.isSettled)
48
+ superReject(reason);
49
+ this.isSettled = true;
13
50
  });
14
- this._controller = new AbortController();
51
+ this.internalCancel = superReject;
15
52
  }
53
+ /** Whether this CancellablePromise was cancelled. */
16
54
  get isCancelled() {
17
- return this._controller.signal.aborted;
55
+ return this.internalIsCancelled;
18
56
  }
19
- cancel() {
20
- this._controller.abort();
57
+ /** Cancels the promise. This causes the promise to reject with { wasCancelled: true, reason: reason }
58
+ * where the reason is the provided argument.
59
+ * @returns The cancelled promise.
60
+ */
61
+ cancel(reason) {
62
+ if (this.isSettled)
63
+ return this;
64
+ this.internalIsCancelled = true;
65
+ this.internalCancel(reason);
66
+ this.isSettled = true;
67
+ return this;
21
68
  }
22
- static fromPromise(promise) {
23
- return new CancellablePromise((resolve, reject) => {
24
- promise.then(resolve).catch(reject);
69
+ internalOnCancel(listener, options) {
70
+ const newPromise = new CancellablePromise((resolve, reject) => {
71
+ this.internalThen(resolve, ({ wasCancelled, reason }) => {
72
+ if (wasCancelled)
73
+ resolve(listener(reason));
74
+ else
75
+ reject(reason);
76
+ }, { ignoreOnCancel: true });
77
+ });
78
+ /** Tie the new promise's cancel to this promise's cancel */
79
+ if (!(options === null || options === void 0 ? void 0 : options.ignoreOnCancel)) {
80
+ newPromise.internalOnCancel((reason) => {
81
+ this.cancel(reason);
82
+ }, { ignoreOnCancel: true });
83
+ }
84
+ return newPromise;
85
+ }
86
+ /** Allows reacting to this CancellablePromise being cancelled */
87
+ onCancel(listener) {
88
+ return this.internalOnCancel(listener);
89
+ }
90
+ internalThen(onFulfilled, onRejected, options) {
91
+ /** Create a catch handler that is undefined if the received callback is undefined */
92
+ const catchHandler = onRejected
93
+ ? (reason) => onRejected({ reason, wasCancelled: this.isCancelled })
94
+ : onRejected;
95
+ // /** Create the CancellablePromise we will returned, associated to the then promise */
96
+ const newPromise = CancellablePromise.fromPromise(super.then(onFulfilled, catchHandler));
97
+ /** Tie the new promise's cancel to this promise's cancel */
98
+ if (!(options === null || options === void 0 ? void 0 : options.ignoreOnCancel)) {
99
+ newPromise.internalOnCancel((reason) => {
100
+ this.cancel(reason);
101
+ }, { ignoreOnCancel: true });
102
+ }
103
+ return newPromise;
104
+ }
105
+ then(onFulfilled, onRejected) {
106
+ return this.internalThen(onFulfilled, onRejected);
107
+ }
108
+ catch(onRejected) {
109
+ return this.then(undefined, onRejected);
110
+ }
111
+ finally(onFinally) {
112
+ return this.then((value) => {
113
+ onFinally === null || onFinally === void 0 ? void 0 : onFinally();
114
+ return value;
115
+ }, (reason) => {
116
+ onFinally === null || onFinally === void 0 ? void 0 : onFinally();
117
+ throw reason;
25
118
  });
26
119
  }
120
+ /** Generates a CancellablePromise from a Promise. If a CancellablePromise is passed, it's returned unscathed.
121
+ * WARNING: unless you attach a method to reject the original Promise with the "onCancel" param.
122
+ * cancelling the resulting CancellablePromise does NOT affect the original Promise. */
123
+ static fromPromise(promise) {
124
+ if ('internalIsCancelled' in promise)
125
+ return promise;
126
+ const newPromise = new CancellablePromise((resolve, reject) => promise.then(resolve, reject));
127
+ return newPromise;
128
+ }
27
129
  }
28
130
 
29
131
  export { CancellablePromise };
package/src/index.cjs CHANGED
@@ -24,6 +24,7 @@ var isFunction = require('./isFunction/isFunction.cjs');
24
24
  var isMobile = require('./isMobile.cjs');
25
25
  var localStorageAsync = require('./localStorageAsync.cjs');
26
26
  var bufferToBase64 = require('./bufferToBase64.cjs');
27
+ var last = require('./last.cjs');
27
28
 
28
29
 
29
30
 
@@ -57,3 +58,4 @@ exports.getItemAsync = localStorageAsync.getItemAsync;
57
58
  exports.removeItemAsync = localStorageAsync.removeItemAsync;
58
59
  exports.setItemAsync = localStorageAsync.setItemAsync;
59
60
  exports.bufferToBase64 = bufferToBase64.bufferToBase64;
61
+ exports.last = last.last;
package/src/index.d.ts CHANGED
@@ -6,3 +6,4 @@ export * from './isFunction';
6
6
  export * from './isMobile';
7
7
  export * from './localStorageAsync';
8
8
  export * from './bufferToBase64';
9
+ export * from './last';
package/src/index.js CHANGED
@@ -20,3 +20,4 @@ export { isFunction } from './isFunction/isFunction.js';
20
20
  export { isAndroid, isIOS, isIPad, isIPhone, isLegacySafari, isMobile, isSamsungBrowser } from './isMobile.js';
21
21
  export { getItemAsync, removeItemAsync, setItemAsync } from './localStorageAsync.js';
22
22
  export { bufferToBase64 } from './bufferToBase64.js';
23
+ export { last } from './last.js';
package/src/last.cjs ADDED
@@ -0,0 +1,21 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ /**
6
+ * Retrieves the last item from an array.
7
+ *
8
+ * @template T - The type of the items in the array.
9
+ * @param {T[]} arr - The array from which to retrieve the last item.
10
+ * @returns {T | undefined} The last item in the array, or undefined if the array is empty.
11
+ *
12
+ * @example
13
+ * const numbers = [1, 2, 3, 4, 5];
14
+ * console.log(last(numbers)); // Outputs: 5
15
+ *
16
+ * const emptyArray: number[] = [];
17
+ * console.log(last(emptyArray)); // Outputs: undefined
18
+ */
19
+ const last = (arr) => arr.length > 0 ? arr[arr.length - 1] : undefined;
20
+
21
+ exports.last = last;
package/src/last.d.ts ADDED
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Retrieves the last item from an array.
3
+ *
4
+ * @template T - The type of the items in the array.
5
+ * @param {T[]} arr - The array from which to retrieve the last item.
6
+ * @returns {T | undefined} The last item in the array, or undefined if the array is empty.
7
+ *
8
+ * @example
9
+ * const numbers = [1, 2, 3, 4, 5];
10
+ * console.log(last(numbers)); // Outputs: 5
11
+ *
12
+ * const emptyArray: number[] = [];
13
+ * console.log(last(emptyArray)); // Outputs: undefined
14
+ */
15
+ export declare const last: <T>(arr: T[]) => T | undefined;
package/src/last.js ADDED
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Retrieves the last item from an array.
3
+ *
4
+ * @template T - The type of the items in the array.
5
+ * @param {T[]} arr - The array from which to retrieve the last item.
6
+ * @returns {T | undefined} The last item in the array, or undefined if the array is empty.
7
+ *
8
+ * @example
9
+ * const numbers = [1, 2, 3, 4, 5];
10
+ * console.log(last(numbers)); // Outputs: 5
11
+ *
12
+ * const emptyArray: number[] = [];
13
+ * console.log(last(emptyArray)); // Outputs: undefined
14
+ */
15
+ const last = (arr) => arr.length > 0 ? arr[arr.length - 1] : undefined;
16
+
17
+ export { last };
@@ -0,0 +1 @@
1
+ export * from './logger';
@@ -0,0 +1,9 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var logger$1 = require('@dynamic-labs/logger');
6
+
7
+ const logger = new logger$1.Logger('magic');
8
+
9
+ exports.logger = logger;
@@ -0,0 +1,2 @@
1
+ import { Logger } from '@dynamic-labs/logger';
2
+ export declare const logger: Logger;
@@ -0,0 +1,5 @@
1
+ import { Logger } from '@dynamic-labs/logger';
2
+
3
+ const logger = new Logger('magic');
4
+
5
+ export { logger };