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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@openlib/drupe

v0.0.4

Published

> Tiny helper that lets you run [Mango selectors](https://docs.couchdb.org/en/stable/api/database/find.html#selector-syntax) anywhere you need a JavaScript predicate.

Readme

drupe

Tiny helper that lets you run Mango selectors anywhere you need a JavaScript predicate.

drupe is inspired by the ergonomics of sift but speaks Mango—the JSON-based query language used by CouchDB and PouchDB. Pass a Mango selector in and get back a function that tests plain JavaScript objects, arrays, or any iterable source.

Why drupe?

  • Reuse the same Mango selectors you ship to CouchDB/PouchDB on the client or in tests.
  • Drop into Array.prototype.filter, find, or any higher-order utility—no extra plumbing required.
  • Ships as a single function that delegates to PouchDB’s battle-tested matchesSelector implementation.
  • Zero configuration, fully typed, and framework/runtime agnostic.

Installation

Install from JSR:

# npm, bun, and older versions of yarn or pnpm
npx jsr add @holmes/drupe

Quick start

import { drupe } from 'drupe'

const isPublishedTechArticle = drupe({
  type: 'article',
  publishedAt: { $exists: true },
  tags: { $in: ['databases', 'javascript'] }
})

const articles = [
  { type: 'article', slug: 'mango-101', tags: ['databases'], publishedAt: '2024-05-02' },
  { type: 'article', slug: 'draft-post', tags: ['javascript'] },
  { type: 'note', slug: 'retro' }
]

const published = articles.filter(isPublishedTechArticle)
// -> [{ type: 'article', slug: 'mango-101', tags: ['databases'], publishedAt: '2024-05-02' }]

The same selector you use in a db.find() call now works as an in-memory predicate.

More examples

All Mango selector operators are supported because drupe simply forwards to PouchDB’s selector engine. For a full reference, see the PouchDB guide on Mango queries and the CouchDB documentation linked above.

import { drupe } from 'drupe'

const isHighValueCustomer = drupe({
  $and: [
    { spend: { $gte: 1000 } },
    { status: { $in: ['gold', 'platinum'] } }
  ]
})

const customers = [
  { name: 'Ada', spend: 3200, status: 'platinum' },
  { name: 'Lin', spend: 840, status: 'gold' },
  { name: 'Edsger', spend: 1500, status: 'silver' }
]

customers.filter(isHighValueCustomer)
// -> [{ name: 'Ada', spend: 3200, status: 'platinum' }]

You can also use $not, $regex, $size, $elemMatch, and any other Mango operator:

const containsLargeAttachment = drupe({
  attachments: {
    $elemMatch: {
      content_type: { $regex: '^image/' },
      length: { $gt: 1_000_000 }
    }
  }
})

docs.filter(containsLargeAttachment)

API

const predicate = drupe(selector)
predicate(document) // -> boolean
  • selector – Any valid Mango selector object.
  • Returns a predicate function that can be reused across collections, iterables, or bespoke logic.

TypeScript: The exported signature is intentionally loose—(selector: any) => (subject: unknown) => boolean—so you can refine the shape that makes sense for your app.

How it works

drupe is intentionally tiny:

import { matchesSelector } from 'pouchdb-selector-core'

export const drupe = (selector: any) => (subject: unknown) => {
  return matchesSelector(subject, selector)
}

When you call drupe(selector), it defers entirely to matchesSelector, the same function PouchDB uses internally to evaluate Mango selectors. That means:

  • Behaviour matches CouchDB/PouchDB exactly (including quirks and edge cases).
  • New Mango features arrive as soon as they land in pouchdb-selector-core.
  • There is no custom query engine to maintain.

Related resources

License

MIT © Sam Holmes