tidy-path-tree
Path tree that used Prefix Tree(Trie Tree)
Installation
$ npm install tidy-path-tree --save
Usage
// for typescript tree.add'/a/b/:name', 'data' /** * will returns : { * path: 'a/b/:name', * params: { * name: '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"> " <JSIdentifier> "*"? ( ReGroup "*"? )?
Path examples:
- /
- /part1
- part1/part2
- /part1/part2/**
- /test/:name/:type
- /test/:country([a-z]+)/:name([a-z]+)?/:code?([0-9]+)