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

war2-pud

v2.1.0

Published

Library to manipulate Warcraft II's pud files

Readme

war2-pud

A cross-platform TypeScript library for parsing, manipulating, and generating Warcraft II map (PUD) files. Works seamlessly in both Node.js and browser environments.

Features

  • Full Read/Write Support: Parse existing .pud files or create new ones from scratch.
  • Cross-Platform: Usable in Node.js, browsers, and other JS runtimes (uses standard DataView/Uint8Array).
  • Complete Map Data Access: Read and modify dimensions, descriptions, terrain (tilesets).
  • Map Layers: Full access to standard tiles (MTXM), movement mapping (SQM), oil deposits (OILM), and action grids (REGM).
  • Unit Management: Easy APIs to read, add, and remove units on map.
  • Player Configurations: Set player races, starting resources (Gold, Lumber, Oil), AI profiles, restricted unit building, spell access, and upgrades.
  • Type-safe: Built entirely in TypeScript, with enums for Units, Spells, Upgrades, Terrain Types, and more.
  • Result Types: Uses neverthrow for safe byte-parsing error handling.

Installation

Using npm or pnpm:

npm install war2-pud
pnpm install war2-pud

Basic Usage

Parsing an existing PUD file

import { promises as fs } from "fs";
import { Pud } from "war2-pud";

async function loadMap() {
    const buffer = await fs.readFile("path/to/my_map.pud");

    // Parse the map data
    const result = Pud.fromPudBytes(buffer);

    if (result.isErr()) {
        console.error("Failed to parse map:", result.error);
        return;
    }

    const pud = result.value;

    console.log(`Map Description: ${pud.description}`);
    console.log(`Dimensions: ${pud.width}x${pud.height}`);
    console.log(`Total Units: ${pud.units.length}`);
}

loadMap();

Modifying and Saving a Map

import { promises as fs } from "fs";
import { Pud, TERRAIN_TYPES, UNIT_TYPES, PLAYER_SIDES } from "war2-pud";

async function editMap() {
    // Read and parse
    const buffer = await fs.readFile("example.pud");
    const pud = Pud.fromPudBytes(buffer)._unsafeUnwrap();

    // Change map description
    pud.description = "My Custom Edited Map!";

    // Change terrain to WINTER
    pud.terrain = TERRAIN_TYPES.WINTER;

    // Configure Player 1 (Red)
    const red = pud.players.red;
    red.race = PLAYER_SIDES.ORC;
    red.startingGold = 5000;
    red.startingLumber = 2500;

    // Disallow building Dragons for red
    red.setUnitAllowed(UNIT_TYPES.DRAGON, false);

    // Add a new unit for Red
    pud.addUnit(
        10, // x coordinate
        10, // y coordinate
        UNIT_TYPES.GRUNT,
        red.id,
        0, // extra data / properties
    );

    // Serialize back to binary format
    const outBytes = pud.toBinary();
    await fs.writeFile("edited.pud", outBytes);
}

editMap();

Creating a Map from Scratch

import { Pud, TERRAIN_TYPES } from "war2-pud";

// Create a 64x64 FOREST map
const newMap = new Pud(64, 64, TERRAIN_TYPES.FOREST);

newMap.description = "New map.";

const rawPudData = newMap.toBinary();
// Get raw bytes of a pud file

Advanced Usage

Working with Map Tiles (MTXM/SQM)

const { map } = pud;

// Raw access to the tiles array (Uint16Array)
const mapTiles = map.tiles;

// Change the tile at (x: 5, y: 10)
const index = 10 * pud.width + 5;
mapTiles[index] = 0x0015; // Specific tile ID

Contributing

# Install dependencies
pnpm install

# Run the test suite
pnpm test

# Build the project
pnpm build

License

MIT