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

idb-take

v1.0.0

Published

Take values from IDBStore or IDBIndex

Downloads

4

Readme

idb-take

Take values from IDBStore or IDBIndex

idb-take is a set of functions on top of .openCursor() functionality.

Think about it as improved IndexedDB 2.0's getAll(range, limit) method, which in addition to limit argument accepts unique, offset and reverse.

Installation

npm install --save idb-take

Example

import { take, takeOne, takeRight, takeRightOne } from 'idb-take'
import { open } from 'idb-factory'

// let's assume you have IndexedDB database with 'books' store and `byFrequency` index
const db = await open('mydb', 1, (e) => {
  e.target.result.createObjectStore('books', { keyPath: 'id' })  
  e.target.result.objectStore('books').createIndex('byFrequency')
})

// query store
const store = db.transaction(['books'], 'readonly').objectStore('books')
await take(store, { gte: 'a' }) // find all keys matching `a` pattern
await take(store, null, { limit: 10, offset: 20 }) // page=3
await takeOne(store, { lt: 'z' }) // get first value

// query index
const index = db.transaction(['books'], 'readonly').objectStore('books').index('byFrequency')
await take(index, { lte: 3 }, { unique: true, limit: 2 })
await takeRight(index, null, { offset: 5 }) // in reverse order
await takeRightOne(index, { gte: 10 }) // get last value

API

Each function accepts 3 arguments:

  • store - an instance of IDBStore or IDBIndex. It also integrates with high level libraries which support .openCursor() method (for example: treo).
  • range (optional) - IDBKeyRange instance or any idb-range argument
  • opts (optional) - filter options:
    • limit - limit amount or returned values
    • offset - skip values
    • reverse - get values in reverse order using prev or prevunique when open cursor.
    • unique - get only unique values using prevunique or nextunique (applicable only for IDBIndex).

take(store, [range], [opts])

Take values from store, which satisfy range criteria.

import { take } from 'idb-take'

await take(store, null, { limit: 20, offset: 20 })
await take(index, { gt: 10, lt: 20 })

takeOne(store, [range], [opts])

Take first value.

takeRight(store, [range], [opts])

Take values in reverse order.

takeRightOne(store, [range], [opts])

Take last value.

License

MIT