Nonstop Pajama Models

    node-match-path
    TypeScript icon, indicating that this package has built-in type declarations

    0.6.3 • Public • Published

    Package version

    node-match-path

    Matches a URL against the given path.

    Getting started

    Install

    npm install node-match-path

    Usage

    const { match } = require('node-match-path')
    
    match('/user/:userId', '/user/5')
    /*
    {
      matches: true,
      params: {
        userId: '5'
      }
    }
    */

    API

    match(path: RegExp | string, url: string): Match

    Returns a match data, if any, between a url and a path.

    String path

    match('/admin', '/admin')
    
    /*
    {
      matches: true,
      params: null
    }
    */

    Path parameters

    match('/admin/:messageId', '/admin/abc-123')
    
    /*
    {
      matches: true,
      params: {
        messageId: 'abc-123'
      }
    }
    */

    Wildcard

    match('/user/*/inbox', '/user/abc-123/inbox')
    
    /*
    {
      matches: true,
      params: null
    }
    */

    Regular expression

    match(/\/messages\/.+?\/participants/, '/messages/5/participants')
    
    /*
    {
      matches: true,
      params: null
    }
    */

    Honorable mentions

    Install

    npm i node-match-path

    DownloadsWeekly Downloads

    490,532

    Version

    0.6.3

    License

    MIT

    Unpacked Size

    6.13 kB

    Total Files

    11

    Last publish

    Collaborators

    • kettanaito