1
Fork 0
Ergonomic WebExtension storage helper. https://www.npmjs.com/package/@holllo/webextension-storage
You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
Bauke 01792d43d2
Version 0.2.0!
5 months ago
source Remove readonly from Value properties. 5 months ago
tests Add source code. 5 months ago
.gitignore Add project configuration files. 5 months ago
LICENSE Add project configuration files. 5 months ago
README.md Add project configuration files. 5 months ago
esbuild.ts Add project configuration files. 5 months ago
package.json Version 0.2.0! 5 months ago
pnpm-lock.yaml Add project configuration files. 5 months ago
tsconfig.json Add project configuration files. 5 months ago

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.