Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

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