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 🙏

© 2025 – Pkg Stats / Ryan Hefner

rusting-js

v0.1.15

Published

This is a TS library that adds some of the Rust features to TS/JS.

Downloads

860

Readme

rusting-js

This is a TS library that adds some of the Rust features to TS/JS.

So far, it has:

Enums

With the Enum function you can create Rust-like enums, meaning: enums that can store values, other that number and string.

import { Enum, Arm } from "rusting-js/enums";

const StrNum = Enum({
  String: Arm<string>(),
  Number: Arm<number>(),
  Error: Arm<Error>(),
});

const strNum = StrNum.String("Hello");

strNum.match({
  String(value) {
    console.log(`${value} World!`);
  }
  Number(value) {
    console.log("This will never be reached");
  }
  Error(error) {
    console.log("This also will never be reached");
  }
});

For more complex enums (those with template types) you can use the EnumClass. This class is used internally to create the enums: Result, Option and ControlFlow

import { EnumClass } from "rusting-js/enums";

class Option<T> extends EnumClass<{ Some: T; None: void }> {
  // This is an abstract method inside the `EnumClass`
  // it is used internally to check the posible types/arms
  // of the enum
  isValidType(type: "None" | "Some"): boolean {
    switch (type) {
      case "None":
      case "Some":
        return true;
    }

    return false;
  }

  static Some<T>(value: T): Option<T> {
    return new Option("Some", value);
  }

  static None<T>(): Option<T> {
    return new Option("None");
  }
}

Option.Some("This is a message");
Option.None();

Error managing

The catchUnwind and catchUnwindAsync functions are for replacing try/catch, both receive a function as its parameter, the function may throw an exception, if it does, the error value will be wrapped in a Err type of the enum Result, if the function runs successfully, the return value will be wrappd in a Ok type.

import { catchUnwind } from "rusting-js";

const result1 = catchUnwind(() => "This will be returned");
console.log(result1.isOk()); // -> true
console.log(result1.unwrap()); // -> This will be returned

const result2 = catchUnwind(() => {
  throw new Error("This will be throw");
});
console.log(result2.isErr()); // -> true
console.log(result2.unwrapErr()); // -> Error("This will be throw")

Others

  • A Mutex class that lets you create locks on variables to better control order of execution.

Some others still not finished features are:

  • RString is a class that imitates the String structure in Rust. So far, it can give you the UTF-8 bytes of a string, and you can instantiated it with an array of numbers if the array is a valid UTF-8.

  • RIterator a class that works like a trait to allow you create Rust-like Iterators. The project currently come with the next types of iterators: Chain, Intersperse, Iter, Map, StepBy and Zip. A lot of functions in RIterator depend on different Iterators so those functions, for now, are currently not available for those reasons.

  • Vec a work in progress class that will allow you to create slices with Rust-like ranges

const v = new Vec<number>();
v["0..3"]

I hope it is useful.