https://github.com/ganevdev/split-proxy
Split proxy string into Object: protocol, host, port, login and password.
https://github.com/ganevdev/split-proxy
Last synced: 10 months ago
JSON representation
Split proxy string into Object: protocol, host, port, login and password.
- Host: GitHub
- URL: https://github.com/ganevdev/split-proxy
- Owner: ganevdev
- License: mit
- Created: 2019-02-11T01:29:17.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2023-12-23T21:25:35.000Z (about 2 years ago)
- Last Synced: 2025-03-31T21:01:54.368Z (11 months ago)
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/split-proxy
- Size: 20.5 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Split Proxy
[](http://npm.im/split-proxy)
Split proxy string into object wish protocol, host, port, login and password.
```bash
npm i split-proxy
```
## Examples
```js
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'
// }
```
```js
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'
// }
```
```js
const splitProxy = require('split-proxy');
splitProxy('http://localhost:9005');
// return this:
// {
// protocol: 'http',
// host: 'localhost',
// port: '9005',
// login: '',
// password: ''
// }
```
```js
const splitProxy = require('split-proxy');
splitProxy('https://www.example.com:9005');
// return this:
// {
// protocol: 'https',
// host: 'www.example.com',
// port: '9005',
// login: '',
// password: ''
// }
```
```js
const splitProxy = require('split-proxy');
splitProxy('123.123.2.42');
// return this:
// {
// protocol: '',
// host: '123.123.2.42',
// port: '',
// login: '',
// password: ''
// }
```
```js
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](https://www.npmjs.com/package/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`.
```js
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'
// }
// }
```
```js
const splitProxy = require('split-proxy');
splitProxy('123.123.2.42:8080', { mode: 'axios' });
// return this:
// {
// host: '123.123.2.42',
// port: 8080
// }
```
```js
const splitProxy = require('split-proxy');
splitProxy('localhost', { mode: 'axios' });
// return this:
// {
// host: 'localhost',
// port: 80
// }
```
## node-tunnel examples
Mode for [node-tunnel](https://github.com/koichik/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`.
```js
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'
// }
```
```js
const splitProxy = require('split-proxy');
splitProxy('123.123.2.42:8080', { mode: 'node-tunnel' });
// return this:
// {
// host: '123.123.2.42',
// port: 8080
// }
```
```js
const splitProxy = require('split-proxy');
splitProxy('localhost', { mode: 'node-tunnel' });
// return this:
// {
// host: 'localhost',
// port: 80
// }
```