@webext-core/storage 1.1.2 → 1.1.3
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/README.md +1 -1
- package/lib/index.cjs +3 -1
- package/lib/index.d.ts +27 -3
- package/lib/index.global.js +3 -1
- package/lib/index.js +3 -1
- package/package.json +2 -2
package/README.md
CHANGED
package/lib/index.cjs
CHANGED
package/lib/index.d.ts
CHANGED
|
@@ -6,6 +6,12 @@ declare type AnySchema = Record<string, any>;
|
|
|
6
6
|
*/
|
|
7
7
|
declare type RemoveListenerCallback = () => void;
|
|
8
8
|
declare type OnChangeCallback<TSchema extends AnySchema, TKey extends keyof TSchema = keyof TSchema> = (newValue: TSchema[TKey], oldValue: TSchema[TKey] | null) => void;
|
|
9
|
+
/**
|
|
10
|
+
* This is the interface for the storage objects exported from the package. It is similar to `localStorage`, except for a few differences:
|
|
11
|
+
*
|
|
12
|
+
* - ***It's async*** since the web extension storage APIs are async.
|
|
13
|
+
* - It can store any data type, ***not just strings***.
|
|
14
|
+
*/
|
|
9
15
|
interface ExtensionStorage<TSchema extends AnySchema> {
|
|
10
16
|
/**
|
|
11
17
|
* Clear all values from storage.
|
|
@@ -34,15 +40,33 @@ interface ExtensionStorage<TSchema extends AnySchema> {
|
|
|
34
40
|
}
|
|
35
41
|
|
|
36
42
|
/**
|
|
37
|
-
* Create a storage instance with an optional type
|
|
43
|
+
* Create a storage instance with an optional schema, `TSchema`, for type safety.
|
|
44
|
+
*
|
|
45
|
+
* @param storage The storage to to use. Either `Browser.storage.local`, `Browser.storage.sync`, or `Browser.storage.managed`.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* import browser from 'webextension-polyfill';
|
|
49
|
+
*
|
|
50
|
+
* interface Schema {
|
|
51
|
+
* installDate: number;
|
|
52
|
+
* }
|
|
53
|
+
* const extensionStorage = defineExtensionStorage<Schema>(browser.storage.local);
|
|
38
54
|
*
|
|
39
|
-
*
|
|
40
|
-
* `Browser.storage.managed`. This is the storage that will back the implementation.
|
|
55
|
+
* const date = await extensionStorage.getItem("installDate");
|
|
41
56
|
*/
|
|
42
57
|
declare function defineExtensionStorage<TSchema extends AnySchema = AnySchema>(storage: Storage.StorageArea): ExtensionStorage<TSchema>;
|
|
43
58
|
|
|
59
|
+
/**
|
|
60
|
+
* An implementation of `ExtensionStorage` based on the `browser.storage.local` storage area.
|
|
61
|
+
*/
|
|
44
62
|
declare const localExtStorage: ExtensionStorage<AnySchema>;
|
|
63
|
+
/**
|
|
64
|
+
* An implementation of `ExtensionStorage` based on the `browser.storage.sync` storage area.
|
|
65
|
+
*/
|
|
45
66
|
declare const syncExtStorage: ExtensionStorage<AnySchema>;
|
|
67
|
+
/**
|
|
68
|
+
* An implementation of `ExtensionStorage` based on the `browser.storage.managed` storage area.
|
|
69
|
+
*/
|
|
46
70
|
declare const managedExtStorage: ExtensionStorage<AnySchema>;
|
|
47
71
|
|
|
48
72
|
export { ExtensionStorage, defineExtensionStorage, localExtStorage, managedExtStorage, syncExtStorage };
|
package/lib/index.global.js
CHANGED
package/lib/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webext-core/storage",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.3",
|
|
4
4
|
"description": "A type-safe, localStorage-esk wrapper around the web extension storage APIs. Supports all browsers (Chrome, Firefox, Safari, etc)",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"tsup": "^6.4.0",
|
|
48
48
|
"typescript": "^4.8.4",
|
|
49
49
|
"vitest": "^0.24.5",
|
|
50
|
-
"@webext-core/fake-browser": "1.2.
|
|
50
|
+
"@webext-core/fake-browser": "1.2.2",
|
|
51
51
|
"tsconfig": "0.0.0"
|
|
52
52
|
},
|
|
53
53
|
"scripts": {
|