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

@lokascript/patterns-reference

v1.3.0

Published

Queryable patterns database for hyperscript with multilingual translations and LLM support

Readme

@lokascript/patterns-reference

Queryable patterns database for hyperscript with multilingual translations and LLM few-shot learning support.

Installation

npm install @lokascript/patterns-reference

Quick Start

The package ships with a pre-populated SQLite database containing:

  • 106 code examples covering hyperscript commands and real-world UI patterns
  • 1,378 translations (106 patterns × 13 languages)
  • 414 LLM few-shot examples for code generation

No setup required - just install and use:

Use the API

import { createPatternsReference } from '@lokascript/patterns-reference';

// Create a patterns reference instance
const ref = createPatternsReference({
  dbPath: './data/patterns.db',
  readonly: true,
});

// Query patterns
const pattern = await ref.getPatternById('toggle-class-basic');
console.log(pattern?.rawCode); // 'on click toggle .active'

// Search patterns
const results = await ref.searchPatterns('toggle');

// Get LLM examples for few-shot learning
const examples = await ref.getLLMExamples('toggle a class on click');

// Get statistics
const stats = await ref.getStats();
console.log(`Total patterns: ${stats.totalPatterns}`);

// Clean up
ref.close();

API Reference

Pattern Queries

// Get pattern by ID
getPatternById(id: string): Promise<Pattern | null>

// Get patterns by category (e.g., 'class-manipulation', 'visibility')
getPatternsByCategory(category: string): Promise<Pattern[]>

// Get patterns containing a specific command
getPatternsByCommand(command: string): Promise<Pattern[]>

// Full-text search across title, code, and description
searchPatterns(query: string, options?: SearchOptions): Promise<Pattern[]>

// Get all patterns (paginated)
getAllPatterns(options?: SearchOptions): Promise<Pattern[]>

// Get pattern statistics
getPatternStats(): Promise<PatternStats>

Translations

// Get translation for a specific language
getTranslation(patternId: string, language: string): Promise<Translation | null>

// Get all translations for a pattern
getAllTranslations(patternId: string): Promise<Translation[]>

// Verify a translation parses correctly
verifyTranslation(translation: Translation): Promise<VerificationResult>

LLM Support

// Get examples matching a prompt (for few-shot learning)
getLLMExamples(prompt: string, language?: string, limit?: number): Promise<LLMExample[]>

// Get examples by command type
getExamplesByCommand(command: string, language?: string, limit?: number): Promise<LLMExample[]>

// Get high-quality examples
getHighQualityExamples(language?: string, minQuality?: number, limit?: number): Promise<LLMExample[]>

// Build formatted context for LLM prompting
buildFewShotContext(prompt: string, language?: string, numExamples?: number): Promise<string>

// Get LLM example statistics
getLLMStats(): Promise<{ total: number; byLanguage: Record<string, number>; avgQuality: number; totalUsage: number }>

Configuration

Database Path

The database path can be configured via:

  1. Constructor option:

    createPatternsReference({ dbPath: '/path/to/db.sqlite' });
  2. Environment variables:

    export LSP_DB_PATH="/path/to/db.sqlite"
    # or
    export HYPERSCRIPT_LSP_DB="/path/to/db.sqlite"

Scripts (Development Only)

These scripts are for contributors regenerating the database. End users don't need these - the database ships pre-populated.

| Script | Description | | --------------------------- | -------------------------------------------------------- | | npm run populate | Full database setup (init + translations + LLM examples) | | npm run db:init | Initialize database with seed patterns | | npm run db:init:force | Reinitialize database (overwrites existing) | | npm run sync:translations | Generate translations for all 13 languages | | npm run seed:llm | Generate LLM few-shot examples | | npm run validate | Validate all patterns parse correctly | | npm run validate:fix | Validate and update verified_parses flag | | npm run build | Build the package | | npm test | Run tests in watch mode | | npm run test:run | Run tests once |

Database Schema

code_examples

Pattern source code from the hyperscript cookbook.

