@fivelab/web-utils 1.0.6 → 1.0.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.
@@ -2,3 +2,4 @@ export * from './config';
2
2
  export * from './observable';
3
3
  export * from './path';
4
4
  export * from './time';
5
+ export * from './wait';
@@ -2,4 +2,5 @@ export { __test__, getConfig, hasConfig, setConfig } from './config.js';
2
2
  export { Observable } from './observable.js';
3
3
  export { getExtension } from './path.js';
4
4
  export { diffTime } from './time.js';
5
+ export { waitProperty } from './wait.js';
5
6
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}
@@ -0,0 +1,5 @@
1
+ export type WaitPropertyOptions = {
2
+ timeout?: number;
3
+ interval?: number;
4
+ };
5
+ export declare function waitProperty<T = unknown>(obj: object, key: PropertyKey, options?: WaitPropertyOptions): Promise<T>;
@@ -0,0 +1,21 @@
1
+ function waitProperty(obj, key, options = {}) {
2
+ const { timeout = 5000, interval = 50, } = options;
3
+ return new Promise((resolve, reject) => {
4
+ const start = Date.now();
5
+ const check = () => {
6
+ if (Object.prototype.hasOwnProperty.call(obj, key)) {
7
+ resolve(obj[key]); // eslint-disable-line @typescript-eslint/no-explicit-any
8
+ return;
9
+ }
10
+ if (Date.now() - start >= timeout) {
11
+ reject(new Error(`Property "${String(key)}" was not defined within ${timeout}ms.`));
12
+ return;
13
+ }
14
+ setTimeout(check, interval);
15
+ };
16
+ check();
17
+ });
18
+ }
19
+
20
+ export { waitProperty };
21
+ //# sourceMappingURL=wait.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wait.js","sources":["../../src/core/wait.ts"],"sourcesContent":["export type WaitPropertyOptions = {\n timeout?: number; // ms, default 5000\n interval?: number; // ms, default 50\n};\n\nexport function waitProperty<T = unknown>(obj: object, key: PropertyKey, options: WaitPropertyOptions = {}): Promise<T> {\n const {\n timeout = 5000,\n interval = 50,\n } = options;\n\n return new Promise((resolve, reject) => {\n const start = Date.now();\n\n const check = () => {\n if (Object.prototype.hasOwnProperty.call(obj, key)) {\n resolve((obj as any)[key] as T); // eslint-disable-line @typescript-eslint/no-explicit-any\n\n return;\n }\n\n if (Date.now() - start >= timeout) {\n reject(new Error(`Property \"${String(key)}\" was not defined within ${timeout}ms.`));\n\n return;\n }\n\n setTimeout(check, interval);\n };\n\n check();\n });\n}\n"],"names":[],"mappings":"AAKM,SAAU,YAAY,CAAc,GAAW,EAAE,GAAgB,EAAE,UAA+B,EAAE,EAAA;IACtG,MAAM,EACF,OAAO,GAAG,IAAI,EACd,QAAQ,GAAG,EAAE,GAChB,GAAG,OAAO;IAEX,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,KAAI;AACnC,QAAA,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,EAAE;QAExB,MAAM,KAAK,GAAG,MAAK;AACf,YAAA,IAAI,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE;gBAChD,OAAO,CAAE,GAAW,CAAC,GAAG,CAAM,CAAC,CAAC;gBAEhC;YACJ;YAEA,IAAI,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK,IAAI,OAAO,EAAE;AAC/B,gBAAA,MAAM,CAAC,IAAI,KAAK,CAAC,aAAa,MAAM,CAAC,GAAG,CAAC,CAAA,yBAAA,EAA4B,OAAO,CAAA,GAAA,CAAK,CAAC,CAAC;gBAEnF;YACJ;AAEA,YAAA,UAAU,CAAC,KAAK,EAAE,QAAQ,CAAC;AAC/B,QAAA,CAAC;AAED,QAAA,KAAK,EAAE;AACX,IAAA,CAAC,CAAC;AACN;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fivelab/web-utils",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "The helpers for easy manipulate with dom.",