Skip to content

vovacodes/url-schemify

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

url-schemify

Tiny module for adding scheme to URLs

Build Status Coverage Status

Usage

To install module run:

npm i -S url-schemify

or

npm install --save url-schemify

then require module in your script:

var schemify = require('url-schemify');
var assert = require('assert');

// url-schemify adds default scheme (http) to the URLs that miss it

assert.equal(schemify('google.com'), 'http://google.com');
assert.equal(schemify('www.example.com'), 'http://www.example.com');

// default scheme could be configured through the options parameter

assert.equal(schemify('google.com', { scheme: 'https' }), 'https://google.com');
// { scheme: '' } will produce protocol-related URL
assert.equal(schemify('www.example.com', { scheme: '' }), '//www.example.com');

// url-schemify doesn't modify URLs that already have scheme or protocol-related ones:

assert.equal(schemify('http://google.com'), 'http://google.com');
assert.equal(schemify('https://www.example.com'), 'https://www.example.com');
assert.equal(schemify('ftp://example.com'), 'ftp://example.com');
assert.equal(schemify('//example.com'), '//example.com');

About

Tiny module for adding scheme to URLs

Resources

Stars

Watchers

Forks

Packages

No packages published