package/package.json000644 0000001045 3560116604 011546 0ustar00000000 000000 { "name": "url-to-options", "description": "Convert a WHATWG URL to an http(s).request options object.", "version": "2.0.0", "license": "MIT", "author": "Steven Vachon (https://svachon.com)", "repository": "github:stevenvachon/url-to-options", "devDependencies": { "semver": "^6.0.0", "universal-url": "^2.0.0" }, "engines": { "node": ">=8" }, "scripts": { "test": "node test.js" }, "files": [ "index.js" ], "keywords": [ "http", "https", "url", "whatwg" ] } package/index.js000644 0000001240 3560116604 010722 0ustar00000000 000000 'use strict'; // Copied from https://github.com/nodejs/node/blob/master/lib/internal/url.js function urlToOptions(url) { var options = { protocol: url.protocol, hostname: typeof url.hostname === 'string' && url.hostname.startsWith('[') ? url.hostname.slice(1, -1) : url.hostname, hash: url.hash, search: url.search, pathname: url.pathname, path: `${url.pathname || ''}${url.search || ''}`, href: url.href }; if (url.port !== '') { options.port = Number(url.port); } if (url.username || url.password) { options.auth = `${url.username}:${url.password}`; } return options; } module.exports = urlToOptions; package/LICENSE000644 0000002056 3560116604 010270 0ustar00000000 000000 MIT License Copyright (c) 2017 Steven Vachon 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. package/README.md000644 0000001511 3560116604 010535 0ustar00000000 000000 # url-to-options [![NPM Version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] > Convert a WHATWG [`URL`](https://developer.mozilla.org/en/docs/Web/API/URL) to an `http.request`/`https.request` options object. ## Installation [Node.js](http://nodejs.org/) `>= 8` is required. To install, type this at the command line: ```shell npm install url-to-options ``` ## Usage ```js const urlToOptions = require('url-to-options'); const url = new URL('http://user:pass@hostname:8080/'); const opts = urlToOptions(url); //-> { auth:'user:pass', port:8080, … } ``` [npm-image]: https://img.shields.io/npm/v/url-to-options.svg [npm-url]: https://npmjs.org/package/url-to-options [travis-image]: https://img.shields.io/travis/stevenvachon/url-to-options.svg [travis-url]: https://travis-ci.org/stevenvachon/url-to-options