@crossbrowsertesting/pac-resolver

中文文档
3.0.2发布于 2021/04/15MITCommonJS近 30 天下载 3880

Generates an asynchronous resolver function from a PAC file

原始使用文档
文档目录6 节
  1. Generates an asynchronous resolver function from a PAC file
  2. Installation
  3. Example
  4. API
  5. pac(String jsStr[, Object options]) → Function
  6. License

pac-resolver

Generates an asynchronous resolver function from a PAC file

Build Status

This module accepts a JavaScript String of code, which is meant to be a PAC proxy file, and returns a generated asynchronous FindProxyForURL() function.

Installation

Install with npm:

$ npm install pac-resolver

Example

Given the PAC proxy file named proxy.pac:

function FindProxyForURL(url, host) {
  if (isInNet(myIpAddress(), "10.1.10.0", "255.255.255.0")) {
    return "PROXY 1.2.3.4:8080";
  } else {
    return "DIRECT";
  }
}

You can consume this PAC file with pac-resolver like so:

var fs = require('fs');
var pac = require('pac-resolver');

var FindProxyForURL = pac(fs.readFileSync('proxy.pac'));

FindProxyForURL('http://foo.com/').then((res) => {
  console.log(res);
  // "DIRECT"
});

API

pac(String jsStr[, Object options]) → Function

Returns an asynchronous FindProxyForURL() function based off of the given JS string jsStr PAC proxy file. An optional options object may be passed in which respects the following options:

  • filename - String - the filename to use in error stack traces. Defaults to proxy.pac.
  • sandbox - Object - a map of functions to include in the sandbox of the JavaScript environment where the JS code will be executed. i.e. if you wanted to include the common alert function you could pass alert: console.log. For async functions, you must set the async = true property on the function instance, and the JS code will be able to invoke the function as if it were synchronous.

License

(The MIT License)

Copyright (c) 2013 Nathan Rajlich <[email protected]>

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.

版本与发布记录

@crossbrowsertesting/pac-resolver 共发布 2 个版本,首次发布于 2019/09/24;过去 12 个月发布了 0 个版本。

版本发布日期距今
3.0.2latest2021/04/155 年前
3.0.12019/09/247 年前

关于 @crossbrowsertesting/pac-resolver 的常见问题

@crossbrowsertesting/pac-resolver 是什么?

Generates an asynchronous resolver function from a PAC file

如何安装 @crossbrowsertesting/pac-resolver?

在项目目录运行 npm install @crossbrowsertesting/pac-resolver,或使用 pnpm add / yarn add / bun add。

@crossbrowsertesting/pac-resolver 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/crossbrowsertesting__pac-resolver 是否存在。

@crossbrowsertesting/pac-resolver 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@crossbrowsertesting/pac-resolver 可以商用吗?

@crossbrowsertesting/pac-resolver 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@crossbrowsertesting/pac-resolver 的下载量有多少?

根据 npm 官方下载统计,@crossbrowsertesting/pac-resolver 在 2026/10/11 – 2026/11/09 这 30 天内被下载 3,880 次,日均约 129 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@crossbrowsertesting/pac-resolver 还在维护吗?

最新版本 3.0.2 发布于 2021/04/15(5 年前);至今共发布 2 个版本,其中过去 12 个月发布了 0 个;首次发布于 2019/09/24。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。