path-to-regexp-loader

0.2.0 • Public • Published

path-to-regexp loader for Webpack

How to Install

npm install path-to-regexp-loader --save-dev

How to Use

Given a routes.json file that may look like this:

[
  { "path": "/tasks", "component": "TodoList" },
  { "path": "/tasks/:id(\\d+)", "component": "TodoItem" }
]

You can parse it by using path-to-regexp-loader:

var routes = require('!!path-to-regexp-loader!./routes.json');
// => returns routes.json content as JSON parsed object
[
  {
    path: '/tasks',
    pattern: /^\/tasks(?:\/(?=$))?$/i,
    keys: [],
    component: 'TodoList'
  },
  {
    path: '/tasks/:id(\\d+)',
    pattern: /^\/tasks\/((?:\d+))(?:\/(?=$))?$/i,
    keys: [
      {
        name: 'id',
        prefix: '/',
        delimiter: '/',
        optional: false,
        repeat: false,
        partial: false,
        asterisk: false,
        pattern: '\\d+'
      }
    ],
    component: 'TodoItem'
  }
]

Related Projects

License

MIT © 2016-present Konstantin Tarkus (@koistya)

Package Sidebar

Install

npm i path-to-regexp-loader

Weekly Downloads

1

Version

0.2.0

License

MIT

Last publish

Collaborators

  • koistya