{"id":21989010,"url":"https://github.com/imweb/node-pac","last_synced_at":"2025-07-24T16:20:22.251Z","repository":{"id":57159083,"uuid":"75487824","full_name":"imweb/node-pac","owner":"imweb","description":"Node版pac脚本解析器","archived":false,"fork":false,"pushed_at":"2018-06-30T02:13:27.000Z","size":29,"stargazers_count":12,"open_issues_count":0,"forks_count":3,"subscribers_count":29,"default_branch":"master","last_synced_at":"2025-07-04T07:08:04.844Z","etag":null,"topics":["js","node","pac","script"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/imweb.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-12-03T17:07:32.000Z","updated_at":"2022-06-10T18:21:07.000Z","dependencies_parsed_at":"2022-09-08T09:02:20.228Z","dependency_job_id":null,"html_url":"https://github.com/imweb/node-pac","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/imweb/node-pac","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imweb%2Fnode-pac","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imweb%2Fnode-pac/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imweb%2Fnode-pac/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imweb%2Fnode-pac/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/imweb","download_url":"https://codeload.github.com/imweb/node-pac/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imweb%2Fnode-pac/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266870510,"owners_count":23998250,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-24T02:00:09.469Z","response_time":99,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["js","node","pac","script"],"created_at":"2024-11-29T19:27:23.162Z","updated_at":"2025-07-24T16:20:22.223Z","avatar_url":"https://github.com/imweb.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# node-pac\r\n[![node version](https://img.shields.io/badge/node.js-%3E=_0.10-green.svg?style=flat-square)](http://nodejs.org/download/)\r\n[![build status](https://img.shields.io/travis/imweb/node-pac.svg?style=flat-square)](https://travis-ci.org/imweb/node-pac)\r\n[![Test coverage](https://codecov.io/gh/imweb/node-pac/branch/master/graph/badge.svg?style=flat-square)](https://codecov.io/gh/imweb/node-pac)\r\n[![David deps](https://img.shields.io/david/imweb/node-pac.svg?style=flat-square)](https://david-dm.org/imweb/node-pac)\r\n[![License](https://img.shields.io/npm/l/node-pac.svg?style=flat-square)](https://www.npmjs.com/package/node-pac)\r\n\r\nNode版pac脚本解析器。\r\n\r\n# 安装\r\n\r\n\tnpm install --save node-pac\r\n\r\n# 用法\r\n\r\n\tvar Pac = require('node-pac');\r\n\tvar pac = new Pac('https://raw.githubusercontent.com/imweb/node-pac/master/test/scripts/normal.pac');\r\n\r\n\tpac.FindProxyForURL('http://9v.cn/index.html', function(err, res)　{\r\n\t\tconsole.log(err, res);\r\n\t});\r\n\r\n# API\r\n1. `Pac`: 构造函数，可以通过`new Pac(options)`或`Pac(options)`两种方式生成Pac对象，其中： options为pac文件内容、本地的pac文件路径、或者http[s]链接，或者为以下对象：\r\n\r\n\t\t｛\r\n\t\t\turl: 'pac文件内容、本地的pac文件路径、或者http[s]链接',\r\n\t\t\ttimeout: 'url为http[s]链接时才生效，设置请求的超时时间，默认5000ms',\r\n\t\t\tcacheTime: '缓存pac脚本的时间，在缓存时间内，node-pac不会重新拉起pac脚本'\r\n\t\t\t//默认为30s，超过这个时间用户再请求时会重新拉取脚本\r\n\t\t\t//也可以通过下面的pac.forceUpdate()强制刷新\r\n\r\n\t\t｝\r\n\r\n2. `pac.FindProxyForURL(url, cb)`或者 `pac.findProxyForURL(url, cb)`: 通过请求url异步获取该请求的代理设置，cb的参数及返回值如下\r\n\r\n\t\tfunction cb(err, res){\r\n\t\t\t//err: 解析出错时的错误对象\r\n\t\t\t//res: 解析成功返回的代理设置，如：PROXY 127.0.0.1:8080; \r\n\t\t\t//或 SOCKS 127.0.0.1:1080;\r\n\t\t}\r\n\r\n\tPS: 如果解析过程出错，按实际情况给出提示，或者直接默认为`DIRECT;`\r\n\r\n3. `pac.FindWhistleProxyForURL(url, cb)`或者 `pac.findWhistleProxyForURL(url, cb)`: 通过请求url异步获取该请求的[whistle](https://github.com/avwo/whistle)代理设置，cb的参数及返回值如下\r\n\r\n\t\tfunction cb(err, res){\r\n\t\t\t//err: 解析出错时的错误对象\r\n\t\t\t//res: 解析成功返回的代理设置，如：proxy://127.0.0.1:8080 \r\n\t\t\t//或 socks://127.0.0.1:1080\r\n\t\t}\r\n\r\n4. `pac.update()`: 重新获取本地或远程的pac脚本并刷新pac对象内部解析脚本，如果获取失败继续使用上一个缓存的内容，一般node-pac会自动更新，无需手动调用该方法，除非程序能确切获取脚本更新的事件或确实需要强制更新才需使用该方法。\r\n\r\n5. `pac.forceUpdate()`: 强制重新获取本地或远程的pac脚本并刷新pac对象内部解析脚本，如果获取失败调用`pac.FindProxyForURL(url, cb)`时会把错误传给cb，一般node-pac会自动更新，无需手动调用该方法，除非程序能确切获取脚本更新的事件或确实需要强制更新才需使用该方法。\r\n\r\n# License\r\n[MIT](https://github.com/imweb/node-pac/blob/master/LICENSE)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimweb%2Fnode-pac","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fimweb%2Fnode-pac","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimweb%2Fnode-pac/lists"}