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 🙏

© 2026 – Pkg Stats / Ryan Hefner

srs.ts

v1.1.2

Published

sing-box SRS rule-set compiler/decompiler for JavaScript runtimes

Readme

srs.ts

npm version GitHub License

TypeScript implementation of the sing-box binary rule-set (.srs) compiler and decompiler.

This project is a small JavaScript/TypeScript library for working with sing-box SRS files without running the Go sing-box binary. It mirrors the binary rule-set format implemented by sing-box, accepts the same plain rule-set JSON shape, and returns Uint8Array data that can be used in modern JavaScript runtimes.

It is not a TypeScript port of the full sing-box proxy platform. It does not load configs, match traffic, manage remote rule sets, or implement route/DNS behavior. It only serializes and deserializes plain headless rule sets.

Features

  • Compile sing-box plain rule-set JSON to .srs binary bytes.
  • Decompile .srs binary bytes back to plain rule-set JSON.
  • Support sing-box rule-set versions 1 through 5.
  • Support default and logical headless rules.
  • Use the sing-box SRS magic header, zlib payload, varint encoding, succinct domain matcher format, and IP set encoding.
  • Run in browsers, Bun, Deno, workers, Node-compatible bundlers, and other runtimes that support standard Uint8Array APIs.

Supported Rule Items

Default rules support these JSON fields:

  • query_type
  • network
  • domain
  • domain_suffix
  • domain_keyword
  • domain_regex
  • source_ip_cidr
  • ip_cidr
  • source_port
  • source_port_range
  • port
  • port_range
  • process_name
  • process_path
  • process_path_regex
  • package_name
  • package_name_regex
  • network_type
  • network_is_expensive
  • network_is_constrained
  • network_interface_address
  • default_interface_address
  • wifi_ssid
  • wifi_bssid
  • invert

Logical rules support type: "logical", mode: "and" | "or", nested rules, and invert.

Version-gated fields follow sing-box's binary format rules:

  • network_type, network_is_expensive, and network_is_constrained require version 3 or later.
  • network_interface_address and default_interface_address require version 4 or later.
  • package_name_regex requires version 5 or later.

The binary-only AdGuard matcher item is intentionally unsupported and will throw if encountered, because sing-box does not expose it as a normal source JSON field.

Usage

import { compile, decompile } from "srs.ts";

const ruleSet = {
  version: 4,
  rules: [
    {
      domain: ["example.com"],
      domain_suffix: ["example.org"],
      ip_cidr: ["10.0.0.0/24"]
    },
    {
      type: "logical",
      mode: "and",
      rules: [{ network: "tcp" }, { port: [80, 443] }]
    }
  ]
};

const srsBytes = compile(ruleSet);
const decoded = decompile(srsBytes);

compile() returns a Uint8Array containing the complete .srs file contents. decompile() accepts a Uint8Array containing .srs bytes and returns plain rule-set JSON.

CLI

The package also installs an srs.ts command for use with npx:

npx srs.ts compile rules.srs
npx srs.ts decompile rules.json

You can pass an explicit output path as a second argument:

npx srs.ts compile source.json output.srs
npx srs.ts decompile source.srs output.json

API

function compile(ruleSet: PlainRuleSet): Uint8Array;
function decompile(data: Uint8Array): PlainRuleSet;

The package also exports TypeScript types for PlainRuleSet, Rule, DefaultRule, LogicalRule, and related helper shapes.

Development

Install dependencies with Bun:

bun install

Run tests:

bun test

Build the package:

bun run build

If sing-box is available on PATH, the tests also perform cross-compatibility checks with sing-box rule-set compile and sing-box rule-set decompile.