tidy-path-tree
TypeScript icon, indicating that this package has built-in type declarations

1.0.19 • Public • Published

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 "*"? )?

Path examples:

  • /
  • /part1
  • part1/part2
  • /part1/part2/**
  • /test/:name/:type
  • /test/:country([a-z]+)/:name([a-z]+)?/:code?([0-9]+)

Readme

Keywords

none

Package Sidebar

Install

npm i tidy-path-tree

Weekly Downloads

4

Version

1.0.19

License

MIT

Unpacked Size

37.7 kB

Total Files

6

Last publish

Collaborators

  • guopi.pro