split-proxy
TypeScript icon, indicating that this package has built-in type declarations

2.0.0 • Public • Published

Split Proxy

Build Status npm

Split proxy string into object wish protocol, host, port, login and password.

npm i split-proxy

Examples

const splitProxy = require('split-proxy');
splitProxy('123.123.2.42:8080@superLogin:superPassword');
 
// return this:
// {
//   protocol: '',
//   host: '123.123.2.42',
//   port: '8080',
//   login: 'superLogin',
//   password: 'superPassword'
// }
const splitProxy = require('split-proxy');
splitProxy('socks5://superLogin:superPassword@123.123.2.42:8080');
 
// return this:
// {
//   protocol: 'socks5',
//   host: '123.123.2.42',
//   port: '8080',
//   login: 'superLogin',
//   password: 'superPassword'
// }
const splitProxy = require('split-proxy');
splitProxy('http://localhost:9005');
 
// return this:
// {
//   protocol: 'http',
//   host: 'localhost',
//   port: '9005',
//   login: '',
//   password: ''
// }
const splitProxy = require('split-proxy');
splitProxy('https://www.example.com:9005');
 
// return this:
// {
//   protocol: 'https',
//   host: 'www.example.com',
//   port: '9005',
//   login: '',
//   password: ''
// }
const splitProxy = require('split-proxy');
splitProxy('123.123.2.42');
 
// return this:
// {
//   protocol: '',
//   host: '123.123.2.42',
//   port: '',
//   login: '',
//   password: ''
// }
const splitProxy = require('split-proxy');
splitProxy('http://123.123.2.42');
 
// return this:
// {
//   protocol: 'http',
//   host: '123.123.2.42',
//   port: '',
//   login: '',
//   password: ''
// }

axios examples

{ mode: 'axios' } special mode for use with library axios (with proxy config options) - it returns an object with the same names and formats as required by axios. It also never returns empty values.

const splitProxy = require('split-proxy');
splitProxy('123.123.2.42:8080@superLogin:superPassword', { mode: 'axios' });
 
// return this:
// {
//   host: '123.123.2.42',
//   port: 8080,
//   auth: {
//     username: 'mikeymike',
//     password: 'rapunz3l'
//   }
// }
const splitProxy = require('split-proxy');
splitProxy('123.123.2.42:8080', { mode: 'axios' });
 
// return this:
// {
//   host: '123.123.2.42',
//   port: 8080
// }
const splitProxy = require('split-proxy');
splitProxy('localhost', { mode: 'axios' });
 
// return this:
// {
//   host: 'localhost'
// }

node-tunnel examples

Mode for node-tunnel, returns an object with the same names and formats as required by node-tunnel. It also never returns empty values.

const splitProxy = require('split-proxy');
splitProxy('123.123.2.42:8080@superLogin:superPassword', { mode: 'node-tunnel' });
 
// return this:
// {
//   host: '123.123.2.42',
//   port: 8080,
//   proxyAuth: 'superLogin:superPassword'
// }
const splitProxy = require('split-proxy');
splitProxy('123.123.2.42:8080', { mode: 'node-tunnel' });
 
// return this:
// {
//   host: '123.123.2.42',
//   port: 8080
// }
const splitProxy = require('split-proxy');
splitProxy('localhost', { mode: 'node-tunnel' });
 
// return this:
// {
//   host: 'localhost'
// }

Readme

Keywords

Package Sidebar

Install

npm i split-proxy

Weekly Downloads

29

Version

2.0.0

License

MIT

Unpacked Size

12.1 kB

Total Files

5

Last publish

Collaborators

  • ganevru