spa-town
TypeScript icon, indicating that this package has built-in type declarations

0.1.2 • Public • Published

spa-town

A simple router based on bath.

Installation

$ npm install spa-town

Usage

import * as assert from 'assert';
import { result, route, router } from 'spa-town';
 
const router1 = router([
  route('root#index', '/'),
  route('users#index', '/users'),
  route('users#index', '/users/'),
  route('users#show', '/users/{id}', { id: /^\w+$/ }),
  route('users#show', '/users/{id}/', { id: /^\w+$/ })
], result('root#notfound', {}));
 
assert.deepEqual(router1('/'), result('root#index', {}));
assert.deepEqual(router1('/users'), result('users#index', {}));
assert.deepEqual(router1('/users/'), result('users#index', {}));
assert.deepEqual(router1('/users/123'), result('users#show', { id: '123' }));
assert.deepEqual(router1('/users/123/'), result('users#show', { id: '123' }));
assert.deepEqual(router1('/no-match'), result('root#notfound', {}));

Badges

npm version Travis CI

License

MIT

Author

bouzuya <m@bouzuya.net> (http://bouzuya.net)

Dependents (1)

Package Sidebar

Install

npm i spa-town

Weekly Downloads

8

Version

0.1.2

License

MIT

Last publish

Collaborators

  • bouzuya