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

@wzdong/idb

v1.1.8

Published

๐Ÿ’ก Let your application use indexedDB simply with `Promise`

Downloads

5

Readme

@wzdong/idb

๐Ÿ“™ First:

If you are not satisfied with the size of localStorage or the data format it supports, try indexedDB. If you find indexedDB cumbersome to use, lets try @wzdong/idb. It lets you use indexedDB just as easily as localStorage! ๐Ÿ˜œ๐Ÿ˜œ

  1. This is an npm package based on indexedDB and the size is only about 10 kB.
  2. The method of use is very simple, you only need to read, store, and remove data through Promise.then() .

๐Ÿ”จ Installation

  • NPM
npm i @wzdong/idb -S
  • CDN
<script src="https://cdn.jsdelivr.net/npm/@wzdong/[email protected]"></script>

๐ŸŒฐ Example

import { initStore } from '@wzdong/idb';

const yourKey = 'uid_1';

// Use `yourKey` to identify the store, and your data will be stored in a store with `yourKey`.
const store = initStore(yourKey);
// It supports the TypeScript notation, which defines your data type by generics, like the following:
// `const store = initStore<{dataName: string}>(yourKey)`

const yourData = { dataName: 'someData' };

// `setData` is to save your data.
store.setData(yourData).then(() => console.log('save success!'));

// `getData` is to get your data, you can receive your data in `.then()`.
store.getData().then((data) => console.log(data));

// `removeData` is to remove your data.
store.removeData(yourData).then(() => console.log('remove success!'));

You can then use indexedDB however you want in your project this way. Isn't this writing very similar to localStorage, yes, it's that simple. It's just that it becomes an implementation of asynchronous promises.

JS Application Example: Form Storage

https://code.juejin.cn/pen/7166548718001324071

๐Ÿง Q&A๏ผš

Why use indexedDB instead of simpler localStorage?

  1. IndexedDB natively supports reading and writing objects, Date, undefined, NaN, Infinity, and self-referencing objects. This is not supported by localStorage, and although it is possible to convert with the help of JSON.stringify(), it is still difficult to fully support these types mentioned above.
  2. The storage space of indexedDB is large enough, generally not less than 250M, and the size is generally 50% of the size of the hard disk. The maximum storage capacity of localStorage is generally not higher than 5M.
  3. IndexDB is natively implemented asynchronously, so you don't have to worry about using it to prevent the normal operation of your application by making errors in reading and writing data.

Why wrap indexedDB?

โ€ƒโ€ƒThe process of using native indexedDB is complex, including database requests, establishment transactions, and transaction operations. The implementation of simplified encapsulation in formal project code is more efficient and more conducive to project maintenance.

๐Ÿ™†โ€โ™‚๏ธ Contributor

  • Author: wzdong
  • Email: [email protected]
  • Github: https://github.com/wzdong26
  • Juejin: https://juejin.cn/user/1764078817409022