All Projects → medialize → Uri.js

medialize / Uri.js

Licence: mit
Javascript URL mutation library

Programming Languages

javascript
184084 projects - #8 most used programming language
HTML
75241 projects
CSS
56736 projects
PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to Uri.js

uri
A type to represent, query, and manipulate a Uniform Resource Identifier.
Stars: ✭ 16 (-99.74%)
Mutual labels:  url, uri, url-parser, uri-template
ocaml-uri
RFC3986 URI parsing library for OCaml
Stars: ✭ 85 (-98.61%)
Mutual labels:  url, uri, rfc-3986
ST-OpenUri
The ultimate Sublime Text plugin for opening URIs (URLs) in your file.
Stars: ✭ 25 (-99.59%)
Mutual labels:  url, uri
url-normalize
URL normalization for Python
Stars: ✭ 82 (-98.66%)
Mutual labels:  url, uri
Kit-UrlParser
RFC 3986 compliant url parsing library with PSR-7 Uri component
Stars: ✭ 31 (-99.49%)
Mutual labels:  uri, rfc-3986
Scala Uri
Simple scala library for building and parsing URIs
Stars: ✭ 225 (-96.32%)
Mutual labels:  url, uri
Pguri
uri type for PostgreSQL
Stars: ✭ 235 (-96.16%)
Mutual labels:  url, uri
Searchwithmybrowser
Open Cortana searches with your default browser.
Stars: ✭ 285 (-95.34%)
Mutual labels:  url, uri
url
A C++ library that implements the URL WhatWG specification
Stars: ✭ 35 (-99.43%)
Mutual labels:  url, url-parser
Linkt
A lightweight and simple Kotlin library for deep link handling on Android 🔗.
Stars: ✭ 101 (-98.35%)
Mutual labels:  url, uri
uri-query-parser
a parser and a builder to work with URI query string the right way in PHP
Stars: ✭ 38 (-99.38%)
Mutual labels:  url, uri
Vscode Remote Workspace
Multi protocol support for handling remote files like local ones in Visual Studio Code.
Stars: ✭ 197 (-96.78%)
Mutual labels:  url, uri
Tldts
JavaScript Library to work against complex domain names, subdomains and URIs.
Stars: ✭ 151 (-97.53%)
Mutual labels:  url, uri
Uri Components
League URI components objects
Stars: ✭ 244 (-96.01%)
Mutual labels:  url, uri
Bidi
Bidirectional URI routing
Stars: ✭ 941 (-84.62%)
Mutual labels:  url, uri
Uri
🌏 Functions for making sense out of URIs in PHP
Stars: ✭ 259 (-95.77%)
Mutual labels:  url, uri
UrlCombine
C# util for combining Url paths. Works similarly to Path.Combine.
Stars: ✭ 23 (-99.62%)
Mutual labels:  url, uri
Uri Parser
RFC3986/RFC3987 compliant URI parser
Stars: ✭ 342 (-94.41%)
Mutual labels:  url, uri
E2guardian
E2guardian is a web content filter that can work in proxy, transparent or icap server modes
Stars: ✭ 340 (-94.44%)
Mutual labels:  url
Snake
A silly snake game on the browser URL
Stars: ✭ 512 (-91.63%)
Mutual labels:  url

URI.js

CDNJS


IMPORTANT: You may not need URI.js anymore! Modern browsers provide the URL and URLSearchParams interfaces.


NOTE: The npm package name changed to urijs


I always want to shoot myself in the head when looking at code like the following:

var url = "http://example.org/foo?bar=baz";
var separator = url.indexOf('?') > -1 ? '&' : '?';

url += separator + encodeURIComponent("foo") + "=" + encodeURIComponent("bar");

Things are looking up with URL and the URL spec but until we can safely rely on that API, have a look at URI.js for a clean and simple API for mutating URIs:

var url = new URI("http://example.org/foo?bar=baz");
url.addQuery("foo", "bar");

URI.js is here to help with that.

API Example

