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

@latinfo/engine

v0.5.7

Published

Binary lookup, inverted-index search, and MPHF engine for Latin American business registries

Readme

@latinfo/engine

Binary lookup, inverted-index search, and minimal perfect hash (MPHF) engine for content-addressed datasets. Storage-agnostic — bring your own backend (R2, S3, filesystem, in-memory).

Pure TypeScript, zero runtime dependencies. Works in Node.js, Cloudflare Workers, Bun, Deno, and modern browsers.

Install

npm install @latinfo/engine

Usage

import { lookupId, searchByName } from '@latinfo/engine';
import type { Storage, SourceConfig } from '@latinfo/engine';

// Implement the Storage interface for your backend
const storage: Storage = {
  async get(key, options) {
    // Return { arrayBuffer() } or null
  },
};

// Provide your own SourceConfig (the engine is dataset-agnostic)
const source: SourceConfig = {
  country: 'xx', institution: 'agency', dataset: 'records',
  source: 'agency-records', baseName: 'agency-records',
  routePath: '/xx/agency/records',
  primaryId: { name: 'id', length: 11, regex: /^\d{11}$/, prefixLength: 5 },
  alternateIds: [],
  fieldNames: ['name', 'status', 'address'],
  searchFieldIndex: 0,
};

// Lookup by ID — O(log n) binary search over a content-addressed shard
const record = await lookupId(storage, source, '12345678901');

// Search by name — inverted index with TF-IDF scoring
const results = await searchByName(storage, source, 'acme corporation');

API

Lookup

  • lookupId(storage, source, id) — exact lookup by primary ID
  • lookupIds(storage, source, id) — for multiRecord: true sources (one ID → many records)
  • loadIndex(storage, source) — preload the prefix index
  • clearIndexCache(baseName?) — clear in-memory cache

Search

  • searchByName(storage, source, query) — V2/V3 inverted index with inline fields
  • resolveQuery(storage, source, query) — ODIS-style: returns instructions for client-side resolution
  • getPostingData(storage, source, terms) — fetch posting lists by term
  • clearSearchCache(baseName?) — clear in-memory cache

Tenders / Procurement

  • searchLicitaciones(storage, config, query) — procurement search with filters (category, amount, buyer, method, status)
  • licitacionesInfo(storage, config) — total record count
  • clearLicitacionesCache(baseName?)

LicitacionesConfig is provided by the caller, so you can run multiple named instances (e.g. current vs historical archives) against the same engine.

MPHF (Minimal Perfect Hash)

  • BBHash — class for building MPHFs
  • buildMphfFile(terms, totalDocs, entrySize) — build from a term list
  • serializeMphf(mphf) / deserializeMphf(buf) — wire format
  • mphfExactLookup(mphf, term) — O(1) term lookup
  • mphfResolveToken(mphf, token, isLast) — prefix-aware resolution

Tokenizer

  • tokenize(text) / tokenizeKeepStopWords(text) / isAllStopWords(text)
  • STOP_WORDS_BY_LANG — stop word sets for ES, PT, EN

Helpers

  • dniToRuc(dni) — Peru DNI to RUC conversion (publicly documented SUNAT formula)

Storage interface

interface Storage {
  get(key: string, options?: {
    range?: { offset: number; length: number };
  }): Promise<StorageObject | null>;
}

interface StorageObject {
  arrayBuffer(): Promise<ArrayBuffer>;
}

Implement this against R2, S3, the filesystem, an in-memory map, or anything else.

Build tools (Node.js only)

The build entry uses fs / readline / path and is not Cloudflare-Workers-safe. Import it from a separate path:

import { buildBinaryFiles, buildSearchIndex } from '@latinfo/engine/build';
  • buildBinaryFiles(tsvPath, outDir, baseName, opts) — builds .idx + sharded .bin files
  • buildSearchIndex(tsvPath, outDir, baseName, opts, totalRecords) — builds V2/V3 search index + posting shards

Binary format

The engine reads its own binary format, designed for content-addressed object storage:

  • .idx — prefix index (~hundreds of KB, cached in memory)
  • .bin — sorted records, sharded at 200 MB each
  • -search.idx + -search-N.dat — V2/V3 inverted index with inline name + status

Shards are content-addressed by sha256 in your storage layer. A small manifest pointer (~1 KB) commits the version atomically — readers always see consistent state.

Credits

The MPHF implementation is based on Limasset et al., "Fast and Scalable Minimal Perfect Hashing for Massive Key Sets" (2017). MurmurHash3 by Austin Appleby (public domain).

License

MIT