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

@6digit/mnemonics

v0.3.0

Published

Dynamic semantic evaluation system for Fragment data using Subscript expressions

Readme

@6digit/mnemonics

Dynamic semantic evaluation system for Fragment data using Subscript expressions with recursive dependency resolution.

Features

  • 🧠 Dynamic Evaluation: Evaluate Subscript expressions against Fragment data
  • 🔄 Recursive Dependencies: Mnemonics can depend on other mnemonics
  • Request-Scoped Caching: Prevent duplicate evaluations within requests
  • 🛡️ Cycle Detection: Automatic detection and prevention of circular dependencies
  • 🎯 Schema Targeting: Apply mnemonics only to specific Fragment schemas
  • 📊 Performance Tracking: Built-in cache statistics and monitoring
  • 🔒 Type Safe: Full TypeScript support with comprehensive type definitions

Installation

npm install @6digit/mnemonics

Quick Start

import { MnemonicEvaluator, MnemonicRepository } from '@6digit/mnemonics';

// Implement your repository (connects to your data store)
class MyMnemonicRepository implements MnemonicRepository {
  async getMnemonicByName(name: string) {
    // Fetch mnemonic from your database
    return {
      name: 'luxury_item',
      expression: 'price > 1000 && brand == "Gucci"',
      description: 'Identifies luxury items'
    };
  }
  
  async getAllMnemonics() {
    // Return all mnemonics
  }
  
  async getMnemonicsForSchema(schemaId: string) {
    // Return schema-specific mnemonics
  }
}

// Create evaluator
const evaluator = new MnemonicEvaluator({
  repository: new MyMnemonicRepository(),
  defaultMaxDepth: 10,
  defaultInitialContext: { Math, Date }
});

// Evaluate a mnemonic
const fragment = {
  id: 'fragment-123',
  schemaId: 'product-schema',
  data: { price: 1200, brand: 'Gucci', category: 'handbag' }
};

const result = await evaluator.evaluate('luxury_item', fragment);
console.log(result.result); // true

Recursive Dependencies

Mnemonics can depend on other mnemonics:

// Define dependent mnemonics
const mnemonics = [
  {
    name: 'luxury_item',
    expression: 'price > 1000 && brand == "Gucci"'
  },
  {
    name: 'affordable_luxury', 
    expression: 'luxury_item && price < 5000'
  }
];

// The evaluator automatically resolves dependencies
const result = await evaluator.evaluate('affordable_luxury', fragment);
// Automatically evaluates 'luxury_item' first, then 'affordable_luxury'

Schema Targeting

Restrict mnemonics to specific Fragment schemas:

const mnemonic = {
  name: 'expensive_product',
  expression: 'price > 100',
  targetSchemaIds: ['product-schema', 'item-schema']
};

// Only evaluates if fragment.schemaId matches target schemas

Batch Evaluation

Evaluate multiple mnemonics efficiently:

const results = await evaluator.evaluateMany(
  ['luxury_item', 'affordable_luxury', 'trending'],
  fragment
);

console.log(results.luxury_item.result); // true/false
console.log(results.affordable_luxury.result); // true/false

Error Handling

The package provides specific error types:

import { 
  MnemonicNotFoundError,
  MnemonicExpressionError,
  MnemonicCyclicDependencyError,
  MnemonicMaxDepthError 
} from '@6digit/mnemonics';

try {
  const result = await evaluator.evaluate('unknown_mnemonic', fragment);
} catch (error) {
  if (error instanceof MnemonicNotFoundError) {
    console.log('Mnemonic not found');
  } else if (error instanceof MnemonicCyclicDependencyError) {
    console.log('Circular dependency detected');
  }
}

Performance Monitoring

Track cache performance and statistics:

const cache = createRequestScopedCache();
const stats = cache.getStats();

console.log(`Cache hits: ${stats.hits}`);
console.log(`Cache misses: ${stats.misses}`);
console.log(`Hit ratio: ${cache.getHitRatio()}`);

API Reference

MnemonicEvaluator

The main class for evaluating mnemonics.

Constructor

new MnemonicEvaluator(config: MnemonicEvaluatorConfig)

Methods

  • evaluate(mnemonicName: string, fragment: Fragment, options?: EvaluationOptions): Promise<EvaluationResult>
  • evaluateMany(mnemonicNames: string[], fragment: Fragment, options?: EvaluationOptions): Promise<Record<string, EvaluationResult>>
  • getStats(): Promise<{repository: string, defaultMaxDepth: number, mnemonicCount: number}>

Types

See the types documentation for complete type definitions.

License

MIT