Skip to main content

Install the package

Choose your preferred package manager to install trie-rules:
npm install trie-rules
The package is distributed as an ES module with full TypeScript type definitions included.

Package details

Requirements

Runtime requirements:
  • Node.js >= 24.0.0
  • Bun >= 1.3.9 (if using Bun)
The package is compatible with all modern JavaScript runtimes that support ES modules.

Verify installation

After installation, verify that the package is correctly installed by importing the main functions:
import { buildTrie, searchAndReplace } from 'trie-rules';

console.log(typeof buildTrie); // 'function'
console.log(typeof searchAndReplace); // 'function'

What’s included

The package exports the following functions and types:

Core functions

  • buildTrie - Constructs a trie from an array of rules
  • searchAndReplace - Performs search and replace operations using a trie
  • containsSource - Checks if a source string exists in the trie
  • containsTarget - Checks if a target string exists in the trie
  • optimizeRules - Optimizes and consolidates redundant rules

Types and enums

  • Rule - Type definition for search and replace rules
  • TrieNode - Type definition for trie data structure
  • BuildTrieOptions - Configuration options for building tries
  • SearchAndReplaceOptions - Configuration options for search operations
  • CaseSensitivity - Enum for case matching behavior
  • MatchType - Enum for match context requirements
  • TriePattern - Enum for predefined clipping patterns

Utility functions

  • adjustCasing - Adjusts replacement casing based on source
  • findFirstAlphaIndex - Finds the first alphabetic character index
  • generateCaseVariants - Generates case variants for a string
  • isAlphabeticLetter - Checks if a character is alphabetic
  • isLetter - Checks if a character is a letter
  • isLowerCase - Checks if a character is lowercase
  • isUpperCase - Checks if a character is uppercase
  • isWordCharacterAt - Checks if character at position is a word character

Constants

  • APOSTROPHE_LIKE_REGEX - Regular expression matching apostrophe-like characters
  • LETTER_REGEX - Regular expression matching any Unicode letter
All exports are available in the package entry point. You can import exactly what you need for optimal tree-shaking.

Next steps

Quick start

Jump into a quick getting started guide with working examples

Build docs developers (and LLMs) love