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

snapenv

v0.2.0

Published

typesafe env validation with zero dependencies

Readme

┌──────────────────────────────────────────────────────────────┐
│                                                              │
│   ◇  snapenv                                                 │
│                                                              │
│   typesafe env validation with zero dependencies             │
│                                                              │
└──────────────────────────────────────────────────────────────┘
> what is this?

  a tiny library that validates and types your environment variables
  no zod, no dependencies, just one function

> example?

  const env = snap({
    DATABASE_URL: "url!",
    PORT: "port=3000",
    DEBUG: "boolean=false",
    NODE_ENV: ["development", "production", "test"],
    ALLOWED_IPS: "string[]",
  })

  env.PORT        // number (3000 if not set)
  env.DEBUG       // boolean (false if not set)
  env.NODE_ENV    // "development" | "production" | "test"
  env.ALLOWED_IPS // string[]

> features?

  ✓ zero dependencies
  ✓ full typescript inference
  ✓ runtime parsing (actual numbers, booleans, arrays)
  ✓ default values
  ✓ prefix support (NEXT_PUBLIC_, VITE_)
  ✓ secret masking in errors
  ✓ custom validators
  ✓ extend/pick/omit utilities
  ✓ works everywhere (node, deno, bun, edge)

> types?

  string      any string              string | undefined
  string!     required string         string
  number      parsed number           number | undefined
  integer     whole number only       number | undefined
  port        valid port 1-65535      number | undefined
  boolean     true/false, 1/0, yes/no boolean | undefined
  url         valid url               string | undefined
  email       valid email             string | undefined
  host        hostname or ip          string | undefined
  uuid        valid uuid              string | undefined
  json        parsed json             unknown
  string[]    comma-separated         string[] | undefined
  number[]    comma-separated numbers number[] | undefined
  [...]       enum of values          union type

  add ! to make required: number!, url!, email!
  add =value for defaults: port=3000, boolean=false

> custom validators?

  import { snap, makeValidator, regex } from "snapenv"

  // regex shorthand
  const env = snap({
    CODE: regex(/^[A-Z]{3}-\d{3}$/, { required: true }),
  })

  // fully custom
  const hex = makeValidator<string>((value) => {
    if (!/^#[0-9a-f]{6}$/i.test(value)) {
      throw new Error("must be a hex color")
    }
    return value
  }, { required: true })

  const env = snap({ COLOR: hex })

> extend/pick/omit?

  // monorepo: combine server + client env
  const server = snap({ DATABASE_URL: "url!" })
  const client = snap({ API_URL: "url!" }, { prefix: "NEXT_PUBLIC_" })
  const env = extend(server, client)

  // pick subset
  const public = pick(env, ["API_URL"])

  // omit sensitive
  const safe = omit(env, ["DATABASE_URL"])

> options?

  snap(schema, {
    source: process.env,       // custom env source
    prefix: "NEXT_PUBLIC_",    // env var prefix
    emptyAsUndefined: true,    // treat "" as undefined
    maskSecrets: true,         // hide secrets in errors
    onError: "throw",          // "throw" | "log" | (errors) => void
  })

> validate without throwing?

  const result = validate(schema, options)

  if (result.success) {
    console.log(result.data.PORT)
  } else {
    console.log(result.errors)
  }

> createSnap?

  const snap = createSnap({ prefix: "MY_APP_" })
  const env = snap({ ... })

> .env files?

  snapenv validates, it doesn't load
  use your runtime's native .env support:

  bun app.ts                        # bun auto-loads .env
  node --env-file=.env app.js       # node 20.6+
  deno run --env-file=.env app.ts   # deno
  node -r dotenv/config app.js      # older node

> install?

  bun add snapenv
  npm install snapenv

> license?

  mit