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 🙏

© 2024 – Pkg Stats / Ryan Hefner

regedit-rs

v1.0.2

Published

A high-performance Windows registry toolkit, powered by Rust with napi-rs

Downloads

228

Readme

regedit-rs

Rust 1.70+

A high-performance Windows registry toolkit inspired by node-regedit, powered by Rust with napi-rs It enables easy manipulation of the Windows registry with optimized performance.

Install

npm install regedit-rs

Example

import { list, createKey, putValue, deleteKey, deleteValue, RegSzValue, RegDwordValue, RegExpandSzValue } from "regedit-rs";

async function main(){
    const keys = ["HKCU\\Software\\regedit-rs", "HKCU\\Software\\regedit-rs\\test"];
    const result = await list(keys);

    if(!result[keys[0]].exists){
        return;
    }

    const nameValue = result[keys[1]].values["name"].value;
    const newPath = new RegExpandSzValue(`%APPDATA%\\${nameValue}`);

    if(newPath.expandedValue !== "C:\\Users\\username\\AppData\\Roaming\\test name"){
        return;
    }

    await createKey("HKCU\\Software\\regedit-rs\\test");
    await putValue({
        "HKCU\\Software\\regedit-rs\\test": {
            "name": new RegSzValue("test name"),
            "number": new RegDwordValue(123),
            "path": newPath
        }
    });

    await deleteKey("HKCU\\Software\\regedit-rs\\old_test");

    await deleteValue({
        "HKCU\\Software\\regedit-rs\\test": ["name", "number", "path"]
    });
}

main();

API

Every function are binded to Rust and support batching to improve performance.

Reading keys and values

List registry key(s) and value(s)

const res = await list(["HKCU\\SOFTWARE", "HKLM\\SOFTWARE", "HKCU\\DONT_EXIST"]);

Result will be an object with the following structure:

{
    "HKCU\\SOFTWARE": {
        "exists": true,
        keys: ["HKCU\\SOFTWARE\\Microsoft", "HKCU\\SOFTWARE\\regedit-rs", ...],
        values: {
            szValue: [RegSzValue] // RegSzValue is a class with a value property
            dwordValue: [RegDwordValue] // RegDwordValue is a class with a value property
            expandSzValue: [RegExpandSzValue] // RegExpandSzValue is a class with a value and expandedValue property
        }
    },
    "HKLM\\SOFTWARE": {
        "exists": true,
        keys: ["HKLM\\SOFTWARE\\Microsoft", "HKLM\\SOFTWARE\\regedit-rs", ...],
        values: {
            szValue: [RegSzValue]
            dwordValue: [RegDwordValue]
            qwordValue: [RegQwordValue]
            expandSzValue: [RegExpandSzValue]
        }
    },
    "HKCU\\DONT_EXIST": {
        "exists": false,
        keys: [],
        values: {}
    }
}

Creating keys

Create registry key(s) if not exists

await createKey("HKCU\\SOFTWARE\\regedit-rs\\test");
await createKey(["HKCU\\SOFTWARE\\regedit-rs\\test", "HKCU\\SOFTWARE\\regedit-rs\\test2"]);

Putting values

Put or update registry value(s)

await putValue({
    "HKCU\\SOFTWARE\\regedit-rs\\test": {
        "name": new RegSzValue("test name"),
        "number": new RegDwordValue(123),
        "path": new RegExpandSzValue("%APPDATA%\\test name")
    }
});

Deleting keys

Delete registry key(s) and all subkeys

await deleteKey("HKCU\\SOFTWARE\\regedit-rs\\test");
await deleteKey(["HKCU\\SOFTWARE\\regedit-rs\\test", "HKCU\\SOFTWARE\\regedit-rs\\test2"]);

Deleting values

Delete registry value(s)

await deleteValue({
    "HKCU\\SOFTWARE\\regedit-rs\\test": ["name", "number", "path"]
});

More

See all types, functions, and classes at index.d.ts

Sample Benchmark

npm run bench
Running "List keys and values of a registry key" suite...
Progress: 100%

  regedit-rs:
    3 162 ops/s, ±1.01%   | fastest

  regedit:
    18 ops/s, ±0.37%      | slowest, 99.43% slower

  winreg:
    33 ops/s, ±0.60%      | 98.96% slower

Finished 3 cases!
  Fastest: regedit-rs
  Slowest: regedit
Running "Create a registry key" suite...
Progress: 100%

  regedit-rs:
    116 548 ops/s, ±0.74%   | fastest

  regedit:
    22 ops/s, ±0.64%        | slowest, 99.98% slower

  winreg:
    43 ops/s, ±1.00%        | 99.96% slower

Finished 3 cases!
  Fastest: regedit-rs
  Slowest: regedit
Running "Put a registry value" suite...
Progress: 100%

  regedit-rs:
    59 015 ops/s, ±0.77%   | fastest

  regedit:
    22 ops/s, ±0.92%       | slowest, 99.96% slower

  winreg:
    43 ops/s, ±0.85%       | 99.93% slower

Finished 3 cases!
  Fastest: regedit-rs
  Slowest: regedit

Test or Contributing

  • Clone this repo
  • Install latest stable Rust
  • Install Node.js 10+
  • Install dependencies with npm install
  • Build bindings with npm run build
  • Run npm test

Release package

We use GitHub actions to automatically publish npm packages.

# 1.0.0 => 1.0.1
npm version patch

# or 1.0.0 => 1.1.0
npm version minor