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 🙏

© 2026 – Pkg Stats / Ryan Hefner

mdbasequery

v0.0.1

Published

Query Markdown vaults with Obsidian Bases-compatible syntax

Readme

mdbasequery

mdbasequery is an Obsidian Bases-compatible query engine for Markdown vaults.

It ships as:

  • a CLI (mdbasequery) for scripts and terminal workflows,
  • a TypeScript library for embedding query execution in applications.

Supported runtimes: Node.js 20+, Bun, and Deno 2.x.

CLI Manual

Install and Run

You can run the CLI without installing globally:

npx mdbasequery --help
bunx mdbasequery --help

Or install globally:

npm install -g mdbasequery
# then
mdbasequery --help

Command Model

Command form:

mdbasequery [options]

There is one command surface; all behavior is controlled through options.

Query Input Modes

mdbasequery supports three ways to provide the query definition:

  1. .base file via --base <path>
  2. Inline YAML via --yaml <yaml-text>
  3. Flag-built query mode (--filter, --select, --sort, etc.)

If --base/--yaml are not provided, the query is built from flags.

Common CLI Examples

Run a .base file against a vault:

mdbasequery \
  --base ./fixtures/queries/basic.base \
  --dir ./fixtures/vaults/basic \
  --format json

Use inline YAML (heredoc to avoid shell escaping issues):

QUERY_YAML=$(cat <<'EOF'
views:
  - type: table
    name: default
    filters: score >= 7
    properties:
      - title
      - score
EOF
)

mdbasequery --yaml "$QUERY_YAML" --dir ./fixtures/vaults/basic --format md

Use CLI flags instead of YAML:

mdbasequery \
  --dir ./fixtures/vaults/basic \
  --filter "score >= 7" \
  --select title \
  --select score \
  --sort score:desc \
  --format csv

Select a specific view from a .base file and write output to disk:

mdbasequery \
  --base ./fixtures/queries/grouped.base \
  --view grouped \
  --dir ./fixtures/vaults/basic \
  --format yaml \
  --out ./result.yaml

Disable strict symbol/function checking:

mdbasequery --yaml "views: [{ type: table, name: default }]" --no-strict

CLI Option Reference

| Option | Type | Description | | --- | --- | --- | | --dir <path> | string | Target directory to scan (default: current directory). | | --base <path> | string | Path to Obsidian-style .base YAML file. | | --yaml <yaml-text> | string | Inline YAML text. | | --view <name> | string | View name to run (default: first view). | | --format <json|jsonl|yaml|csv|md> | string | Output format (default: json). | | --out <path> | string | Write serialized output to file instead of stdout. | | --strict | flag | Enable strict mode (default behavior). | | --no-strict | flag | Disable strict mode for unknown symbols/functions. | | --include <glob> | repeatable string | Include path glob(s), matched against vault-relative paths. | | --exclude <glob> | repeatable string | Exclude path glob(s), matched against vault-relative paths. | | --debug | flag | Enable debug diagnostics in result metadata. | | --filter <expr> | repeatable string | Add filter expression(s) in flag-built mode. | | --select <property> | repeatable string | Select/project property/column in flag-built mode. | | --sort <prop:asc|desc> | repeatable string | Sort criteria in flag-built mode. | | --group-by <property> | string | Group rows by one property in flag-built mode. | | --limit <n> | number | Limit row count in flag-built mode. | | --help, -h | flag | Show CLI help text. |

Output Formats

  • json: one structured object with rows, columns, summaries, stats, diagnostics.
  • jsonl: one JSON object per row.
  • yaml: YAML representation of the full result object.
  • csv: projected columns in declared/selected order.
  • md: Markdown table for quick human review.

Exit Codes and Diagnostics

  • Exit code 0: successful query execution.
  • Exit code 1: fatal CLI/query error, or row-level diagnostics recorded as errors.

Diagnostics are returned as part of result metadata (and included in structured formats).

