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 🙏

© 2026 – Pkg Stats / Ryan Hefner

functype-os

v0.3.0

Published

Functional OS utilities using functype data structures — env vars, path expansion, file ops, platform detection

Downloads

427

Readme

functype-os

Functional OS utilities for Node.js using functype data structures. Wraps environment variables, path expansion, filesystem operations, platform detection, and config file resolution with Option, Either, Task, and List.

Install

pnpm add functype-os functype

Modules

Env

Wraps process.env with Option and Either.

import { Env } from "functype-os"

Env("HOME") // Option<string>
Env.get("HOME") // Option<string>
Env.getRequired("DATABASE_URL") // Either<EnvError, string>
Env.getOrDefault("PORT", "3000") // string
Env.has("CI") // boolean
Env.entries() // List<readonly [string, string]>

Path

Pure path expansion — tilde, environment variables, and resolution.

import { expandTilde, expandVars, expandPath, Path } from "functype-os"

expandTilde("~/Documents") // "/home/user/Documents"
expandVars("$HOME/.config") // Either<PathError, string>
expandPath("~/$APP_DIR/config.toml") // Either<PathError, string> (absolute)

Path.join("a", "b") // "a/b"
Path.resolve("relative") // "/cwd/relative"
Path.dirname("/a/b/c.txt") // "/a/b"
Path.basename("/a/b/c.txt") // "c.txt"
Path.extname("file.ts") // ".ts"
Path.isAbsolute("/abs") // true

Fs

Async filesystem operations returning TaskResult.

import { Fs } from "functype-os"

await Fs.exists("/path/to/file") // TaskResult<boolean>
await Fs.readFile("/path/to/file") // TaskResult<string>
await Fs.readFileOpt("/path/to/file") // TaskResult<Option<string>> (None on ENOENT)
await Fs.readdir("/path/to/dir") // TaskResult<List<string>>

Platform

OS and container/runtime detection with lazy-cached sync checks.

import { Platform } from "functype-os"

Platform.os() // "darwin" | "linux" | "win32" | string
Platform.arch() // "arm64" | "x64" | ...
Platform.homeDir() // "/home/user"
Platform.isWindows() // boolean
Platform.isMac() // boolean
Platform.isLinux() // boolean
Platform.userInfo() // Option<UserInfo>

// Container/runtime detection (lazy-cached)
Platform.isDocker() // boolean
Platform.isKubernetes() // boolean
Platform.isWSL() // boolean
Platform.isCI() // boolean
Platform.isContainer() // isDocker() || isKubernetes()

ConfigResolver

Find the first existing config file from a list of candidates with path expansion.

import { ConfigResolver } from "functype-os"

const config = await ConfigResolver.resolve({
  candidates: ["./app.toml", "~/.config/app/config.toml", "$APPDATA/app/config.toml"],
})
// TaskResult<Option<string>> — Ok(Some("/home/user/.config/app/config.toml"))

const required = await ConfigResolver.resolveRequired({
  candidates: ["./app.toml", "~/.config/app/config.toml"],
})
// TaskResult<string> — Err(ConfigError) if none found

const all = await ConfigResolver.resolveAll({
  candidates: ["./a.toml", "./b.toml", "./c.toml"],
})
// TaskResult<List<string>> — all existing paths

Errors

Discriminated union error types for exhaustive matching.

import type { OsError } from "functype-os"
import { EnvError, PathError, FsError, ConfigError } from "functype-os"

const handleError = (error: OsError) => {
  switch (error._tag) {
    case "EnvError":
      return `Missing env var: ${error.variable}`
    case "PathError":
      return `Path issue: ${error.path} (${error.reason})`
    case "FsError":
      return `FS error: ${error.operation} on ${error.path}`
    case "ConfigError":
      return `No config found in: ${error.candidates.join(", ")}`
  }
}

Requirements

  • Node.js >= 18
  • functype >= 0.49.0 (peer dependency)

Development

pnpm install
pnpm dev              # build with watch
pnpm test             # run tests
pnpm validate         # format + lint + typecheck + test + build

License

MIT