Skip to content
master
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
src
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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.

By default host: 'localhost' and port: 80.

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',
//   port: 80
// }

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.

By default host: 'localhost' and port: 80.

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',
//   port: 80
// }

About

Split proxy string into Object: protocol, host, port, login and password.

Resources

License

Releases

No releases published

Packages

No packages published