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 🙏

© 2024 – Pkg Stats / Ryan Hefner

registrie

v0.9.1

Published

A flexible trie-based registry for storing and querying entries with optional hierarchical keys. `Registrie` supports both simple key-value stores and complex nested structures, making it a versatile tool for various applications.

Downloads

9

Readme

RegisTrie

npm versionLicense: MIT

A flexible trie-based registry for storing and querying entries with optional hierarchical keys. Registrie supports both simple key-value stores and complex nested structures, making it a versatile tool for various applications.

Installation

To install Registrie using npm:

npm install registrie

Or with yarn:

yarn add registrie

Usage

Registrie can be used as either a simple key-value store or a more complex registry for nested entries.

Basic Example

If no entryKey is provided, Registrie behaves as a simple key-value registry.

import { Registrie } from 'registrie';

// Create a new registry
const basicRegistry = Registrie<string>();

// Register entries
basicRegistry.register('apple', 'A tasty fruit');
basicRegistry.register('banana', 'A yellow fruit');

// Query entries
console.log(basicRegistry.query('apple')); // Output: 'A tasty fruit'

// Get suggestions for a partial key
console.log(basicRegistry.candidate('b')); // Output: ['banana']

// Erase an entry
basicRegistry.erase('apple');
console.log(basicRegistry.query('apple')); // Output: undefined

Nested Example

If entryKey is provided, Registrie supports nested structures. This is useful for managing hierarchical data where each entry has a key and potentially children.

import { Registrie } from 'registrie';

interface Category {
  name: string;
  subCategories?: Category[];
}

// Create a nested registry
const nestedRegistry = Registrie<Category>('name', 'subCategories');

// Define categories
const fruits: Category = {
  name: 'fruits',
  subCategories: [{ name: 'apple' }, { name: 'banana' }]
};

const vegetables: Category = {
  name: 'vegetables',
  subCategories: [{ name: 'carrot' }, { name: 'broccoli' }]
};

// Register categories
nestedRegistry.register(fruits);
nestedRegistry.register(vegetables);

// Query entries
console.log(nestedRegistry.query('fruits apple')); // Output: { name: 'apple' }

// Get suggestions
console.log(nestedRegistry.candidate('fruits')); // Output: ['apple', 'banana']

API

BasicRegistrie<T = any>

register(key: string, value: T, frozen?: boolean): void

Registers an entry in the registry.

  • key: The key to use for the entry.
  • value: The entry to register.
  • frozen: If true (default), registers the entry as frozen (immutable).

query(key: string): T | undefined

Queries the registry for an entry by its key.

  • key: The key to search for in the registry.

candidate(key: string): string[]

Provides suggestions for a partial key input.

  • key: The partial key to use for suggestions.

erase(key: string): void

Erases an entry from the registry.

  • key: The key of the entry to remove.

NestedRegistrie<T extends object>

register(value: T, frozen?: boolean): void

Registers a nested entry in the registry.

  • value: The entry to register.
  • frozen: If true (default), registers the entry as frozen (immutable).

query(key: string): T | undefined

Queries the registry for an entry by its key.

  • key: The key to search for in the registry.

candidate(key: string): Array<T[keyof T]>

Provides suggestions for a partial key input.

  • key: The partial key to use for suggestions.

erase(key: string): void

Erases an entry and its children from the registry.

  • key: The key of the entry to remove.

License

MIT License © Higuma Soft