1.0.19 • Published 5 years ago
tidy-path-tree v1.0.19
tidy-path-tree
Path tree that used Prefix Tree(Trie Tree)
Installation
$ npm install tidy-path-tree --save
Usage
// for typescript
import { PathTree } from 'tidy-path-tree'
const tree = new PathTree<string>()
tree.add('/a/b/:name', 'data')
/**
* will returns : {
* path: 'a/b/:name',
* params: {
* name: 'tidy'
* }
* }
*/
const found = tree.find('/a/b/tidy')
Path Grammar
Path: Layer ( Layer Delimiter )* GlobStarEnd?
Layer: Seg*
Seg: Param | Text | ReGroup
GlobStarEnd: Delimiter "**"
ReGroup: "(" <RegularExpressBody> ")"
Text: TextChar+
TextChar:
- <Char not Delimiter && not in '\r\n:(/?\\'>
- BackslashChar
BackslashChar: "\" <Char not in "\r\n">
Param = ":" <JSIdentifier> "*"? ( ReGroup "*"? )?