webext-storage 0.0.0 → 1.0.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.
|
@@ -17,6 +17,9 @@ export class StorageItem {
|
|
|
17
17
|
async set(value) {
|
|
18
18
|
await chromeP.storage[this.area].set({ [this.key]: value });
|
|
19
19
|
}
|
|
20
|
+
async remove() {
|
|
21
|
+
await chromeP.storage[this.area].remove(this.key);
|
|
22
|
+
}
|
|
20
23
|
onChange(callback, signal) {
|
|
21
24
|
const changeHandler = (changes, area) => {
|
|
22
25
|
console.log('changeHandler', changes, area);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "webext-storage",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "A more usable typed storage API for Web Extensions",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"browser",
|
|
@@ -25,7 +25,8 @@
|
|
|
25
25
|
"main": "./distribution/storage-item.js",
|
|
26
26
|
"types": "./distribution/storage-item.d.ts",
|
|
27
27
|
"files": [
|
|
28
|
-
"distribution"
|
|
28
|
+
"distribution/storage-item.js",
|
|
29
|
+
"distribution/storage-item.d.ts"
|
|
29
30
|
],
|
|
30
31
|
"scripts": {
|
|
31
32
|
"build": "tsc",
|
package/readme.md
CHANGED
|
@@ -5,6 +5,13 @@
|
|
|
5
5
|
|
|
6
6
|
> A more usable typed storage API for Web Extensions
|
|
7
7
|
|
|
8
|
+
- Browsers: Chrome, Firefox, and Safari
|
|
9
|
+
- Manifest: v2 and v3
|
|
10
|
+
- Permissions: `storage` or `unlimitedStorage`
|
|
11
|
+
- Context: They can be called from any context
|
|
12
|
+
|
|
13
|
+
**Sponsored by [PixieBrix](https://www.pixiebrix.com)** :tada:
|
|
14
|
+
|
|
8
15
|
## Install
|
|
9
16
|
|
|
10
17
|
```sh
|
|
@@ -26,6 +33,9 @@ await username.set('Ugo');
|
|
|
26
33
|
await username.get();
|
|
27
34
|
// Promise<string>
|
|
28
35
|
|
|
36
|
+
await username.remove();
|
|
37
|
+
// Promise<void>
|
|
38
|
+
|
|
29
39
|
await username.set({name: 'Ugo'});
|
|
30
40
|
// TypeScript Error: Argument of type '{ name: string; }' is not assignable to parameter of type 'string'.
|
|
31
41
|
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-new -- Type tests only */
|
|
2
|
-
import { expectType, expectNotAssignable, expectAssignable } from 'tsd';
|
|
3
|
-
import { StorageItem } from './storage-item.js';
|
|
4
|
-
new StorageItem('key', { area: 'local' });
|
|
5
|
-
new StorageItem('key', { area: 'sync' });
|
|
6
|
-
const unknownItem = new StorageItem('key');
|
|
7
|
-
expectAssignable(unknownItem.get());
|
|
8
|
-
const objectItem = new StorageItem('key');
|
|
9
|
-
expectType(objectItem.get());
|
|
10
|
-
expectType(objectItem.set({ name: 'new name' }));
|
|
11
|
-
const stringItem = new StorageItem('key');
|
|
12
|
-
expectAssignable(stringItem.get());
|
|
13
|
-
expectNotAssignable(stringItem.get());
|
|
14
|
-
expectType(stringItem.get());
|
|
15
|
-
expectType(stringItem.set('some string'));
|
|
16
|
-
// @ts-expect-error Type is string
|
|
17
|
-
await stringItem.set(1);
|
|
18
|
-
// @ts-expect-error Type is string
|
|
19
|
-
await stringItem.set(true);
|
|
20
|
-
// @ts-expect-error Type is string
|
|
21
|
-
await stringItem.set([true, 'string']);
|
|
22
|
-
// @ts-expect-error Type is string
|
|
23
|
-
await stringItem.set({ wow: [true, 'string'] });
|
|
24
|
-
// @ts-expect-error Type is string
|
|
25
|
-
await stringItem.set(1, { days: 1 });
|