
Security News
Happy Birthday, Shai-Hulud
It has been one year since Shai-Hulud made its first appearance on npm.
@webreflection/idb-map
Advanced tools
Social Media Photo by delfi de la Rua on Unsplash
An IndexedDB based Map with an asynchronous interface.
An IDBMap instance implements all Map methods or accessors except these are all asynchroonus.
An IDBMap also extends EventTarget too, so dispatchEvent is also available, among others. Handled events are by default abort, close, error and versionchange.
The IDBMap constructor is the only main different API compared to Map:
name suffix as string. The DB will be called 'IDBMap/${name}'. The storage name used for this db will be entries. An empty string is also a valid name but please be aware of naming collisionsoptions object, currently to either override transactions' durability, where its default value is 'default', or to use a different database prefix name which default value is 'IDBMap'type IDBMapOptions = {
durability?: 'strict' | 'relaxed' | 'default';
prefix?: string;
}
class IDBMap extends EventTarget implements Map {
constructor(
name:string,
options:IDBMapOptions = { durability: 'default', prefix: 'IDBMap' }
):IDBMap
// the only extra method not present in Map or EventTarget
close():Promise<void>
}
import IDBMap from '@webreflection/idb-map';
// create an async map with a generic storage name
const idbMap = new IDBMap('my-storage-name');
// check any Map property by awaiting it
console.log(await idbMap.size);
console.log(await idbMap.has('nope'));
// optional helpers for buffered data
const encoder = new TextEncoder;
const decoder = new TextDecoder;
// set any IDB compatible value
await idbMap.set('test.txt', 'test value');
console.log(await idbMap.has('test.txt'));
await idbMap.set('other.txt', encoder.encode('other value'));
// get any IDB stored value
console.log(await idbMap.get('test.txt'));
console.log(decoder.decode(await idbMap.get('other.txt')));
// retrieve any other async Map API method
console.log(await idbMap.keys());
console.log(await idbMap.size);
for (const entry of await idbMap.entries())
console.log(entry);
// or remove a single key
await idbMap.delete('other.txt');
console.log(await idbMap.keys());
console.log(await idbMap.size);
// or clear the whole thing
await idbMap.clear();
console.log(await idbMap.keys());
console.log(await idbMap.size);
// eventually close it
await idbMap.close();
There are other projects with a similar goal, most popular or notable is idb-keyval, but ...
.close() asynchronous method to ensure a db has been successfully closedThat's pretty much it; you already know this module and the only different thing is the way an IDBMap is initialized.
FAQs
Async IndexedDB based Map
The npm package @webreflection/idb-map receives a total of 9,418 weekly downloads. As such, @webreflection/idb-map popularity was classified as popular.
We found that @webreflection/idb-map demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.

Security News
It has been one year since Shai-Hulud made its first appearance on npm.

Research
/Security News
Operators behind PolinRider used a compromised GitHub account to plant malware in four development versions of a Packagist package with 700,000+ downloads.

Security News
GitHub Actions now supports cache-mode, a least-privilege control on the Actions cache aimed at the cache poisoning technique behind recent compromises.