Skip to main content

CaseSensitivity

Enumerates the case sensitivity options for matching and replacement.
enum CaseSensitivity {
  Insensitive = 'i',
  Sensitive = ''
}
Insensitive
'i'
The matching is case-insensitive, and replacement should take into account the case of the initial of the “from”. If the “from” starts with a capital (ignoring all symbols), then so will the replacement.
Sensitive
''
The matching is case-sensitive, so the replacement’s first initial will not reflect the initial casing of the first letter of the “from”.

Example

import { CaseSensitivity } from 'trie-rules';

const rule = {
  from: ['hello'],
  to: 'hi',
  options: { casing: CaseSensitivity.Insensitive }
};

MatchType

Enumerates the types of matches that can be performed.
enum MatchType {
  Alone = 'a',
  Any = '',
  Whole = 'w'
}
Alone
'a'
The rule should match the word when it appears alone, surrounded by whitespace.
Any
''
The rule should match the word in any context, regardless of surrounding characters.
Whole
'w'
The rule should match the word as a whole, ensuring it is not part of a larger word.

Example

import { MatchType } from 'trie-rules';

const rule = {
  from: ['test'],
  to: 'exam',
  options: { match: MatchType.Whole }
};
// Matches "test" but not "testing"

TriePattern

Enumerates predefined patterns for clipping during search and replace operations.
enum TriePattern {
  Apostrophes = 'apostrophes'
}
Apostrophes
'apostrophes'
Represents apostrophe-like characters used in word boundaries or contractions.

Example

import { TriePattern } from 'trie-rules';

const rule = {
  from: ['word'],
  to: 'replacement',
  options: { clipEndPattern: TriePattern.Apostrophes }
};
// Clips apostrophe-like characters at the end of matches

Build docs developers (and LLMs) love