Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
webext-storage
Advanced tools
Readme
A more usable typed storage API for Web Extensions
storage
or unlimitedStorage
Sponsored by PixieBrix :tada:
chrome.storage.local.get()
is very inconvenient to use and it does not provide type safety. This module provides a better API:
// Before
const storage = await chrome.storage.local.get('user-options');
const value = storage['user-options']; // The type is `any`
await chrome.storage.local.set({['user-options']: {color: 'red'}}); // Not type-checked
chrome.storage.onChanged.addListener((storageArea, change) => {
if (storageArea === 'local' && change['user-options']) { // Repetitive
console.log('New options', change['user-options'].newValue)
}
});
// After
const options = new StorageItem<Record<string, string>>('user-options');
const value = await options.get(); // The type is `Record<string, string> | undefined`
await options.set({color: 'red'}) // Type-checked
options.onChanged(newValue => {
console.log('New options', newValue)
});
Why this is better:
get
only is only .get()
instead of the awkward post-get object access thatget
and set
operation is type-safedefaultValue
, the return type will not be | undefined
onChanged
example speaks for itselfnpm install webext-storage
Or download the standalone bundle to include in your manifest.json
.
import {StorageItem} from "webext-storage";
const username = new StorageItem<string>('username')
// Or
const username = new StorageItem('username', {defaultValue: 'admin'})
await username.set('Ugo');
// Promise<void>
await username.get();
// Promise<string>
await username.remove();
// Promise<void>
await username.set({name: 'Ugo'});
// TypeScript Error: Argument of type '{ name: string; }' is not assignable to parameter of type 'string'.
username.onChanged(newName => {
console.log('The user’s new name is', newName);
});
MIT © Federico Brigante
FAQs
A more usable typed storage API for Web Extensions
The npm package webext-storage receives a total of 299 weekly downloads. As such, webext-storage popularity was classified as not popular.
We found that webext-storage demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.