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

@virustotal/yara-x

v1.15.0

Published

JavaScript API for YARA-X

Readme

@virustotal/yara-x

JavaScript bindings for YARA-X using WebAssembly.

Installation

npm install @virustotal/yara-x

Quick Start

import init, { Compiler } from "@virustotal/yara-x";

// Initialize the WebAssembly module
await init();

// Compile a rule
const compiler = new Compiler();
compiler.addSource('rule test { strings: $a = "abc" condition: $a }');

const rules = compiler.build();

// Scan data
const payload = new Uint8Array([0x61, 0x62, 0x63, 0x64]); // "abcd"
const result = rules.scan(payload);

if (result.valid && result.matches.length > 0) {
  console.log("Rule matched!");
}

API Reference

Compiler

The Compiler translates YARA-X rules into a executable format.

  • addSource(source: string): Compiles a rule string. Throws an error if compilation fails.
  • build(): Rules: Finalizes compilation and returns a Rules object.
  • defineGlobal(identifier: string, value: any): Defines an external variable used in conditions (boolean, number, string).
  • newNamespace(namespace: string): Scopes subsequent rules to a specific namespace.
  • errors: string[]: Array of compilation error messages.
  • warnings: string[]: Array of compilation warning messages.

Rules

The Rules object represents the compiled set of rules ready for scanning.

  • scan(payload: Uint8Array): ScanResult: Scans the payload using the default scanner profile.
  • scanner(): Scanner: Spawns a dedicated Scanner for advanced configuration.
  • warnings: string[]: Warnings inherited from the compiler.

Scanner

The Scanner provides fine-grained control over scanning operations.

  • scan(payload: Uint8Array): ScanResult: Scans the payload.
  • setGlobal(identifier: string, value: any): Overrides values defined by compiler.defineGlobal().
  • setMaxMatchesPerPattern(n: number): Limits reporting to first n matches per pattern.
  • setTimeoutMs(timeout_ms: number): Sets a hard timeout for scanning.

Scan Results Structure

The .scan(...) methods return an object detailing matches and diagnostics:

{
  "valid": true,
  "matches": [
    {
      "identifier": "rule_name",
      "namespace": "default",
      "isPrivate": false,
      "isGlobal": false,
      "tags": ["tag_a"],
      "metadata": [
        { "identifier": "key", "value": "value" }
      ],
      "patterns": [
        {
          "identifier": "$a",
          "kind": "text",
          "isPrivate": false,
          "matches": [
            { "offset": 2, "length": 3 }
          ]
        }
      ]
    }
  ],
  "warnings": []
}

Resource Management

Objects generated in WebAssembly live in the Wasm heap, which is separate from the JavaScript garbage-collected heap. If you do not manually free these objects, they will leak memory in the WebAssembly space.

Ensure you call .free() on objects when no longer needed:

const compiler = new Compiler();
try {
  compiler.addSource('rule x { condition: true }');
  const rules = compiler.build();
  const payload = new Uint8Array([0x00]); // Self-contained payload
  rules.scan(payload);
  rules.free();
} finally {
  compiler.free();
}

Modern JavaScript (Explicit Resource Management)

If your environment supports the new JavaScript using keyword (Explicit Resource Management), you can let the runtime handle it automatically because the types implement [Symbol.dispose]:

{
  using compiler = new Compiler();
  compiler.addSource('rule x { condition: true }');
} // compiler.free() is called automatically here!