Urlz
Functional toolkit for URLs. Drop-in url
and
querystring
replacement.
Originally built for a static site generator where URL transformations are common, but use-cases
are really unlimited.
Features
- High-level URL manipulations
- Curried composable API
- Crossplatform: works in NodeJS and all modern browsers
- Extensive test suite
Dependencies:
Peer dependencies:
url
querystring
@paqmind/ramda
(temp. until basic Ramda)
Usage
$ npm install urlz
let U = // The following snippets also use shortcuts for:let R = let UU =
Glossary
http://foo.com/bar/baz
– absolute URLfoo.com/bar/baz
– invalid URL, may occur in human text (*)/bar/baz
– root-relative URL (not absolute!)bar/baz
– relative URL
- – should be specially handled with libs like
normalize-url
. We don't provide normalization heuristics here (yet).
Motivation
format
/ parse
provide limited, low-level, mutable API
1. Original There is also newer WHATWG URL
API but it doesn't support relative
URLs. Which basically makes it unusable for many scenarios. So while NodeJS renders url
as deprecated
it's still much better than WHATWG version (unsurprisingly).
urlz
is trailing slash aware
2. Trailing slash is significant in some cases. It may affect backend routing AND it affects relative URLs:
urlz
doesn't assume anything and keeps trailing slash untouched for all operations where it's possible.
urlz
respects "relativeness" and "absoluteness" of urls
3. console // "/bar/foo.txt" (+)console // "bar/foo.txt" (-) naive console // "/bar/foo.txt" (+)console // "/foo.txt/bar" (-) naive
urlz
is composition friendly
4. let R = let src = "content/team/about.md"let dst = Rsrc console // "public/team/about/index.html" // corresponding to "/team/about/" URL
urlz
is like CRUD for path fragments
5. // GETconsole // "foo"console // "bar" // UPDATEconsole // "/qux/bar/baz.txt"console // "/foo/qux/baz.txt" // DELETEconsole // "/bar/baz.txt"console // "/foo/baz.txt" // ...
urlz
provides extra utils
6. TODO: describe
API
TODO: describe