Skip to content

Instantly share code, notes, and snippets.

@bouzuya
Last active July 16, 2016 12:56
Show Gist options
  • Save bouzuya/647039fa9fe5173f276def55590b6500 to your computer and use it in GitHub Desktop.
Save bouzuya/647039fa9fe5173f276def55590b6500 to your computer and use it in GitHub Desktop.
bath - A simple path template engine

bath

A simple path template engine.

Usage

$ npm install bath
import assert from 'assert';
import bath from 'bath';

const { path, params } = bath('/users/:id');

assert.deepEqual(path({ id: '123' }) === '/users/123');
assert.deepEqual(params('/users/123'), { id: '123' });
import assert from 'assert';
import { path, params } from 'bath';

assert.deepEqual(path('/users/:id')({ id: '123' }) === '/users/123');
assert.deepEqual(params('/users/:id')('/users/123'), { id: '123' });

Types

type Path = string;
type Params = { [key: string]: string; };
type Template = string;
type bath = (tempate: Template) => {
  params: (path: Path) => Params | undefined;
  path: (params?: Params) => Path;
};
@bouzuya
Copy link
Author

bouzuya commented Jul 16, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment