composable-normalize

2.0.3 • Public • Published

API stability npm version JavaScript Style Guide

composable-normalize

Experiment to normalize URLs w/ functional programming

Install

npm i --save-dev composable-normalize

Usage

import {normalize} from 'composable-normalize'
 
normalize('HTTP://www.Github.com/')
//=> 'http://www.github.com/'
 
normalize('http://www.github.com/../a/b/../c/./d')
// => 'http://www.github.com/a/b/c/d/'
 
normalize('http://www.github.com:80/bar')
// => 'http://www.github.com/bar/'
 
normalize('http://www.github.com/%7Eusername/')
// => 'http://www.github.com/~username/'

also as a bonus you can do functional composition right to left 🔥

import {normalize, compose} from 'composable-normalize'
 
compose(str => `${str}bar`, normalize)('HTTP://github.com////foo/')
// => 'http://github.com/foo/bar'

Current Features

  • Dedupe slashes
  • Dedupe dots
  • Decode
  • Lowercase scheme
  • Remove default http/https ports
  • Adds trailing slash

Todos

  • Add Tests
  • Publish to npm
  • Add Options?

Package Sidebar

Install

npm i composable-normalize

Weekly Downloads

0

Version

2.0.3

License

MIT

Last publish

Collaborators

  • davidchase