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

ygopro-cdb-encode

v1.0.2

Published

YGOPro CDB encoder/decoder and query helpers for Node.js/TypeScript.

Readme

ygopro-cdb-encode

YGOPro CDB encoder/decoder and query helpers for Node.js/TypeScript, built on top of sql.js.

Features

  • Read and query .cdb files with sql.js.
  • Convert between DB rows and CardDataEntry.
  • Query with SQL or with a filter object (TypeORM-style operators).
  • Create new databases, insert cards, and export .cdb bytes.

Install

npm i ygopro-cdb-encode

Usage

Open an existing CDB

import fs from 'fs';
import initSqlJs from 'sql.js';
import { YGOProCdb } from 'ygopro-cdb-encode';

const SQL = await initSqlJs();
const data = new Uint8Array(fs.readFileSync('cards.cdb'));
const cdb = new YGOProCdb(SQL).from(data);

const blueEyes = cdb.findOne('texts.name = :name', { name: '青眼白龙' });
console.log(blueEyes?.code);

Create a new CDB and add cards

import initSqlJs from 'sql.js';
import { YGOProCdb, CardDataEntry } from 'ygopro-cdb-encode';

const SQL = await initSqlJs();
const cdb = new YGOProCdb(SQL);

const card = new CardDataEntry().fromPartial({
  code: 123456,
  name: '测试卡',
  desc: '测试描述',
  attack: 1800,
  defense: 1000,
  level: 4,
});

cdb.addCard(card);
const bytes = cdb.export(); // Uint8Array

Query API

SQL statement

const cards = cdb.find('datas.atk >= :atk AND texts.name = :name', {
  atk: 2000,
  name: '黑魔术师',
});

Filter object

const cards = cdb.find({
  name: '黑魔术师',
  atk: MoreThanOrEqual(2000),
});

Operators

import {
  Not,
  LessThan,
  MoreThan,
  LessThanOrEqual,
  MoreThanOrEqual,
  And,
  Or,
  HasBit,
  HasAllBits,
} from 'ygopro-cdb-encode';
  • Not(value) / Not(op)
  • LessThan(value)
  • MoreThan(value)
  • LessThanOrEqual(value)
  • MoreThanOrEqual(value)
  • And(...values | ...ops)
  • Or(...values | ...ops)
  • HasBit(value)column & value != 0
  • HasAllBits(value)column & value = value

Virtual fields in filters

The filter API supports computed fields to match CardData semantics:

  • codedatas.id
  • leveldatas.level & 255
  • lscale(datas.level >> 24) & 255
  • rscale(datas.level >> 16) & 255
  • rawLeveldatas.level
  • rawDefensedatas.def
  • defenseCASE WHEN TYPE_LINK THEN NULL ELSE datas.def END
  • linkMarkerCASE WHEN TYPE_LINK THEN datas.def ELSE NULL END

API Overview

class YGOProCdb {
  constructor(sqljs: SqlJsStatic | Database | YGOProCdb)
  from(db: Database | Uint8Array): this

  find(stmt?: string, params?: Record<string, any>): CardDataEntry[]
  find(filter?: CdbFindFilter): CardDataEntry[]
  findOne(stmt?: string, params?: Record<string, any>): CardDataEntry | undefined
  findOne(filter?: CdbFindFilter): CardDataEntry | undefined
  findById(id: number): CardDataEntry | undefined

  addCard(card: CardDataEntry | CardDataEntry[]): this
  export(): Uint8Array
  finalize(): void
}

License

MIT