Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/namusyaka/howl.js
This is a simple path router for use in client side
https://github.com/namusyaka/howl.js
Last synced: about 1 month ago
JSON representation
This is a simple path router for use in client side
- Host: GitHub
- URL: https://github.com/namusyaka/howl.js
- Owner: namusyaka
- Created: 2014-01-26T14:46:54.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2014-02-22T17:24:31.000Z (over 10 years ago)
- Last Synced: 2024-09-11T03:13:32.162Z (2 months ago)
- Language: JavaScript
- Homepage:
- Size: 242 KB
- Stars: 1
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Howl.js
Howl.js is a simple path router for use in client side
## Usage
### Class methods
#### `Howl.map`
```javascript
var router = Howl.map(function(router) {
function commonCallback(bar, baz) {
console.log('bar : ' + bar + ', baz : ' + baz);
}
router.on('/foo/:bar/:baz', { bar : /^\d+$/, baz : /^\w+$/ }).to(commonCallback);
router.on('/hoge/:bar/:baz', commonCallback);
});// Calls commonCallback, and then returns returned value of callback function.
router.call('/foo/123/test'); // 'bar : 123, baz : test'// Returns `null` if cannot find a matched route.
router.call('/foo/test/123'); // null;
```### Instance methods
#### `#on`
Registers route to routes.
```javascript
var howl = new Howl();// Quick usage
howl.on('/foo/', function() { console.log('this is foo') });
howl.on('/users/:name/:action', { name : /^\w+$/, action : /^post$|^get$/ }, function(name, action) {
console.log('Hello, ' + name);
console.log('Let us' + action + '!');
});
```### `#call`
Calls recognized route, and then executes callback function.
```javascript
var howl = new Howl();// Quick usage
howl.on('/foo/', function() { console.log('this is foo') });
howl.on('/users/:name/:action', { name : /^\w+$/, action : /^post$|^get$/ }, function(name, action) {
console.log('Hello, ' + name);
console.log('Let us' + action + '!');
});howl.call('/users/namusyaka/post'); // 'Hello, namusyaka'
// 'Let us post!'
```## License
The MIT License
## Author
namusyaka