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

rst3s-td

v0.0.4

Published

Rust Iterators and Options in Typescript

Downloads

2

Readme

RST3S-TD

npm build status

I'm fed up with Javascript! I want to make websites, but the builtin functions are painful to use! Let's introduce some methods from a well designed language!

ARR ESS TEE THREE ESS DASH TEE DEE, also known as known as the RuSt TypeScript Stripped STandarD project is a library to reimplement functionality from Rust's std::option, std::result, and std::iter into Typescript. To be clear, this is NOT a port from Rust. There will be semantic differences (see below).

You're welcome.

Check SUPPORT.md for supported methods.

Example

import { Iterator, Result, Option } from "rst3s-td";

let a = Option.fromSome("Hello")              //  let a = Some("Hello".to_owned())
    .map((s) => s + " World")                 //      .map(|s| s + "World")
    .unwrap();                                //      .unwrap()

let b = Result.fromOk({ a: 10,  b: 20 })      //  let b = Ok(Data { a: 10, b: 20 })
    .map((obj) => obj.a)                      //      .map(|obj| obj.a)
    .iter()                                   //      .into_iter()
    .chain(Iterator.fromArray([4, 5, 6]));    //      .chain([4, 5, 6]);

for (let it of b) {
    console.log(it);
}

let c = Iterator.fromArray([1, 2, 3, 4, 5])   //  let c = ([1, 2, 3, 4, 5]).into_iter()
    .filter((x) => x % 2 != 0)                //      .filter(|x| x % 2 != 0)
    .map((x) => x * 2)                        //      .map(|x| x * 2)
    .zip(b)                                   //      .zip(b)
    .inspect(([a, b]) => console.log(a, b))   //      .inspect(|(a, b)| eprintln!("{} {}", a, b))
    .collect();                               //      .collect::<Vec<_>>(); 

Notable Semantic Differences

Iterators

Iterators are generally do not write to themselves. For example:

Rust:

let a = [1, 2, 3];
let it = a.iter()
assert_eq!(Some(&1), iter.next());
assert_eq!(Some(&2), iter.next());
assert_eq!(Some(&3), iter.next());

This Library:

let it = Iterator.fromArray([1, 2, 3]);
let it1 = it.next();    // it1 = 1 
let it2 = it1.next();   // it2 = 2
let it3 = it2.next();   // it3 = 3
let it4 = it.next();    // it4 = 1

References

Rust and Javascript handle references and mutability quite differently. Please be mindful that just because a closure is a mutable reference in the original, does not mean that this library will accurately capture that behavior.

Documentation

All methods use camel case, but otherwise, you can just use the Rust std docs here.

However, a few outlier methods are documented below.

Option.then<T>(b: boolean, f: () => T): Option<T>
Option.thenSome<T>(b: boolean, v: T): Option<T>
Option.fromSome<T>(data: T): Option<T>
Option.fromNone<T>(): Option<T>

Result.fromOk<T, E>(data: T): Result<T, E>
Result.fromErr<T, E>(error: E): Result<T, E>

Iterator.fromArray<I>(array: Array<I>): Iterator<I>