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 🙏

© 2025 – Pkg Stats / Ryan Hefner

pacparser

v0.0.6

Published

A library to parse proxy auto-config (PAC) files in JavaScript.

Readme

Pacparser

codecov

A library to parse proxy auto-config (PAC) files in Node.js.

It run pac script in a Node.js vm and execute findProxy method.

Installation

npm install pacparser # use in node.js
npm install pacparser -g # use as a command line tool

Usage

You can create a new instance of Pacparser and load a PAC file like this:

import Pacparser from "pacparser";
const pacParser = new Pacparser();
pacParser.parsePac("https://proxy.example.com/proxy.pac");
const proxy = await pacParser.findProxy("https://direct.mozilla.org");

Or like this:

import Pacparser from "pacparser";
const pacParser = Pacparser.create(path.join(__dirname, "./proxy.pac"));
await pacParser.findProxy("https://direct.mozilla.org"); // returns "DIRECT"

You can input a pac source (filepath or url or pac script) by

new Pacparser(pac); // return a new instance
Pacparser.create(pac); // return a new instance , same as new Pacparser(pac)
pacParser.parsePac(path); // switch pac source by call parsePac() in pacParser instance

And then you can find proxy by call findProxy()

await pacParser.findProxy(url); // return a promise
await pacParser.findProxy("https://direct.mozilla.org"); // returns "DIRECT"

CLI

pacparser exec

You can use pacparser as a cli tool to parse pac file.

pacparser exec --pac './proxy.pac' --findproxy https://www.google.com # DIRECT
# Or use shortcut command
pap exec -p './proxy.pac' -f https://www.google.com # DIRECT

pap exec -p  'function FindProxyForURL(url, host) {
  if (
    (isPlainHostName(host) || dnsDomainIs(host, ".mozilla.org")) &&
    !localHostOrDomainIs(host, "www.mozilla.org") &&
    !localHostOrDomainIs(host, "merchant.mozilla.org") &&
    !localHostOrDomainIs(host, "www.google.com")
  ) {
    return "DIRECT";
  } else {
    return "PROXY w3proxy.mozilla.org:8080; DIRECT";
  }
}' -f https://www.google.com  # PROXY w3proxy.mozilla.org:8080; DIRECT

pap exec -p  http://localhost:3000/proxy.pac -f https://www.google.com  # DIRECT

pacparser builtin functions

pap builtin -f isPlainHostName -i www.google.com  # false
pap builtin -f isResolvable -i www.google.com  # true
pap builtin -f isInNet -i www.google.com,192.168.1.0,255.255.255.0 # false
pap builtin -f isInNet -i "192.168.1.1","192.168.1.0","255.255.255.0" # true
pap builtin -f myIpAddress  # 192.168.1.65

API

Pacparser

The main class.

static Pacparser.create(path?string)

Create a new instance of Pacparser.

pacparser.parsePac(pac:string): pacparser instance

switch pac source (filepath or url or pac script) by call parsePac() in pacParser instance, it return the pacparser instance, so you can chain call.

const pacParser = Pacparser.create();
pacParser.parsePac(path.join(__dirname, "./proxy.pac")).findProxy("https://direct.mozilla.org");

pacparser.findProxy(url) : Promise<string>

Find the proxy for a given URL.

pacparser.cleanup()

Cleanup the pacparser instance pac source

pacparser.getPacSource()

Get pac source in pacparser instance

pacparser.getPacCode()

Get pac code in pacparser instance

pacparser.reload()

If pac source is changed,it will reload pac source

Builtin functions

Pacparser provides some builtin functions to help you write your pac script. you can read more about them in Proxy Auto-Configuration (PAC) file

import {
  isPlainHostName,
  dnsDomainIs,
  localHostOrDomainIs,
  isResolvable,
  isInNet,
  dnsResolve,
  convert_addr,
  myIpAddress,
  shExpMatch,
  dnsDomainLevels,
  weekdayRange,
  dateRange,
  timeRange,
  alter,
} from "pacparser";

isPlainHostName("www.mozilla.org"); // false
isPlainHostName("www"); // true
dnsDomainIs("www.mozilla.org", ".mozilla.org") // true
localHostOrDomainIs("www.mozilla.org", "www.mozilla.org") // true (exact match)
isResolvable("www.mozilla.org") // true
dateRange(1, "JUN", 1995, 15, "AUG", 1995);
isInNet("192.168.1.1", "192.168.1.0", "255.255.255.0")
convert_addr("192.0.2.172"); // returns the decimal number 1745889538
dnsDomainLevels("www.mozilla.org"); // 2
...

License

MIT