@w3ux/utils 2.0.8 → 2.0.10

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/base.cjs CHANGED
@@ -34,7 +34,8 @@ __export(base_exports, {
34
34
  rmCommas: () => rmCommas,
35
35
  rmDecimals: () => rmDecimals,
36
36
  shuffle: () => shuffle,
37
- withTimeout: () => withTimeout
37
+ withTimeout: () => withTimeout,
38
+ withTimeoutThrow: () => withTimeoutThrow
38
39
  });
39
40
  module.exports = __toCommonJS(base_exports);
40
41
  var import_utils = require("dedot/utils");
@@ -136,6 +137,17 @@ var withTimeout = (ms, promise, options) => {
136
137
  );
137
138
  return Promise.race([promise, timeout]);
138
139
  };
140
+ var withTimeoutThrow = (ms, promise, options) => {
141
+ const timeout = new Promise(
142
+ (reject) => setTimeout(async () => {
143
+ if (typeof options?.onTimeout === "function") {
144
+ options.onTimeout();
145
+ }
146
+ reject("Function timeout");
147
+ }, ms)
148
+ );
149
+ return Promise.race([promise, timeout]);
150
+ };
139
151
  var appendOrEmpty = (condition, value) => condition ? ` ${value}` : "";
140
152
  var appendOr = (condition, value, fallback) => condition ? ` ${value}` : ` ${fallback}`;
141
153
  var formatAccountSs58 = (address, ss58Prefix) => {
@@ -174,7 +186,8 @@ var minBigInt = (...values) => values.reduce((min, current) => current < min ? c
174
186
  rmCommas,
175
187
  rmDecimals,
176
188
  shuffle,
177
- withTimeout
189
+ withTimeout,
190
+ withTimeoutThrow
178
191
  });
179
192
  /* @license Copyright 2024 w3ux authors & contributors
180
193
  SPDX-License-Identifier: GPL-3.0-only */
package/base.d.cts CHANGED
@@ -58,6 +58,13 @@ declare const shuffle: <T>(array: T[]) => T[];
58
58
  declare const withTimeout: (ms: number, promise: Promise<unknown>, options?: {
59
59
  onTimeout?: () => void;
60
60
  }) => Promise<unknown>;
61
+ /**
62
+ * @name withTimeoutThrow
63
+ * @summary Timeout a promise after a specified number of milliseconds by throwing an error
64
+ */
65
+ declare const withTimeoutThrow: <T>(ms: number, promise: Promise<T>, options?: {
66
+ onTimeout?: () => void;
67
+ }) => Promise<unknown>;
61
68
  /**
62
69
  * @name appendOrEmpty
63
70
  * @summary Returns ` value` if a condition is truthy, or an empty string otherwise.
@@ -104,4 +111,4 @@ declare const maxBigInt: (...values: bigint[]) => bigint;
104
111
  */
105
112
  declare const minBigInt: (...values: bigint[]) => bigint;
106
113
 
107
- export { appendOr, appendOrEmpty, camelize, ellipsisFn, eqSet, formatAccountSs58, isSuperset, maxBigInt, minBigInt, minDecimalPlaces, pageFromUri, removeHexPrefix, rmCommas, rmDecimals, shuffle, withTimeout };
114
+ export { appendOr, appendOrEmpty, camelize, ellipsisFn, eqSet, formatAccountSs58, isSuperset, maxBigInt, minBigInt, minDecimalPlaces, pageFromUri, removeHexPrefix, rmCommas, rmDecimals, shuffle, withTimeout, withTimeoutThrow };
package/base.d.ts CHANGED
@@ -58,6 +58,13 @@ declare const shuffle: <T>(array: T[]) => T[];
58
58
  declare const withTimeout: (ms: number, promise: Promise<unknown>, options?: {
59
59
  onTimeout?: () => void;
60
60
  }) => Promise<unknown>;
61
+ /**
62
+ * @name withTimeoutThrow
63
+ * @summary Timeout a promise after a specified number of milliseconds by throwing an error
64
+ */
65
+ declare const withTimeoutThrow: <T>(ms: number, promise: Promise<T>, options?: {
66
+ onTimeout?: () => void;
67
+ }) => Promise<unknown>;
61
68
  /**
62
69
  * @name appendOrEmpty
63
70
  * @summary Returns ` value` if a condition is truthy, or an empty string otherwise.
@@ -104,4 +111,4 @@ declare const maxBigInt: (...values: bigint[]) => bigint;
104
111
  */
105
112
  declare const minBigInt: (...values: bigint[]) => bigint;
106
113
 
