1
Fork 0
Ergonomic WebExtension storage helper. https://www.npmjs.com/package/@holllo/webextension-storage
Go to file
Bauke 137c8eb290
Remove unused assertion and variable declaration.
2023-12-03 13:22:03 +01:00
source Remove readonly from Value properties. 2022-12-28 12:36:06 +01:00
tests Remove unused assertion and variable declaration. 2023-12-03 13:22:03 +01:00
.gitignore Add project configuration files. 2022-12-26 12:57:43 +01:00
LICENSE Add project configuration files. 2022-12-26 12:57:43 +01:00
README.md Add project configuration files. 2022-12-26 12:57:43 +01:00
esbuild.ts Fix linting issues. 2023-12-02 13:11:32 +01:00
package.json Update dependencies. 2023-12-02 13:07:53 +01:00
pnpm-lock.yaml Update dependencies. 2023-12-02 13:07:53 +01:00
tsconfig.json Add project configuration files. 2022-12-26 12:57:43 +01:00

README.md

@holllo/webextension-storage 🗃

Ergonomic WebExtension storage helper.

Example

import {createValue} from "@holllo/webextension-storage";

const updatedDate = await createValue<Date>({
  // A function that deserializes a string from storage to convert to the wanted
  // type.
  deserialize: (value) => new Date(value),

  // A function that serializes the type to a string to be set in storage.
  serialize: (date) => date.toISOString(),

  // The key to get from storage.
  key: "updatedDate",

  // The StorageArea to use, defaults to local.
  storage: browser.storage.sync,

  // The value to use if there is none in storage.
  value: new Date(),
});

// Get the inner value.
console.log(updatedDate.value);

// Set the inner value.
updatedDate.value = new Date();

// Save the value to storage.
await updatedDate.save();

// Remove the value from storage.
await updatedDate.remove();

License

Distributed under the AGPL-3.0-or-later license, see LICENSE for more information.