Giter Club home page Giter Club logo

normalize_url's Introduction

normalize_url Build Status

Normalize a url. This is useful for displaying, storing, sorting, etc.

Installation

Add :normalize_url to your list of dependencies in mix.exs

def deps do
  [{:normalize_url, "~> 0.0.2"}]
end

Ensure :normalize_url is started before your application

def application do
  [applications: [:normalize_url]]
end

Usage

NormalizeUrl.normalize_url("https://www.google.com?b=b&a=a")
# => "https://google.com?a=a&b=b"

NormalizeUrl.normalize_url("//foo.bar#about")
# => "http://foo.bar"

Options

strip_www

Type: boolean
Default: true

Remove www. from the url

NormalizeUrl.normalize_url("http://www.johnotander.com")
# => "http://johnotander.com"

NormalizeUrl.normalize_url("http://www.johnotander.com", [strip_www: false])
# => "http://www.johnotander.com"
strip_fragment

Type: boolean
Default: true

Remove #framents from the url

NormalizeUrl.normalize_url("http://johnotander.com#about.html")
# => "http://johnotander.com"

NormalizeUrl.normalize_url("http://www.johnotander.com", [strip_fragment: false])
# => "http://johnotander.com#about.html"
:normalize_protocol

Type: boolean
Default: true

Normalize relative protocols

NormalizeUrl.normalize_url("//johnotander.com#about")
# => "http://johnotander.com"

NormalizeUrl.normalize_url("//www.johnotander.com", [normalize_protocol: false])
# => "//johnotander.com"
add_root_path

Type: boolean
Default: false

Adds a trailing slash for the root path, if the path is empty.

NormalizeUrl.normalize_url("http://example.com")
# => "http://example.com"

NormalizeUrl.normalize_url("http://example.com", [add_root_path: true])
# => "http://example.com/"

Development

mix test

Related

License

MIT

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Crafted with <3 by John Otander (@4lpine).

normalize_url's People

Contributors

johno avatar jaimeiniesta avatar lowks avatar

Stargazers

 avatar John Dengis avatar Thomas Athanas avatar

Watchers

James Cloos avatar  avatar  avatar

normalize_url's Issues

can't have "http://" on port 8080

The library normalises http:.//xxx:8080 to https://xxx

iex(1)> NormalizeUrl.normalize_url("http://foo.com:8080")
"https://foo.com"

8080 is (by convention) an alternate HTTP port, not an HTTPS port. There doesn't seem to be much consensus on what the alt-https port is: tho I've seen 8443 used in a couple of places. Presumably because it would require browser re-configuring.

Unused variable

lib/normalize_url.ex:30: warning: variable scheme is unused

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.