@ada-support/web-storage 0.4.0 → 0.5.0

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/index.d.ts CHANGED
@@ -15,3 +15,5 @@ export declare const adaSessionStorage: {
15
15
  };
16
16
  export declare type AdaStorageKey = StorageKey;
17
17
  export declare type AdaStorageValueByKey = StorageValueByKey;
18
+ /** Checks if Web Storage API is supported */
19
+ export declare const isWebStorageSupported: () => boolean;
package/dist/index.js CHANGED
@@ -1,6 +1,19 @@
1
1
  "use strict";
2
2
  exports.__esModule = true;
3
- exports.adaSessionStorage = exports.adaLocalStorage = void 0;
3
+ exports.isWebStorageSupported = exports.adaSessionStorage = exports.adaLocalStorage = void 0;
4
4
  var create_storage_1 = require("./create-storage");
5
5
  exports.adaLocalStorage = (0, create_storage_1.createStorage)(localStorage);
6
6
  exports.adaSessionStorage = (0, create_storage_1.createStorage)(sessionStorage);
7
+ /** Checks if Web Storage API is supported */
8
+ var isWebStorageSupported = function () {
9
+ try {
10
+ var key = "key_to_test_local_storage";
11
+ localStorage.setItem(key, key);
12
+ localStorage.removeItem(key);
13
+ return true;
14
+ }
15
+ catch (e) {
16
+ return false;
17
+ }
18
+ };
19
+ exports.isWebStorageSupported = isWebStorageSupported;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ada-support/web-storage",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "A package to provide access to Web Storage API",
5
5
  "main": "dist/index.js",
6
6
  "publishConfig": {
package/src/index.ts CHANGED
@@ -5,3 +5,16 @@ export const adaLocalStorage = createStorage(localStorage);
5
5
  export const adaSessionStorage = createStorage(sessionStorage);
6
6
  export type AdaStorageKey = StorageKey;
7
7
  export type AdaStorageValueByKey = StorageValueByKey;
8
+
9
+ /** Checks if Web Storage API is supported */
10
+ export const isWebStorageSupported = (): boolean => {
11
+ try {
12
+ const key = "key_to_test_local_storage";
13
+ localStorage.setItem(key, key);
14
+ localStorage.removeItem(key);
15
+
16
+ return true;
17
+ } catch (e) {
18
+ return false;
19
+ }
20
+ };