Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including format-url with all npm packages installed. Try it out:

var formatUrl = require("format-url")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

format-url v1.1.0

Light wrapper around Node.js url.format() to make life a little easier

format-url

Light wrapper around Node.js url.format() to reduce the number of checks you need to do before calling it. Designed to detect protocol and path (or lack thereof), but still get the result you expect from url.format().

Usage

$ npm install format-url
$ node
> var urlFormat = require('format-url');
undefined
> urlFormat('127.0.0.0');
'http://127.0.0.0'
> urlFormat('127.0.0.0:8080');
'http://127.0.0.0:8080'
> urlFormat('http://127.0.0.0:8080');
'http://127.0.0.0:8080'
> urlFormat('https://127.0.0.0:8080');
'https://127.0.0.0:8080'
> urlFormat('127.0.0.0:8080/path/to/things');
'http://127.0.0.0:8080/path/to/things'

Tests can be found in the test/ directory.

Licence

ISC

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free