@putkoff/abstract-utilities 0.1.171 → 0.1.172
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/dist/cjs/index.js +54 -13
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.js +53 -14
- package/dist/esm/index.js.map +1 -1
- package/dist/functions/safe_utils/src/index.d.ts +3 -2
- package/dist/functions/safe_utils/src/safe_globals.d.ts +7 -0
- package/dist/functions/safe_utils/src/safe_storage.d.ts +21 -0
- package/package.json +1 -1
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns `window` if running in a browser, otherwise `undefined`.
|
|
3
|
+
*/
|
|
4
|
+
export declare function getSafeLocalStorage(): Storage | undefined;
|
|
5
|
+
/**
|
|
6
|
+
* Call a Storage method by name, silencing any errors or missing storage.
|
|
7
|
+
*
|
|
8
|
+
* @param method One of the keys of the Storage interface: "getItem", "setItem", etc.
|
|
9
|
+
* @param args The arguments you’d normally pass to that method.
|
|
10
|
+
* @returns The method’s return value, or undefined if storage/method isn’t available.
|
|
11
|
+
*/
|
|
12
|
+
export declare function callStorage<K extends keyof Storage>(method: K, ...args: Parameters<Storage[K]>): ReturnType<Storage[K]> | undefined;
|
|
13
|
+
/**
|
|
14
|
+
* Safely call localStorage / sessionStorage / any Storage API.
|
|
15
|
+
*
|
|
16
|
+
* @param storageName "localStorage" or "sessionStorage"
|
|
17
|
+
* @param method one of the Storage methods, e.g. "getItem", "setItem", etc.
|
|
18
|
+
* @param args arguments to pass along (e.g. key, value)
|
|
19
|
+
* @returns whatever the underlying method returns, or undefined if unavailable/fails
|
|
20
|
+
*/
|
|
21
|
+
export declare function safeStorage<S extends "localStorage" | "sessionStorage", M extends keyof Storage>(storageName: S, method: M, ...args: Parameters<Storage[M]>): ReturnType<Storage[M]> | undefined;
|