@fivelab/web-utils 1.0.5 → 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.
@@ -5,6 +5,4 @@ export { notifyByResponse, notifyError, notifyFetchError, notifyInfo, notifySucc
5
5
  export { request } from './request.js';
6
6
  export { observeElementVisibility } from './visibility.js';
7
7
  export { registerNotificationAdapter } from './notifications/adapter.js';
8
- export { createToastAdapter } from './notifications/toastr.js';
9
- export { createNotyfAdapter } from './notifications/notyf.js';
10
8
  //# 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":";;;;;;"}
@@ -1,6 +1,4 @@
1
1
  export { registerNotificationAdapter } from './notifications/adapter';
2
- export { createToastAdapter } from './notifications/toastr';
3
- export { createNotyfAdapter } from './notifications/notyf';
4
2
  export declare function notifySuccess(message: string): Promise<void>;
5
3
  export declare function notifyError(message: string): Promise<void>;
6
4
  export declare function notifyInfo(message: string): Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"notifications.js","sources":["../../src/browser/notifications.ts"],"sourcesContent":["import { getAdapter } from './notifications/adapter';\nexport { registerNotificationAdapter } from './notifications/adapter';\nexport { createToastAdapter } from './notifications/toastr';\nexport { createNotyfAdapter } from './notifications/notyf';\n\nexport async function notifySuccess(message: string) {\n await getAdapter().success(message);\n}\n\nexport async function notifyError(message: string) {\n await getAdapter().error(message);\n}\n\nexport async function notifyInfo(message: string) {\n await getAdapter().info(message);\n}\n\nexport async function notifyWarning(message: string) {\n await getAdapter().warning(message);\n}\n\nexport async function notifyFetchError() {\n await getAdapter().error('Network error: unable to fetch the API request.');\n}\n\nexport async function notifyByResponse(response: Response): Promise<void>;\nexport async function notifyByResponse(response: Response, message: string): Promise<void>\n\nexport async function notifyByResponse(response: Response, message?: string) {\n if ([200, 201, 204].includes(response.status)) {\n if (message) {\n await notifySuccess(message);\n }\n } else {\n await notifyError(`Receive wrong status - ${response.statusText}`);\n }\n}\n"],"names":[],"mappings":";;;AAKO,eAAe,aAAa,CAAC,OAAe,EAAA;AAC/C,IAAA,MAAM,UAAU,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC;AACvC;AAEO,eAAe,WAAW,CAAC,OAAe,EAAA;AAC7C,IAAA,MAAM,UAAU,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC;AACrC;AAEO,eAAe,UAAU,CAAC,OAAe,EAAA;AAC5C,IAAA,MAAM,UAAU,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC;AACpC;AAEO,eAAe,aAAa,CAAC,OAAe,EAAA;AAC/C,IAAA,MAAM,UAAU,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC;AACvC;AAEO,eAAe,gBAAgB,GAAA;AAClC,IAAA,MAAM,UAAU,EAAE,CAAC,KAAK,CAAC,iDAAiD,CAAC;AAC/E;AAKO,eAAe,gBAAgB,CAAC,QAAkB,EAAE,OAAgB,EAAA;AACvE,IAAA,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE;QAC3C,IAAI,OAAO,EAAE;AACT,YAAA,MAAM,aAAa,CAAC,OAAO,CAAC;QAChC;IACJ;SAAO;QACH,MAAM,WAAW,CAAC,CAAA,uBAAA,EAA0B,QAAQ,CAAC,UAAU,CAAA,CAAE,CAAC;IACtE;AACJ;;;;"}
1
+ {"version":3,"file":"notifications.js","sources":["../../src/browser/notifications.ts"],"sourcesContent":["import { getAdapter } from './notifications/adapter';\nexport { registerNotificationAdapter } from './notifications/adapter';\n\nexport async function notifySuccess(message: string) {\n await getAdapter().success(message);\n}\n\nexport async function notifyError(message: string) {\n await getAdapter().error(message);\n}\n\nexport async function notifyInfo(message: string) {\n await getAdapter().info(message);\n}\n\nexport async function notifyWarning(message: string) {\n await getAdapter().warning(message);\n}\n\nexport async function notifyFetchError() {\n await getAdapter().error('Network error: unable to fetch the API request.');\n}\n\nexport async function notifyByResponse(response: Response): Promise<void>;\nexport async function notifyByResponse(response: Response, message: string): Promise<void>\n\nexport async function notifyByResponse(response: Response, message?: string) {\n if ([200, 201, 204].includes(response.status)) {\n if (message) {\n await notifySuccess(message);\n }\n } else {\n await notifyError(`Receive wrong status - ${response.statusText}`);\n }\n}\n"],"names":[],"mappings":";;;AAGO,eAAe,aAAa,CAAC,OAAe,EAAA;AAC/C,IAAA,MAAM,UAAU,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC;AACvC;AAEO,eAAe,WAAW,CAAC,OAAe,EAAA;AAC7C,IAAA,MAAM,UAAU,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC;AACrC;AAEO,eAAe,UAAU,CAAC,OAAe,EAAA;AAC5C,IAAA,MAAM,UAAU,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC;AACpC;AAEO,eAAe,aAAa,CAAC,OAAe,EAAA;AAC/C,IAAA,MAAM,UAAU,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC;AACvC;AAEO,eAAe,gBAAgB,GAAA;AAClC,IAAA,MAAM,UAAU,EAAE,CAAC,KAAK,CAAC,iDAAiD,CAAC;AAC/E;AAKO,eAAe,gBAAgB,CAAC,QAAkB,EAAE,OAAgB,EAAA;AACvE,IAAA,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE;QAC3C,IAAI,OAAO,EAAE;AACT,YAAA,MAAM,aAAa,CAAC,OAAO,CAAC;QAChC;IACJ;SAAO;QACH,MAAM,WAAW,CAAC,CAAA,uBAAA,EAA0B,QAAQ,CAAC,UAAU,CAAA,CAAE,CAAC;IACtE;AACJ;;;;"}
@@ -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.5",
3
+ "version": "1.0.7",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "The helpers for easy manipulate with dom.",
@@ -14,6 +14,10 @@
14
14
  "types": "./dist/browser/*.d.ts",
15
15
  "import": "./dist/browser/*.js"
16
16
  },
17
+ "./browser/notifications/*": {
18
+ "types": "./dist/browser/notifications/*.d.ts",
19
+ "import": "./dist/browser/notifications/*.js"
20
+ },
17
21
  "./behaviors": {
18
22
  "types": "./dist/behaviors/index.d.ts",
19
23
  "import": "./dist/behaviors/index.js"