npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

node-pac

v0.5.1

Published

Node版pac脚本解析器

Downloads

5,813

Readme

node-pac

node version Test coverage License

Node版pac脚本解析器。

安装

npm install --save node-pac

用法

var Pac = require('node-pac');
var pac = new Pac('https://raw.githubusercontent.com/imweb/node-pac/master/test/scripts/normal.pac');

pac.FindProxyForURL('http://9v.cn/index.html', function(err, res) {
	console.log(err, res);
});

API

  1. Pac: 构造函数,可以通过new Pac(options)Pac(options)两种方式生成Pac对象,其中: options为pac文件内容、本地的pac文件路径、或者http[s]链接,或者为以下对象:

     {
     	url: 'pac文件内容、本地的pac文件路径、或者http[s]链接',
     	timeout: 'url为http[s]链接时才生效,设置请求的超时时间,默认5000ms',
     	cacheTime: '缓存pac脚本的时间,在缓存时间内,node-pac不会重新拉起pac脚本'
     	//默认为30s,超过这个时间用户再请求时会重新拉取脚本
     	//也可以通过下面的pac.forceUpdate()强制刷新
    
     }
  2. pac.FindProxyForURL(url, cb)或者 pac.findProxyForURL(url, cb): 通过请求url异步获取该请求的代理设置,cb的参数及返回值如下

     function cb(err, res){
     	//err: 解析出错时的错误对象
     	//res: 解析成功返回的代理设置,如:PROXY 127.0.0.1:8080; 
     	//或 SOCKS 127.0.0.1:1080;
     }

    PS: 如果解析过程出错,按实际情况给出提示,或者直接默认为DIRECT;

  3. pac.FindWhistleProxyForURL(url, cb)或者 pac.findWhistleProxyForURL(url, cb): 通过请求url异步获取该请求的whistle代理设置,cb的参数及返回值如下

     function cb(err, res){
     	//err: 解析出错时的错误对象
     	//res: 解析成功返回的代理设置,如:proxy://127.0.0.1:8080 
     	//或 socks://127.0.0.1:1080
     }
  4. pac.update(): 重新获取本地或远程的pac脚本并刷新pac对象内部解析脚本,如果获取失败继续使用上一个缓存的内容,一般node-pac会自动更新,无需手动调用该方法,除非程序能确切获取脚本更新的事件或确实需要强制更新才需使用该方法。

  5. pac.forceUpdate(): 强制重新获取本地或远程的pac脚本并刷新pac对象内部解析脚本,如果获取失败调用pac.FindProxyForURL(url, cb)时会把错误传给cb,一般node-pac会自动更新,无需手动调用该方法,除非程序能确切获取脚本更新的事件或确实需要强制更新才需使用该方法。

License

MIT