pax_global_header00006660000000000000000000000064131614121050014504gustar00rootroot0000000000000052 comment=040579fb1271df6232dd96a7600c9efb1510eb47 prepend-http-2.0.0/000077500000000000000000000000001316141210500141155ustar00rootroot00000000000000prepend-http-2.0.0/.editorconfig000066400000000000000000000002571316141210500165760ustar00rootroot00000000000000root = true [*] indent_style = tab end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true [*.yml] indent_style = space indent_size = 2 prepend-http-2.0.0/.gitattributes000066400000000000000000000000351316141210500170060ustar00rootroot00000000000000* text=auto *.js text eol=lf prepend-http-2.0.0/.gitignore000066400000000000000000000000271316141210500161040ustar00rootroot00000000000000node_modules yarn.lock prepend-http-2.0.0/.npmrc000066400000000000000000000000231316141210500152300ustar00rootroot00000000000000package-lock=false prepend-http-2.0.0/.travis.yml000066400000000000000000000000631316141210500162250ustar00rootroot00000000000000language: node_js node_js: - '8' - '6' - '4' prepend-http-2.0.0/index.js000066400000000000000000000006031316141210500155610ustar00rootroot00000000000000'use strict'; module.exports = (url, opts) => { if (typeof url !== 'string') { throw new TypeError(`Expected \`url\` to be of type \`string\`, got \`${typeof url}\``); } url = url.trim(); opts = Object.assign({https: false}, opts); if (/^\.*\/|^(?!localhost)\w+:/.test(url)) { return url; } return url.replace(/^(?!(?:\w+:)?\/\/)/, opts.https ? 'https://' : 'http://'); }; prepend-http-2.0.0/license000066400000000000000000000021251316141210500154620ustar00rootroot00000000000000MIT License Copyright (c) Sindre Sorhus (sindresorhus.com) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. prepend-http-2.0.0/package.json000066400000000000000000000011561316141210500164060ustar00rootroot00000000000000{ "name": "prepend-http", "version": "2.0.0", "description": "Prepend `http://` to humanized URLs like todomvc.com and localhost", "license": "MIT", "repository": "sindresorhus/prepend-http", "author": { "name": "Sindre Sorhus", "email": "sindresorhus@gmail.com", "url": "sindresorhus.com" }, "engines": { "node": ">=4" }, "scripts": { "test": "xo && ava" }, "files": [ "index.js" ], "keywords": [ "prepend", "protocol", "scheme", "url", "uri", "http", "https", "humanized" ], "devDependencies": { "ava": "*", "xo": "*" } } prepend-http-2.0.0/readme.md000066400000000000000000000015361316141210500157010ustar00rootroot00000000000000# prepend-http [![Build Status](https://travis-ci.org/sindresorhus/prepend-http.svg?branch=master)](https://travis-ci.org/sindresorhus/prepend-http) > Prepend `http://` to humanized URLs like `todomvc.com` and `localhost` ## Install ``` $ npm install prepend-http ``` ## Usage ```js const prependHttp = require('prepend-http'); prependHttp('todomvc.com'); //=> 'http://todomvc.com' prependHttp('localhost'); //=> 'http://localhost' prependHttp('http://todomvc.com'); //=> 'http://todomvc.com' prependHttp('todomvc.com', {https: true}); //=> 'https://todomvc.com' ``` ## API ### prependHttp(url, [options]) #### url Type: `string` URL to prepend `http://` on. #### options Type: `Object` ##### https Type: `boolean`
Default: `false` Prepend `https://` instead of `http://`. ## License MIT © [Sindre Sorhus](https://sindresorhus.com) prepend-http-2.0.0/test.js000066400000000000000000000015461316141210500154400ustar00rootroot00000000000000import test from 'ava'; import m from '.'; test('prepend http', t => { t.is(m('todomvc.com'), 'http://todomvc.com'); t.is(m('http://todomvc.com'), 'http://todomvc.com'); t.is(m('https://todomvc.com'), 'https://todomvc.com'); t.is(m('//todomvc.com'), '//todomvc.com'); t.is(m('localhost'), 'http://localhost'); t.is(m('localhost:8000'), 'http://localhost:8000'); t.is(m('localhost:8000 '), 'http://localhost:8000'); t.is(m('./relative'), './relative'); t.is(m('../relative'), '../relative'); t.is(m('/relative'), '/relative'); t.is(m('mailto:info@site.com'), 'mailto:info@site.com'); t.is(m('tel:1234567890'), 'tel:1234567890'); }); test('https option', t => { t.is(m('todomvc.com', {https: true}), 'https://todomvc.com'); t.is(m('//todomvc.com', {https: true}), '//todomvc.com'); t.is(m('localhost:8000', {https: true}), 'https://localhost:8000'); });