Compatibility and Behavior Notes

  • Filters and formulas share the same expression language.
  • Effective filter per view is global filter AND view filter.
  • Formula dependencies are topologically ordered; cycles fail clearly.
  • Strict mode is enabled by default.
  • Summary formulas evaluate with values bound to selected column values.
  • Output ordering is deterministic.
  • this context in CLI/library mode is deterministic metadata (filePath, name).

Library Manual

Installation

npm install mdbasequery
# or
bun add mdbasequery

Quick Start

import { queryBase, serializeResult } from "mdbasequery";

const result = await queryBase({
  dir: "./fixtures/vaults/basic",
  yaml: `
views:
  - type: table
    name: default
    filters: score >= 7
    properties:
      - title
      - score
`.trim(),
  strict: true,
});

console.log(result.rows.length);
console.log(serializeResult(result, "json"));

API Overview

Primary exports:

  • queryBase(options): Promise<QueryResult>
  • parseBaseYaml(input): QuerySpec
  • compileQuery(spec, options?): CompiledQuery
  • runCompiledQuery(compiled, source?): Promise<QueryResult>
  • serializeResult(result, format): string

Runtime adapters:

  • detectRuntimeAdapter()
  • nodeAdapter, bunAdapter, denoAdapter

queryBase Options

queryBase accepts a QueryBaseOptions object with:

  • spec?: QuerySpec - already parsed query spec.
  • basePath?: string - path to .base file.
  • yaml?: string - inline YAML text.
  • view?: string - selected view name.
  • dir?: string - vault root directory.
  • strict?: boolean - strict symbol/function behavior (default true).
  • include?: string[] - include globs.
  • exclude?: string[] - exclude globs.
  • debug?: boolean - enable debug diagnostics.
  • adapter?: RuntimeAdapter - runtime adapter injection.

Provide exactly one query source among spec, basePath, or yaml.

Compile Once, Run Many

import { compileQuery, parseBaseYaml, runCompiledQuery } from "mdbasequery";

const spec = parseBaseYaml(`
views:
  - type: table
    name: default
    filters: score >= 7
`.trim());

const compiled = compileQuery(spec, { strict: true });

const first = await runCompiledQuery(compiled, { dir: "./vault-a" });
const second = await runCompiledQuery(compiled, { dir: "./vault-b" });

console.log(first.rows.length, second.rows.length);

Result Shape

QueryResult contains:

  • rows: row contexts with note, file, formula, this, and projected fields.
  • columns: projected column order.
  • groups?: grouped rows when grouping is active.
  • summaries?: computed summary values.
  • stats: scan/match timing and counts.
  • diagnostics: warnings and errors.

Error Handling

  • Schema/YAML issues throw validation errors (for example from parseBaseYaml).
  • Strict mode rejects unknown identifiers/functions.
  • Formula cycles throw explicit cycle errors.
  • CLI returns exit code 1 for failures and diagnostic errors.

Development Manual

Prerequisites

  • Bun (primary dev runtime)
  • Node.js 20+
  • Deno 2.x

Setup

bun install

Build and Test Commands

bun run build
bun run lint-typecheck
bun run test:bun
bun run test:node
bun run test:deno
bun run ci

bun run ci runs the required local validation suite:

  1. typecheck/lint
  2. Bun tests
  3. Node conformance tests
  4. Deno conformance tests

CI Jobs

GitHub Actions runs:

  • lint-typecheck
  • test-bun
  • test-node
  • test-deno
  • compat-smoke-cli (matrix across Bun/Node/Deno)

Repository Layout

  • src/core - schema, expression engine, query engine, serialization, indexing.
  • src/runtime-adapters - runtime-specific filesystem/path adapters.
  • src/cli.ts - CLI entrypoint.
  • tests - Bun test suite (unit/integration/docs smoke).
  • test-runtime - Node/Deno conformance tests.
  • fixtures - vault and query fixtures.
  • .github/workflows/ci.yml - CI workflow definitions.

Release Checklist

  1. Ensure bun run ci passes locally.
  2. Ensure GitHub Actions checks are green.
  3. Build artifacts (dist) and package metadata are correct.
  4. Publish to npm.
  5. Verify npx mdbasequery --help and bunx mdbasequery --help post-release.