index.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. "use strict";
  2. var __importDefault = (this && this.__importDefault) || function (mod) {
  3. return (mod && mod.__esModule) ? mod : { "default": mod };
  4. };
  5. const get_uri_1 = __importDefault(require("get-uri"));
  6. const url_1 = require("url");
  7. const agent_1 = __importDefault(require("./agent"));
  8. function createPacProxyAgent(uri, opts) {
  9. // was an options object passed in first?
  10. if (typeof uri === 'object') {
  11. opts = uri;
  12. // result of a url.parse() call?
  13. if (opts.href) {
  14. if (opts.path && !opts.pathname) {
  15. opts.pathname = opts.path;
  16. }
  17. opts.slashes = true;
  18. uri = url_1.format(opts);
  19. }
  20. else {
  21. uri = opts.uri;
  22. }
  23. }
  24. if (!opts) {
  25. opts = {};
  26. }
  27. if (typeof uri !== 'string') {
  28. throw new TypeError('a PAC file URI must be specified!');
  29. }
  30. return new agent_1.default(uri, opts);
  31. }
  32. (function (createPacProxyAgent) {
  33. createPacProxyAgent.PacProxyAgent = agent_1.default;
  34. /**
  35. * Supported "protocols". Delegates out to the `get-uri` module.
  36. */
  37. createPacProxyAgent.protocols = Object.keys(get_uri_1.default.protocols);
  38. createPacProxyAgent.prototype = agent_1.default.prototype;
  39. })(createPacProxyAgent || (createPacProxyAgent = {}));
  40. module.exports = createPacProxyAgent;
  41. //# sourceMappingURL=index.js.map