// mutating URLs
URI("http://example.org/foo.html?hello=world")
  .username("rodneyrehm")
    // -> http://[email protected]/foo.html?hello=world
  .username("")
    // -> http://example.org/foo.html?hello=world
  .directory("bar")
    // -> http://example.org/bar/foo.html?hello=world
  .suffix("xml")
    // -> http://example.org/bar/foo.xml?hello=world
  .query("")
    // -> http://example.org/bar/foo.xml
  .tld("com")
    // -> http://example.com/bar/foo.xml
  .query({ foo: "bar", hello: ["world", "mars"] });
    // -> http://example.com/bar/foo.xml?foo=bar&hello=world&hello=mars

// cleaning things up
URI("?&foo=bar&&foo=bar&foo=baz&")
  .normalizeQuery();
    // -> ?foo=bar&foo=baz

// working with relative paths
URI("/foo/bar/baz.html")
  .relativeTo("/foo/bar/world.html");
    // -> ./baz.html

URI("/foo/bar/baz.html")
  .relativeTo("/foo/bar/sub/world.html")
    // -> ../baz.html
  .absoluteTo("/foo/bar/sub/world.html");
    // -> /foo/bar/baz.html

// URI Templates
URI.expand("/foo/{dir}/{file}", {
  dir: "bar",
  file: "world.html"
});
// -> /foo/bar/world.html

See the About Page and API Docs for more stuff.

Using URI.js

URI.js (without plugins) has a gzipped weight of about 7KB - if you include all extensions you end up at about 13KB. So unless you need second level domain support and use URI templates, we suggest you don't include them in your build. If you don't need a full featured URI mangler, it may be worth looking into the much smaller parser-only alternatives listed below.

URI.js is available through npm, bower, bowercdn, cdnjs and manually from the build page:

# using bower
bower install uri.js

# using npm
npm install urijs

Browser

I guess you'll manage to use the build tool or follow the instructions below to combine and minify the various files into URI.min.js - and I'm fairly certain you know how to <script src=".../URI.min.js"></script> that sucker, too.

Node.js and NPM

Install with npm install urijs or add "urijs" to the dependencies in your package.json.

// load URI.js
var URI = require('urijs');
// load an optional module (e.g. URITemplate)
var URITemplate = require('urijs/src/URITemplate');

URI("/foo/bar/baz.html")
  .relativeTo("/foo/bar/sub/world.html")
    // -> ../baz.html

RequireJS

Clone the URI.js repository or use a package manager to get URI.js into your project.

require.config({
  paths: {
    urijs: 'where-you-put-uri.js/src'
  }
});

require(['urijs/URI'], function(URI) {
  console.log("URI.js and dependencies: ", URI("//amazon.co.uk").is('sld') ? 'loaded' : 'failed');
});
require(['urijs/URITemplate'], function(URITemplate) {
  console.log("URITemplate.js and dependencies: ", URITemplate._cache ? 'loaded' : 'failed');
});

Minify

See the build tool or use Google Closure Compiler:

// ==ClosureCompiler==
// @compilation_level SIMPLE_OPTIMIZATIONS
// @output_file_name URI.min.js
// @code_url http://medialize.github.io/URI.js/src/IPv6.js
// @code_url http://medialize.github.io/URI.js/src/punycode.js
// @code_url http://medialize.github.io/URI.js/src/SecondLevelDomains.js
// @code_url http://medialize.github.io/URI.js/src/URI.js
// @code_url http://medialize.github.io/URI.js/src/URITemplate.js
// ==/ClosureCompiler==

Resources

Documents specifying how URLs work:

Informal stuff

How other environments do things

Discussion on Hacker News

Forks / Code-borrow

  • node-dom-urls passy's partial implementation of the W3C URL Spec Draft for Node
  • urlutils cofounders' window.URL constructor for Node

Alternatives

If you don't like URI.js, you may like one of the following libraries. (If yours is not listed, drop me a line…)

Polyfill

URL Manipulation

URL Parsers

URI Template

Various

Authors

Contains Code From

License

URI.js is published under the MIT license. Until version 1.13.2 URI.js was also published under the GPL v3 license - but as this dual-licensing causes more questions than helps anyone, it was dropped with version 1.14.0.

Changelog

moved to Changelog

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].