This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Vanilla JS router | |
* | |
* An isomorphic router - works client-side (browser), or server-side (NodeJS) | |
* | |
* It resolves URL paths like '/profile/1' to route patterns such as '/profile/:id', | |
* and generates a params object that is passed to each route. | |
* | |
* Features: | |
* | |
* - Easy setup, zero dependencies |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const curry = fn => (...args) => | |
args.length >= fn.length ? fn(...args) : curry(fn.bind(undefined, ...args)) | |
const always = a => b => a | |
const compose = (...fns) => args => fns.reduceRight((x, f) => f(x), args) | |
const getFunctor = x => | |
Object.freeze({ | |
value: x, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Operators | |
const eq = (a) => (b) => a === b | |
// Types | |
const typeOf = (a) => typeof a | |
const isArray = (a) => Array.isArray(a) | |
const isUndefined = (a) => eq('undefined')(typeOf(a)) | |
// Lists | |
const reverse = (xs) => xs.reverse() |