lyndseybrowning / trie-prefix-tree

Create and modify trie prefix structures and extract word lists including prefixes, anagrams and sub-anagrams
48 stars 14 forks source link

Add caseSensitive parameter #11

Open shanghungshih opened 2 years ago

shanghungshih commented 2 years ago

Thanks for this useful module!!

In my use case, I have to treat the words with case-sensitive, and I realized the trie would convert the word to lowercase no matter what. So I added a parameter called caseSensitive with default value false to fit your original design.

I publish a temporary npm module called trie-prefix-tree-v1.6. Try the example below!

const trie = require('trie-prefix-tree');
const trieWithCaseSensitive = require('trie-prefix-tree-v1.6');

const words = ['abc DEF', 'ABC DEF'];
const input = trie(words);
const inputWithCaseSensitive = trieWithCaseSensitive(words, true);

console.log(`getPrefix of 'a' from input: ${input.getPrefix('a')}`);
console.log(`getPrefix of 'a' from inputWithCaseSensitive: ${inputWithCaseSensitive.getPrefix('a')}`);
/*
getPrefix of 'a' from input: abc def
getPrefix of 'a' from inputWithCaseSensitive: abc DEF
*/