107
- export { appendOr, appendOrEmpty, camelize, ellipsisFn, eqSet, formatAccountSs58, isSuperset, maxBigInt, minBigInt, minDecimalPlaces, pageFromUri, removeHexPrefix, rmCommas, rmDecimals, shuffle, withTimeout };
114
+ export { appendOr, appendOrEmpty, camelize, ellipsisFn, eqSet, formatAccountSs58, isSuperset, maxBigInt, minBigInt, minDecimalPlaces, pageFromUri, removeHexPrefix, rmCommas, rmDecimals, shuffle, withTimeout, withTimeoutThrow };
package/base.js CHANGED
@@ -98,6 +98,17 @@ var withTimeout = (ms, promise, options) => {
98
98
  );
99
99
  return Promise.race([promise, timeout]);
100
100
  };
101
+ var withTimeoutThrow = (ms, promise, options) => {
102
+ const timeout = new Promise(
103
+ (reject) => setTimeout(async () => {
104
+ if (typeof options?.onTimeout === "function") {
105
+ options.onTimeout();
106
+ }
107
+ reject("Function timeout");
108
+ }, ms)
109
+ );
110
+ return Promise.race([promise, timeout]);
111
+ };
101
112
  var appendOrEmpty = (condition, value) => condition ? ` ${value}` : "";
102
113
  var appendOr = (condition, value, fallback) => condition ? ` ${value}` : ` ${fallback}`;
103
114
  var formatAccountSs58 = (address, ss58Prefix) => {
@@ -135,7 +146,8 @@ export {
135
146
  rmCommas,
136
147
  rmDecimals,
137
148
  shuffle,
138
- withTimeout
149
+ withTimeout,
150
+ withTimeoutThrow
139
151
  };
140
152
  /* @license Copyright 2024 w3ux authors & contributors
141
153
  SPDX-License-Identifier: GPL-3.0-only */
package/index.cjs CHANGED
@@ -57,7 +57,8 @@ __export(index_exports, {
57
57
  unimplemented: () => unimplemented,
58
58
  unitToPlanck: () => unitToPlanck,
59
59
  varToUrlHash: () => varToUrlHash,
60
- withTimeout: () => withTimeout
60
+ withTimeout: () => withTimeout,
61
+ withTimeoutThrow: () => withTimeoutThrow
61
62
  });
62
63
  module.exports = __toCommonJS(index_exports);
63
64
 
@@ -161,6 +162,17 @@ var withTimeout = (ms, promise, options) => {
161
162
  );
162
163
  return Promise.race([promise, timeout]);
163
164
  };
165
+ var withTimeoutThrow = (ms, promise, options) => {
166
+ const timeout = new Promise(
167
+ (reject) => setTimeout(async () => {
168
+ if (typeof options?.onTimeout === "function") {
169
+ options.onTimeout();
170
+ }
171
+ reject("Function timeout");
172
+ }, ms)
173
+ );
174
+ return Promise.race([promise, timeout]);
175
+ };
164
176
  var appendOrEmpty = (condition, value) => condition ? ` ${value}` : "";
165
177
  var appendOr = (condition, value, fallback) => condition ? ` ${value}` : ` ${fallback}`;
166
178
  var formatAccountSs58 = (address, ss58Prefix) => {
@@ -432,7 +444,8 @@ var mergeDeep = (target, ...sources) => {
432
444
  unimplemented,
433
445
  unitToPlanck,
434
446
  varToUrlHash,
435
- withTimeout
447
+ withTimeout,
448
+ withTimeoutThrow
436
449
  });
437
450
  /* @license Copyright 2024 w3ux authors & contributors
438
451
  SPDX-License-Identifier: GPL-3.0-only */
package/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- export { appendOr, appendOrEmpty, camelize, ellipsisFn, eqSet, formatAccountSs58, isSuperset, maxBigInt, minBigInt, minDecimalPlaces, pageFromUri, removeHexPrefix, rmCommas, rmDecimals, shuffle, withTimeout } from './base.cjs';
1
+ export { appendOr, appendOrEmpty, camelize, ellipsisFn, eqSet, formatAccountSs58, isSuperset, maxBigInt, minBigInt, minDecimalPlaces, pageFromUri, removeHexPrefix, rmCommas, rmDecimals, shuffle, withTimeout, withTimeoutThrow } from './base.cjs';
2
2
  export { u8aConcat } from './convert.cjs';
3
3
  export { addedTo, applyWidthAsPadding, capitalizeFirstLetter, extractUrlValue, inChrome, isValidAddress, isValidHttpUrl, localStorageOrDefault, makeCancelable, matchedProperties, mergeDeep, planckToUnit, remToUnit, removeVarFromUrlHash, removedFrom, setStateWithRef, snakeToCamel, sortWithNull, unescape, unimplemented, unitToPlanck, varToUrlHash } from './unit.cjs';
4
4
  import 'react';
