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

@uruhalushia/rule-converter-wasm

v0.3.2

Published

WebAssembly bindings for browser usage. This package exposes payload-based conversion only; file and directory APIs stay in the CLI/N-API packages.

Readme

@uruhalushia/rule-converter-wasm

WebAssembly bindings for browser usage. This package exposes payload-based conversion only; file and directory APIs stay in the CLI/N-API packages.

Build

Install the wasm target and wasm-pack first:

rustup target add wasm32-unknown-unknown
cargo install wasm-pack
pnpm --dir wasm build

The build scripts pass --no-opt because current Rust emits bulk-memory instructions that older bundled wasm-opt builds may reject. Browser runtimes support these instructions.

For bundlers such as Vite/Webpack:

pnpm --dir wasm build:bundler

Local Usage After Build

After running pnpm --dir wasm build, the browser-ready package is generated in wasm/pkg. The files in pkg are ignored by git and can be served directly during local development.

Browser Without A Bundler

Create an HTML file outside pkg, then import the generated module by relative path:

<!doctype html>
<meta charset="utf-8" />
<button id="convert">convert</button>
<script type="module">
  import init, { strToBuf } from './wasm/pkg/rule_converter_wasm.js'

  await init()

  document.querySelector('#convert').addEventListener('click', () => {
    const result = strToBuf(
      `payload:\n  - DOMAIN,example.com\n  - DOMAIN-SUFFIX,example.net\n`,
      {
        inputTarget: 'mihomo',
        inputFormat: 'yaml',
        inputBehavior: 'classical',
        outputTarget: 'mihomo',
        outputFormat: 'mrs',
        outputBehavior: 'domain',
      },
    )

    const bytes = result.outputs.domain
    console.log(result.info.domain.behavior, result.info.domain.format, result.info.domain.count, bytes)
  })
</script>

Serve the repository directory with any static server; opening the file directly with file:// usually fails because WebAssembly modules are fetched asynchronously.

python -m http.server 5173
# open http://localhost:5173/your-test.html

Bundler / Vite / Webpack

Build the bundler package first:

pnpm --dir wasm build:bundler

Then install the generated local package in your web app:

pnpm add file:/home/atri/git/xishang/rule-converter/wasm/pkg

Use it from app code:

import init, { strToBuf } from '@uruhalushia/rule-converter-wasm'

await init()

const result = strToBuf(
  `payload:\n  - DOMAIN,example.com\n  - DOMAIN-SUFFIX,example.net\n`,
  {
    inputTarget: 'mihomo',
    inputFormat: 'yaml',
    inputBehavior: 'classical',
    outputTarget: 'mihomo',
    outputFormat: 'mrs',
    outputBehavior: 'domain',
  },
)

for (const [name, bytes] of Object.entries(result.outputs)) {
  console.log(name, result.info[name].behavior, result.info[name].format, result.info[name].count, bytes)
}

The returned bytes value is a Uint8Array, so it can be downloaded, uploaded, or stored in IndexedDB directly.

MMDB list APIs also accept uploaded file bytes:

import init, { listAsnNumbers, listGeoipCountries, listGeoipDatCountries, listGeositeCodes } from '@uruhalushia/rule-converter-wasm'

await init()

const bytes = new Uint8Array(await file.arrayBuffer())
console.log(listGeoipCountries(bytes))
console.log(listAsnNumbers(bytes))
console.log(listGeoipDatCountries(geoipDatBytes))
console.log(listGeositeCodes(geositeDatBytes))

DB conversions use the same bufToBuf / bufToStr functions. For example:

const db = new Uint8Array(await mmdbFile.arrayBuffer())
const cn = bufToStr(db, {
  inputTarget: 'geoip',
  inputFormat: 'mmdb',
  outputTarget: 'general',
  outputFormat: 'ipset',
  countries: ['cn'],
  split: false,
})
const dat = bufToBuf(db, {
  inputTarget: 'geoip',
  inputFormat: 'mmdb',
  outputTarget: 'geoip',
  outputFormat: 'dat',
})
const geositeRules = bufToStr(geositeDatBytes, {
  inputTarget: 'geosite',
  inputFormat: 'dat',
  outputTarget: 'general',
  outputFormat: 'ruleset',
  codes: ['cn'],
  split: false,
})

Use detectBuf / detectStr to inspect uploaded input without converting it:

import init, { detectBuf } from '@uruhalushia/rule-converter-wasm'

await init()
console.log(detectBuf(new Uint8Array(await file.arrayBuffer())))

Rule matching uses the same input options as conversion. Mihomo config input is supported when providers use local path/file:// references supplied by the host application; browser HTTP provider downloads should be handled by the caller before matching:

import init, { matchStr } from '@uruhalushia/rule-converter-wasm'

await init()
const result = matchStr('DOMAIN-SUFFIX,example.com\n', 'ads.example.com', {
  inputTarget: 'general',
  inputFormat: 'text',
  inputBehavior: 'classical',
})
console.log(result.matched, result.rules)

Options use the same names as the N-API package:

type RuleTarget = 'mihomo' | 'general' | 'egern' | 'sing-box'
type InputFormat = 'yaml' | 'mrs' | 'text' | 'adguard' | 'json' | 'srs' | 'domainset' | 'ruleset' | 'ipset' | 'mmdb' | 'sing-db' | 'metadb' | 'dat' | 'sing-geosite'
type OutputFormat = 'mrs' | 'text' | 'adguard' | 'yaml' | 'json' | 'srs' | 'domainset' | 'ruleset' | 'ipset' | 'mmdb' | 'sing-db' | 'metadb' | 'dat' | 'sing-geosite'
type InputBehavior = 'auto' | 'domain' | 'ip' | 'classical'
type OutputBehavior = 'domain' | 'ip' | 'classical'

Defaults are outputTarget: 'mihomo', outputFormat: 'mrs', and outputBehavior: 'domain'.