Skip to main content

Ahh

A collection of mostly rusty stuff to help make TypeScript a little easier to work with — if you don’t mind a little verbosity.

Example

This is an example on how you might use result.ts:

import { Err, Ok, Result } from "./result.ts";

function mustStartWith(s: string, start: string): Result<string, string> {
  if (s.startsWith(start)) {
    return Ok(s);
  } else {
    return Err(`string must start with "${start}"`);
  }
}

console.log(mustStartWith("abc", "a").contains("abc"));
console.log(
  mustStartWith("bca", "a").containsErr(`string must start with "a"`),
);

Licence

This is licenced under the ISC Licence, see the LICENCE file for more information.