mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-16 04:40:39 -07:00
feat: create trie programmatically in options
This commit is contained in:
committed by
Jun Yang
parent
8734e2e6ce
commit
befc33c4eb
@@ -0,0 +1,27 @@
|
||||
import { Operators } from '../render/operator'
|
||||
|
||||
export interface Trie {
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
export function createTrie (operators: Operators): Trie {
|
||||
const trie: Trie = {}
|
||||
for (const [name, handler] of Object.entries(operators)) {
|
||||
let node = trie
|
||||
|
||||
for (let i = 0; i < name.length; i++) {
|
||||
const c = name[i]
|
||||
node[c] = node[c] || {}
|
||||
|
||||
if (i === name.length - 1 && c !== '=') {
|
||||
node[c].needBoundary = true
|
||||
}
|
||||
|
||||
node = node[c]
|
||||
}
|
||||
|
||||
node.handler = handler
|
||||
node.end = true
|
||||
}
|
||||
return trie
|
||||
}
|
||||
Reference in New Issue
Block a user