Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

registrie

Package Overview
Dependencies
Maintainers
0
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

registrie

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.

  • 0.9.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
0
Created
Source

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

Keywords

FAQs

Package last updated on 26 Sep 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc