pax_global_header00006660000000000000000000000064134622542750014524gustar00rootroot0000000000000052 comment=f4a79ceb9b51a622026e309e60bca987d4775cda prepend-http-3.0.1/000077500000000000000000000000001346225427500141375ustar00rootroot00000000000000prepend-http-3.0.1/.editorconfig000066400000000000000000000002571346225427500166200ustar00rootroot00000000000000root = 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-3.0.1/.gitattributes000066400000000000000000000000231346225427500170250ustar00rootroot00000000000000* text=auto eol=lf prepend-http-3.0.1/.gitignore000066400000000000000000000000271346225427500161260ustar00rootroot00000000000000node_modules yarn.lock prepend-http-3.0.1/.npmrc000066400000000000000000000000231346225427500152520ustar00rootroot00000000000000package-lock=false prepend-http-3.0.1/.travis.yml000066400000000000000000000000651346225427500162510ustar00rootroot00000000000000language: node_js node_js: - '12' - '10' - '8' prepend-http-3.0.1/index.d.ts000066400000000000000000000012271346225427500160420ustar00rootroot00000000000000declare namespace prependHttp { interface Options { /** Prepend `https://` instead of `http://`. @default true */ readonly https?: boolean; } } /** Prepend `https://` to humanized URLs like `sindresorhus.com` and `localhost`. @param url - URL to prepend `https://` to. @example ``` import prependHttp = require('prepend-http'); prependHttp('sindresorhus.com'); //=> 'https://sindresorhus.com' prependHttp('localhost', {https: false}); //=> 'http://localhost' prependHttp('https://sindresorhus.com'); //=> 'https://sindresorhus.com' ``` */ declare function prependHttp(url: string, options?: prependHttp.Options): string; export = prependHttp; prepend-http-3.0.1/index.js000066400000000000000000000006121346225427500156030ustar00rootroot00000000000000'use strict'; module.exports = (url, options) => { if (typeof url !== 'string') { throw new TypeError(`Expected \`url\` to be of type \`string\`, got \`${typeof url}\``); } url = url.trim(); options = { https: true, ...options }; if (/^\.*\/|^(?!localhost)\w+:/.test(url)) { return url; } return url.replace(/^(?!(?:\w+:)?\/\/)/, options.https ? 'https://' : 'http://'); }; prepend-http-3.0.1/index.test-d.ts000066400000000000000000000003501346225427500170130ustar00rootroot00000000000000import {expectType} from 'tsd'; import prependHttp = require('.'); const options: prependHttp.Options = {}; expectType(prependHttp('sindresorhus.com')); expectType(prependHttp('sindresorhus.com', {https: false})); prepend-http-3.0.1/license000066400000000000000000000021251346225427500155040ustar00rootroot00000000000000MIT 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-3.0.1/package.json000066400000000000000000000011701346225427500164240ustar00rootroot00000000000000{ "name": "prepend-http", "version": "3.0.1", "description": "Prepend `https://` to humanized URLs like sindresorhus.com and localhost", "license": "MIT", "repository": "sindresorhus/prepend-http", "author": { "name": "Sindre Sorhus", "email": "sindresorhus@gmail.com", "url": "sindresorhus.com" }, "engines": { "node": ">=8" }, "scripts": { "test": "xo && ava && tsd" }, "files": [ "index.js", "index.d.ts" ], "keywords": [ "prepend", "protocol", "scheme", "url", "uri", "http", "https", "humanized" ], "devDependencies": { "ava": "^1.4.1", "tsd": "^0.7.2", "xo": "^0.24.0" } } prepend-http-3.0.1/readme.md000066400000000000000000000015041346225427500157160ustar00rootroot00000000000000# prepend-http [![Build Status](https://travis-ci.org/sindresorhus/prepend-http.svg?branch=master)](https://travis-ci.org/sindresorhus/prepend-http) > Prepend `https://` to humanized URLs like `sindresorhus.com` and `localhost` ## Install ``` $ npm install prepend-http ``` ## Usage ```js const prependHttp = require('prepend-http'); prependHttp('sindresorhus.com'); //=> 'https://sindresorhus.com' prependHttp('localhost', {https: false}); //=> 'http://localhost' prependHttp('https://sindresorhus.com'); //=> 'https://sindresorhus.com' ``` ## API ### prependHttp(url, [options]) #### url Type: `string` URL to prepend `https://` to. #### options Type: `object` ##### https Type: `boolean`
Default: `true` Prepend `https://` instead of `http://`. ## License MIT © [Sindre Sorhus](https://sindresorhus.com) prepend-http-3.0.1/test.js000066400000000000000000000022621346225427500154560ustar00rootroot00000000000000import test from 'ava'; import prependHttp from '.'; test('prepend http', t => { t.is(prependHttp('sindresorhus.com', {https: false}), 'http://sindresorhus.com'); t.is(prependHttp('http://sindresorhus.com', {https: false}), 'http://sindresorhus.com'); t.is(prependHttp('https://sindresorhus.com', {https: false}), 'https://sindresorhus.com'); t.is(prependHttp('//sindresorhus.com', {https: false}), '//sindresorhus.com'); t.is(prependHttp('localhost', {https: false}), 'http://localhost'); t.is(prependHttp('localhost:8000', {https: false}), 'http://localhost:8000'); t.is(prependHttp('localhost:8000 ', {https: false}), 'http://localhost:8000'); t.is(prependHttp('./relative'), './relative'); t.is(prependHttp('../relative'), '../relative'); t.is(prependHttp('/relative'), '/relative'); t.is(prependHttp('mailto:info@site.com'), 'mailto:info@site.com'); t.is(prependHttp('tel:1234567890'), 'tel:1234567890'); }); test('https option', t => { t.is(prependHttp('sindresorhus.com', {https: true}), 'https://sindresorhus.com'); t.is(prependHttp('//sindresorhus.com', {https: true}), '//sindresorhus.com'); t.is(prependHttp('localhost:8000', {https: true}), 'https://localhost:8000'); });