Skip to content

Instantly share code, notes, and snippets.

@bouzuya
Last active Jul 16, 2016
Embed
What would you like to do?
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

This comment has been minimized.

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