Install the package
Choose your preferred package manager to installtrie-rules:
The package is distributed as an ES module with full TypeScript type definitions included.
Package details
- Package name:
trie-rules - License: MIT
- Repository: github.com/ragaeeb/trie-rules
- Bundle size: View detailed bundle analysis at bundlejs.com
Requirements
Runtime requirements:
- Node.js >= 24.0.0
- Bun >= 1.3.9 (if using Bun)
Verify installation
After installation, verify that the package is correctly installed by importing the main functions:What’s included
The package exports the following functions and types:Core functions
buildTrie- Constructs a trie from an array of rulessearchAndReplace- Performs search and replace operations using a triecontainsSource- Checks if a source string exists in the triecontainsTarget- Checks if a target string exists in the trieoptimizeRules- Optimizes and consolidates redundant rules
Types and enums
Rule- Type definition for search and replace rulesTrieNode- Type definition for trie data structureBuildTrieOptions- Configuration options for building triesSearchAndReplaceOptions- Configuration options for search operationsCaseSensitivity- Enum for case matching behaviorMatchType- Enum for match context requirementsTriePattern- Enum for predefined clipping patterns
Utility functions
adjustCasing- Adjusts replacement casing based on sourcefindFirstAlphaIndex- Finds the first alphabetic character indexgenerateCaseVariants- Generates case variants for a stringisAlphabeticLetter- Checks if a character is alphabeticisLetter- Checks if a character is a letterisLowerCase- Checks if a character is lowercaseisUpperCase- Checks if a character is uppercaseisWordCharacterAt- Checks if character at position is a word character
Constants
APOSTROPHE_LIKE_REGEX- Regular expression matching apostrophe-like charactersLETTER_REGEX- Regular expression matching any Unicode letter
Next steps
Quick start
Jump into a quick getting started guide with working examples