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

@kasifraza/env-validator

v1.0.3

Published

Type-safe environment variable validation with defaults, coercion, and early failure. Zero dependencies.

Downloads

5,041

Readme

@kasifraza/env-validator

npm package license downloads Tests

Type-safe environment variable validation with defaults, coercion, and early failure. Zero dependencies.

Install

npm install @kasifraza/env-validator

Usage

import { validateEnv } from '@kasifraza/env-validator';

const config = validateEnv({
  PORT: { type: 'number', default: 3000 },
  DATABASE_URL: { type: 'string' },
  REDIS_URL: { type: 'string' },
  ENABLE_CACHE: { type: 'boolean', default: true },
  NODE_ENV: { type: 'string', choices: ['development', 'production', 'test'] },
  ALLOWED_ORIGINS: { type: 'array', default: ['http://localhost:3000'] },
  AWS_CONFIG: { type: 'json', required: false },
});

// config is fully typed:
// config.PORT → number
// config.DATABASE_URL → string
// config.ENABLE_CACHE → boolean
// config.ALLOWED_ORIGINS → string[]

Features

  • Type coercionstring, number, boolean, json, array
  • Defaults — Fallback values when env var is not set
  • Required/Optional — Required by default, opt-out with required: false
  • Choices — Restrict to allowed values
  • Custom transform — Apply any transformation function
  • Collect all errors — Reports every invalid var at once, not one at a time
  • Zero dependencies — No bloat
  • Full TypeScript — Inferred return types from schema

API

validateEnv(schema, env?)

| Param | Type | Description | |-------|------|-------------| | schema | EnvSchema | Validation rules per variable | | env | Record<string, string> | Defaults to process.env |

Rule options

| Option | Type | Default | Description | |--------|------|---------|-------------| | type | 'string' \| 'number' \| 'boolean' \| 'json' \| 'array' | 'string' | Coercion type | | required | boolean | true | Throw if missing | | default | any | — | Fallback value | | choices | any[] | — | Allowed values | | transform | (value: string) => any | — | Custom transform (overrides type coercion) |

Custom transform example

const config = validateEnv({
  API_URL: {
    transform: (v) => v.replace(/\/$/, ''), // strip trailing slash
  },
});

Error handling

Throws EnvValidationError with all failures collected:

EnvValidationError: Environment validation failed:
  - DATABASE_URL is required but not set
  - PORT: Cannot convert "abc" to number
  - NODE_ENV must be one of [development, production, test], got "staging"

License

MIT