npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

chrome-storage-api

v1.3.0

Published

Helper for chrome.storage API.

Downloads

11

Readme

chrome-storage-api

npm version build License

ko-fi

Overview

Helper for chrome.storage API.

Notes

To use the chrome.storage API, declare the "storage" permission in the manifest:

{
  "name": "My extension",

  "permissions": ["storage"]
}

Installation

You can install this library using npm:

npm install chrome-storage-api

Usage

import { Storage } from "chrome-storage-api"

// Local Storage
Storage.Local.{get | set | push | unshift}

// Sync Storage
Storage.Sync.{get | set | push | unshift}

// Managed Storage
Storage.Managed.{get}

// Session Storage
Storage.Session.{get | set | push | unshift}

Methods

get

Gets one or more items from storage.

import { Storage } from "chrome-storage-api";

// Get a single item from storage.
const singleResult = await Storage.Local.get("key1");
console.log(singleResult);
// Output: value1

// Get multiple items from storage.
const multipleResult = await Storage.Local.get(["key1", "key2"]);
console.log(multipleResult);
// Output: [value1, value2]

// Get items with default values.
const resultWithDefaultValue = await Storage.Local.get({
  key4: "value4",
  key5: "value5",
});
console.log(resultWithDefaultValue);
// Output: { key4: "value4", key5: "value5" }

// Get items using a callback function.
Storage.Local.get("key1", (items) => console.log(items));
// Output: { key1: "value1" }

set

Sets multiple items.

import { Storage } from "chrome-storage-api";

Storage.Local.set({ key3: "value3" }, () => console.log("Value 3 was set."));

onChange

Fired when one or more items change.

import { Storage } from "chrome-storage-api";

Storage.onChange((changes, areaName) => {
  console.log(`New Value: ${changes.key1.newValue}`);
  console.log(`Old Value: ${changes.key1.oldValue}`);
  console.log(`Area Name: ${areaName}`);
});

// Outputs:
//   New Value: new value1
//   Old Value: value1
//   Area Name: local

push

Pushes values to a specified key in the Chrome storage.

import { Storage } from "chrome-storage-api";

await Storage.Local.set({ key4: ["value1", "value2"] });
await Storage.Local.push("key4", ["value3", "value4"]);

Storage.Local.get("key4", (items) => console.log(items));
// Output: Array(4)[value1, value2, value3, value4]

unshift

Unshifts values to a specified key in the Chrome storage.

import { Storage } from "chrome-storage-api";

await Storage.Local.set({ key5: ["value3", "value4"] });
await Storage.Local.unshift("key5", ["value1", "value2"]);

Storage.Local.get("key5", (items) => console.log(items));
// Output: Array(4)[value1, value2, value3, value4]

Link

License

This project is licensed under the MIT License - see the LICENSE file for details.