colouring-montreal/app/src/frontend/nav/url-param-transform.ts

17 lines
400 B
TypeScript
Raw Normal View History

export interface UrlParamTransform<T> {
fromParam: (x: string) => T;
toParam: (x: T) => string;
}
const identity: <T>(x: T) => T = (x) => x;
export const stringParamTransform: UrlParamTransform<string> = {
fromParam: identity,
toParam: identity
};
export const intParamTransform: UrlParamTransform<number> = {
fromParam: x => parseInt(x, 10),
toParam: x => x.toString()
};