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 🙏

© 2024 – Pkg Stats / Ryan Hefner

strongly-env

v0.1.4

Published

A utility to elegantly read environment variables as JavaScript/TypeScript types. Simple, lightweight and performant wih no external dependencies. Also provides option to revert to default value in case env variable is undefined.

Downloads

2

Readme

strongly-env

A utility to elegantly read environment variables as JavaScript/TypeScript types. Simple, lightweight and performant wih no external dependencies. Also provides option to revert to default value in case env variable is undefined.

Installation

Install the package using npm or yarn:

npm install strongly-env
# or
yarn add strongly-env

Usage

In your code, you can import the utility functions from the package and use them to read environment variables. Please note that this package is designed for server-side environments and relies on process.env. It might not work as expected in browser-based environments.

Import and Usage

import { config } from "strongly-env";

// Load an integer environment variable with a default value
const maxThreshold = config.loadInteger("MAX_THRESHOLD", 5);

// Load a decimal environment variable with a default value
const taxRate = config.loadDecimal("TAX_RATE", 0.08);

// Load a boolean environment variable with a default value
const debugMode = config.loadBoolean("DEBUG_MODE", false);

// Load a string environment variable with a default value
const dbName = config.loadString("DATABASE_NAME", "mydb");

// Load an array of strings from an environment variable
const allowedOrigins = config.loadArray("ALLOWED_ORIGINS", []);

// Load a JSON object from an environment variable
const appConfig = config.loadObject("APP_CONFIG", {
  name: "MyApp",
  version: "1.0.0",
});

// Handle cases where env variable is undefined
const undefinedValue = config.loadInteger(undefined, 100);

Utility Functions

loadInteger(envVariable: string | undefined, defaultValue?: number): number
Load an integer environment variable with an optional default value.

loadDecimal(envVariable: string | undefined, defaultValue?: number): number
Load a decimal environment variable with an optional default value.

loadBoolean(envVariable: string | undefined, defaultValue?: boolean): boolean
Load a boolean environment variable with an optional default value.

loadString(envVariable: string | undefined, defaultValue?: string): string
Load a string environment variable with an optional default value.

loadArray(envVariable: string | undefined, defaultValue?: string[]): string[]
Load an array of strings from an environment variable with an optional default value.

loadObject(envVariable: string | undefined, defaultValue: any): any
Load a JSON object from an environment variable with an optional default value.

Warning

This package is intended for server-side environments that support process.env, such as Node.js applications. It may not work as expected in browser-based environments due to its reliance on server-specific features. Please ensure that you only use this package in environments where process.env is available.

If you plan to use this package in a browser-based environment, you might need to consider alternative approaches or modifications to make it compatible.