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

@travisennis/stdlib

v0.0.14

Published

A standard library built for me.

Readme

@travisennis/stdlib

A modern TypeScript standard library providing robust functional programming primitives and error handling patterns. Built with type safety and composability in mind.

Features

  • Option - Safe handling of nullable values
  • Result<T, E> - Type-safe error handling
  • Try - Exception handling wrapper
  • Either<L, R> - Disjoint union type representation
  • Random - Seeded random number generation
  • Env Paths - Platform-specific environment paths
  • DESM - ESM directory and file path utilities
  • Utility Functions - Helper functions for working with collections of monadic types
  • Type Guards - Built-in type guards for all data types
  • Full TypeScript Support - Written in TypeScript with complete type definitions
  • Zero Dependencies - Pure TypeScript implementation with no runtime dependencies

Installation

npm install @travisennis/stdlib

Usage

Option

Handle nullable values safely:

import { Option } from '@travisennis/stdlib/option';

// Create Options
const some = Option.some(5);
const none = Option.none<number>();

// Handle nullable values
const value = Option.from(possiblyNullValue);

// Transform values
const doubled = some
  .map(x => x * 2)
  .unwrapOr(0); // Provides default if none

// Pattern matching
const result = some.match({
  some: value => `Got ${value}`,
  none: () => "Got nothing"
});

Result<T, E>

Handle errors in a functional way:

import { Result } from '@travisennis/stdlib/result';

function divide(a: number, b: number): Result<number, string> {
  return b === 0
    ? Result.err("Division by zero")
    : Result.ok(a / b);
}

const result = divide(10, 2)
  .map(x => x * 2)
  .mapErr(err => `Error: ${err}`);

// Pattern matching
const message = result.match({
  ok: value => `Result: ${value}`,
  err: error => error
});

Try

Wrap exception-throwing code:

import { syncTry, asyncTry } from '@travisennis/stdlib/try';

// Synchronous operations
const result = syncTry(() => {
  // potentially throwing code
  return JSON.parse(someJson);
});

// Async operations
const asyncResult = await asyncTry(
  fetch('https://api.example.com/data')
);

Either<L, R>

Handle binary outcomes:

import { Either, isLeft, isRight } from '@travisennis/stdlib/either';

// Creating Eithers
const right = Either.right<string, number>(5);
const left = Either.left<string, number>("left value");

// Transformations
const doubled = right
  .map(x => x * 2)            // Transform right value
  .mapLeft(x => x.length);    // Transform left value

// Pattern matching
const result = right.match({
  right: value => `Right: ${value}`,
  left: value => `Left: ${value}`
});

// Type guards
if (isRight(right)) {
  // TypeScript knows this is a Right value
  console.log(right.value);
}

Random

Generate random numbers with optional seeding:

import { random } from '@travisennis/stdlib/random';

// Use with default seed (Math.random)
const rng = random();
const randomInt = rng.int(1, 10);    // Random integer between 1 and 10
const randomFloat = rng.float(0, 1);  // Random float between 0 and 1

// Use with custom seed for reproducible sequences
const seededRng = random(12345);
const seededInt = seededRng.int(1, 10);

Env Paths

Get platform-specific paths for your application:

import envPaths from '@travisennis/stdlib/env';

const paths = envPaths('myapp');

// Access various platform-specific paths
console.log(paths.data);    // Data directory
console.log(paths.config);  // Config directory
console.log(paths.cache);   // Cache directory
console.log(paths.logs);    // Logs directory
console.log(paths.temp);    // Temp directory
console.log(paths.state);   // State directory

DESM

ESM-friendly path utilities for working with file and directory paths:

import { dirname, filename, join } from '@travisennis/stdlib/desm';

// Get directory name from import.meta.url
const dir = dirname(import.meta.url);

// Get file name from URL
const file = filename(import.meta.url);

// Join paths relative to current module
const path = join(import.meta.url, '../assets', 'config.json');

Utility Functions

Work with collections of monadic types:

import { utilities } from '@travisennis/stdlib/utilities';

// Convert array of Options to Option of array
const results = utilities.sequence.option([
  Option.some(1),
  Option.some(2),
  Option.some(3)
]); // Option<number[]>

// Map and sequence in one operation
const mapped = utilities.traverse.result([1, 2, 3], 
  x => Result.ok(x * 2)
); // Result<number[], E>

Configuration

No configuration is required. The library works out of the box with TypeScript projects.

License

MIT License - see the LICENSE file for details.

Acknowledgements

This library implements functional programming patterns inspired by Rust's standard library and functional programming concepts from languages like Haskell and Scala. The implementation focuses on providing these patterns in a TypeScript-friendly way while maintaining type safety and ease of use.

The code in @travisennis/stdlib/desm was inspired by https://github.com/mcollina/desm