| Column | Type | Description | | ----------- | ---- | ------------------------------------- | | id | TEXT | Unique identifier | | title | TEXT | Human-readable title | | raw_code | TEXT | Hyperscript code | | description | TEXT | Pattern description | | feature | TEXT | Category (e.g., 'class-manipulation') | | created_at | TEXT | Creation timestamp |

pattern_translations

Multilingual translations of patterns.

| Column | Type | Description | | --------------- | ------- | -------------------------------- | | id | INTEGER | Auto-increment ID | | code_example_id | TEXT | Foreign key to code_examples | | language | TEXT | Language code (en, ja, es, etc.) | | hyperscript | TEXT | Translated code | | word_order | TEXT | SVO, SOV, VSO, or V2 | | confidence | REAL | Translation confidence (0-1) | | verified_parses | INTEGER | Whether translation parses (0/1) |

llm_examples

Prompt/completion pairs for few-shot learning.

| Column | Type | Description | | --------------- | ------- | ---------------------------- | | id | INTEGER | Auto-increment ID | | code_example_id | TEXT | Foreign key to code_examples | | language | TEXT | Language code | | prompt | TEXT | Natural language prompt | | completion | TEXT | Hyperscript code | | quality_score | REAL | Quality rating (0-1) | | usage_count | INTEGER | Retrieval count |

Supported Languages

The database supports 13 languages with different word orders:

| Language | Code | Word Order | | ---------- | ---- | ---------- | | English | en | SVO | | Spanish | es | SVO | | French | fr | SVO | | Portuguese | pt | SVO | | Indonesian | id | SVO | | Swahili | sw | SVO | | Chinese | zh | SVO | | Japanese | ja | SOV | | Korean | ko | SOV | | Turkish | tr | SOV | | Quechua | qu | SOV | | Arabic | ar | VSO | | German | de | V2 |

Integration with @lokascript/semantic

The patterns-reference package integrates with @lokascript/semantic to provide runtime pattern matching from the database.

Semantic Bridge

import { initializeSemanticIntegration } from '@lokascript/patterns-reference';

// Initialize integration (registers database as pattern source)
const result = await initializeSemanticIntegration();

if (result.success) {
  console.log(`Registered with: ${result.registeredWith}`);
  // 'semantic' if @lokascript/semantic is available
  // 'standalone' if running without semantic package
}

// Query patterns directly
import { queryPatterns, getSupportedLanguages } from '@lokascript/patterns-reference';

const jaPatterns = await queryPatterns('ja');
const languages = await getSupportedLanguages();

LLM Adapter (for @lokascript/core)

The package provides a unified LLM adapter that replaces the deprecated llm-examples-query.ts:

import { findRelevantExamples, buildFewShotContextSync } from '@lokascript/patterns-reference';

// Find examples matching a prompt
const examples = findRelevantExamples('toggle a class on click', 'en', 5);

// Build formatted context for LLM prompting
const context = buildFewShotContextSync('show a modal', 'en', 3);

Development

# Install dependencies
npm install

# Full database setup
npm run populate

# Run tests
npm test

# Validate translations
npm run validate

# Build
npm run build

Troubleshooting

Native Module Installation

This package uses better-sqlite3, a native Node.js module. If you encounter installation errors:

macOS:

xcode-select --install  # Install Xcode command line tools

Linux (Debian/Ubuntu):

sudo apt-get install build-essential python3

Windows:

npm install --global windows-build-tools

better-sqlite3 ships with prebuilt binaries for most platforms, so compilation is usually not required. If you encounter issues, ensure you're using a supported Node.js version (18, 20, or 22 LTS).

Database Not Found

If you get "database not found" errors, the database path may not be resolving correctly. Set it explicitly:

import { createPatternsReference } from '@lokascript/patterns-reference';
import { join } from 'path';

const ref = createPatternsReference({
  dbPath: join(__dirname, 'node_modules/@lokascript/patterns-reference/data/patterns.db'),
});

Or use environment variables:

export LSP_DB_PATH="/absolute/path/to/patterns.db"

License

MIT