package/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { appendOr, appendOrEmpty, camelize, ellipsisFn, eqSet, formatAccountSs58, isSuperset, maxBigInt, minBigInt, minDecimalPlaces, pageFromUri, removeHexPrefix, rmCommas, rmDecimals, shuffle, withTimeout } from './base.js';
1
+ export { appendOr, appendOrEmpty, camelize, ellipsisFn, eqSet, formatAccountSs58, isSuperset, maxBigInt, minBigInt, minDecimalPlaces, pageFromUri, removeHexPrefix, rmCommas, rmDecimals, shuffle, withTimeout, withTimeoutThrow } from './base.js';
2
2
  export { u8aConcat } from './convert.js';
3
3
  export { addedTo, applyWidthAsPadding, capitalizeFirstLetter, extractUrlValue, inChrome, isValidAddress, isValidHttpUrl, localStorageOrDefault, makeCancelable, matchedProperties, mergeDeep, planckToUnit, remToUnit, removeVarFromUrlHash, removedFrom, setStateWithRef, snakeToCamel, sortWithNull, unescape, unimplemented, unitToPlanck, varToUrlHash } from './unit.js';
4
4
  import 'react';
package/index.js CHANGED
@@ -98,6 +98,17 @@ var withTimeout = (ms, promise, options) => {
98
98
  );
99
99
  return Promise.race([promise, timeout]);
100
100
  };
101
+ var withTimeoutThrow = (ms, promise, options) => {
102
+ const timeout = new Promise(
103
+ (reject) => setTimeout(async () => {
104
+ if (typeof options?.onTimeout === "function") {
105
+ options.onTimeout();
106
+ }
107
+ reject("Function timeout");
108
+ }, ms)
109
+ );
110
+ return Promise.race([promise, timeout]);
111
+ };
101
112
  var appendOrEmpty = (condition, value) => condition ? ` ${value}` : "";
102
113
  var appendOr = (condition, value, fallback) => condition ? ` ${value}` : ` ${fallback}`;
103
114
  var formatAccountSs58 = (address, ss58Prefix) => {
@@ -368,7 +379,8 @@ export {
368
379
  unimplemented,
369
380
  unitToPlanck,
370
381
  varToUrlHash,
371
- withTimeout
382
+ withTimeout,
383
+ withTimeoutThrow
372
384
  };
373
385
  /* @license Copyright 2024 w3ux authors & contributors
374
386
  SPDX-License-Identifier: GPL-3.0-only */
package/package.json CHANGED
@@ -1,16 +1,15 @@
1
1
  {
2
2
  "name": "@w3ux/utils",
3
- "version": "2.0.8",
3
+ "version": "2.0.10",
4
4
  "license": "GPL-3.0-only",
5
- "dependencies": {
6
- "dedot": "^0.8.1"
7
- },
8
- "main": "index.cjs",
9
- "module": "index.js",
5
+ "type": "module",
10
6
  "exports": {
11
7
  ".": {
12
8
  "import": "./index.js",
13
9
  "require": "./index.cjs"
14
10
  }
11
+ },
12
+ "dependencies": {
13
+ "dedot": "^0.8.1"
15
14
  }
16
15
  }
package/unit.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { MutableRefObject, RefObject } from 'react';
1
+ import { RefObject } from 'react';
2
2
  import { AnyObject } from './types.cjs';
3
3
 
4
4
  /**
@@ -44,7 +44,7 @@ declare const snakeToCamel: (str: string) => string;
44
44
  * @name setStateWithRef
45
45
  * @summary Synchronize React state and its reference with the provided value.
46
46
  */
47
- declare const setStateWithRef: <T>(value: T, setState: (_state: T) => void, ref: MutableRefObject<T>) => void;
47
+ declare const setStateWithRef: <T>(value: T, setState: (_state: T) => void, ref: RefObject<T>) => void;
48
48
  /**
49
49
  * @name localStorageOrDefault
50
50
  * @summary Retrieve the local stroage value with the key, return defult value if it is not
package/unit.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { MutableRefObject, RefObject } from 'react';
1
+ import { RefObject } from 'react';
2
2
  import { AnyObject } from './types.js';
3
3
 
4
4
  /**
@@ -44,7 +44,7 @@ declare const snakeToCamel: (str: string) => string;
44
44
  * @name setStateWithRef
45
45
  * @summary Synchronize React state and its reference with the provided value.
46
46
  */
47
- declare const setStateWithRef: <T>(value: T, setState: (_state: T) => void, ref: MutableRefObject<T>) => void;
47
+ declare const setStateWithRef: <T>(value: T, setState: (_state: T) => void, ref: RefObject<T>) => void;
48
48
  /**
49
49
  * @name localStorageOrDefault
50
50
  * @summary Retrieve the local stroage value with the key, return defult value if it is not