path-exec
v0.1.4
Published
A simple route control to execute actions.
Downloads
34
Readme
Path-Exec
A simple route control to execute actions.
How Install
npm install --save path-exec
How Used
Create a paths control, this save a function and is executed when matched with path.exec()
const PathExec = require('path-exec')
let paths = new PathExec()
paths.use(pathName, keys, execFunction)
Write a path match with paths.use()
paths.use('/say/:name', ['name'], function () {
// run this function with paths.exec('/say/...'), Ej: /say/jhon, /say/abc, /say/any, ...
})
The
pathName
use path-to-regexp
paths.exec()
Use to match all paths defined with paths.use
.
// paths.use('/say/:name' ...
// paths.use('/say/:name?/role' ...
// paths.use('/say/:name?/setting/:option' ...
paths
.exec('/say/role')
.then(function () {
// has run '/say/:name?/role'
})
Customize parameters
Defined with path value.
// Use
paths
.use('/say/:action', ['action'], function (params, valued, next) {
console.log(`Is Say ${params.action} with ${valued}`)
next()
})
// Execut
paths
.exec('/say/hello', 34)
.then(function () {
console.log('is ok') // § ~ . ・§
})
Change Logs
Please see the changelog on CHANGELOG.md
License
Please see the license MIT on LICENSE