Skip to content

Commit

Permalink
feat: add remove alias
Browse files Browse the repository at this point in the history
  • Loading branch information
Atinux committed Mar 5, 2024
1 parent 76560ec commit 1ee816f
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 1 deletion.
3 changes: 2 additions & 1 deletion docs/1.guide/1.index.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,10 @@ await storage.removeItem("foo:bar", { removeMeta: true });
// same as await storage.removeItem("foo:bar", true);
```

You can also use the `del` alias:
You can also use the `del` or `remove` aliases:

```js
await storage.remove("foo:bar");
await storage.del("foo:bar");
```

Expand Down
1 change: 1 addition & 0 deletions src/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,7 @@ export function createStorage<T extends StorageValue>(
set: (key, value, opts = {}) => storage.setItem(key, value, opts),
has: (key, opts = {}) => storage.hasItem(key, opts),
del: (key, opts = {}) => storage.removeItem(key, opts),
remove: (key, opts = {}) => storage.removeItem(key, opts),
};

return storage;
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,5 @@ export interface Storage<T extends StorageValue = StorageValue> {
set: Storage["setItem"];
has: Storage["hasItem"];
del: Storage["removeItem"];
remove: Storage["removeItem"];
}
3 changes: 3 additions & 0 deletions test/storage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,5 +169,8 @@ describe("utils", () => {
expect(await storage.keys()).toEqual(["foo"]);
await storage.del("foo");
expect(await storage.has("foo")).toBe(false);
await storage.setItem("bar", "baz");
await storage.remove("bar");
expect(await storage.has("bar")).toBe(false);
});
});

0 comments on commit 1ee816f

Please sign in to comment.