0.1.4 • Published 8 years ago

path-exec v0.1.4

Weekly downloads
3
License
MIT
Repository
github
Last release
8 years ago

Path-Exec

A simple route control to execute actions.

How Install

Use npm to install path-exec

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

0.1.4

8 years ago

0.1.3

8 years ago

0.1.2

8 years ago

0.1.1

8 years ago

0.1.0

8 years ago