Giter Club home page Giter Club logo

erl's Introduction

Erl

Codeship Status for sporto/erl

A URL parsing and construction library for ELM

parse a url string

-- Given a url string
url = "http://sam:[email protected]:3000/products/kids?color=red&age=10#toys/1"

Erl.parse url 

-- Returns a Erl.Url record:

{
  protocol: "http",
  username: "sam",
  password: "pass",
  host: ["api", "example", "com"],
  port': 3000,
  path: ["products", "kids"],
  hash: "toys/1",
  hasTrailingSlash: False,
  query: Dict {
    "color": "red",
    "age": "10"
  }
}

See MDN for more details (https://developer.mozilla.org/en-US/docs/Web/API/Location). Note that in MDN query is called search.

Construct

new

-- Construct an empty Erl.Url record:

url = 
  Erl.new

Mutations

-- Modify the protocol
{ url | protocol = "https" }

-- Modify host
{url | host = ["api", "acme", "com"] }

-- Modify port
{ url | port' = 9000 }

-- Modify path
{url | path = ["users", "1"] }

-- Modify path by appending segments
Erl.appendPathSegments url ["users", "1"]

-- Modify hash
{url | hash = "users/1" }

-- Clear query string
Erl.clearQuery url

-- Add one query string key/value (patches previous query string)
Erl.addQuery "key" "value" url

-- Remove one query string key/value
Erl.removeQuery "key" url

-- Replaces query string with key/value (removes any previous keys)
Erl.setQuery "key" "value" url

toString

-- Given a Erl.Url record (url):

Erl.toString url 

-- Returns the url as string:

"http://www.foo.com:2000/users/1?k=2&q=1#a/b"

Documentation

Documentation at package.elm-lang.org

Test

elm-package install
npm i
npm test

Todo

  • Username
  • Password
  • Maybe more convenience methods for updating parts

Changelog

  • 9.0.0 Added hasTrailingSlash
  • 8.0.0 hash is a string, not a list anymore
  • 7.3.0 Added hashToString
  • 7.2.0 Added queryToString
  • 7.1.0 Added appendPathSegments
  • 7.0.0 Hash goes after query as per https://url.spec.whatwg.org/
  • 6.0.0 setQuery replaces the whole query, Added addQuery and removeQuery
  • 5.0.1 setQuery removes the key when passed an empty value
  • 5.0.0 Renamed fragment to hash to aling with the MDN documentation better

erl's People

Contributors

imccoy avatar

Watchers

 avatar  avatar  avatar

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.