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

@mfdlabs/environment

v1.0.3

Published

A Node.js library for managing environment variables

Downloads

6

Readme

@mfdlabs/environment

This library provides a class that can be inherited to provide a consistent environment variable interface.

Example


// The environment class can be imported like this:
import environment from '@mfdlabs/environment';
// Or this:
import { environment } from '@mfdlabs/environment';

// We advise you create an inherited class to provide a consistent interface
// for your application. With a static instance, so you don't have to create
// a new instance every time you want to access the environment variables.

class MyEnvironment extends environment {
  // The static instance is used to access the environment variables
  public static singleton = new MyEnvironment();

  // You can define a default value for an environment variable
  // that will be used if the environment variable is not set.
  public get exampleEnvVar(): string {
    return super.getOrDefault<string>('EXAMPLE_ENV_VAR', 'default value');
  }

  // You can also define a default value that is a function.
  // This is useful if you want to use the value of another environment variable
  // to set the default value.
  public get exampleEnvVar2(): string {
    return super.getOrDefault<string>('EXAMPLE_ENV_VAR_2', () => this.exampleEnvVar);
  }
}

// You can then access the environment variables like this:
const exampleEnvVar = MyEnvironment.singleton.exampleEnvVar;

// In the future there is an idea to add decorators to make this even easier.
// And there is also an idea to allow runtime overrides of environment variables
// for testing purposes.

Exports

The package exports the following:


/* A type that represents the default value getter function */
export type DefaultValueGetter<T> = () => T;

/* A class that can be inherited to provide a consistent environment variable interface */
class environment { /* ... */ };

Methods

The following methods are available on the environment class:

| Method Name | Return Type | Is Protected? | Is Static? | Description | |-----------------|-------------|---------------|------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | getOrDefault | T | Yes | No | A method for getting an environment variable, casting it or returning the default value specified in the second argument of this. If your default value is null or empty, please specify the last argument in order to correctly parse it or else it will be inferred as a string. | | hasDockerEnv | boolean | No | Yes | A method that checks if the file /.dockerenv exists. This is not a for sure way to check for docker though. | | hasDockerCGroup | boolean | No | Yes | A method that checks if the current system includes 'docker' within /proc/self/cgroup. This is not a for sure way to check for docker though. | | isDocker | boolean | No | Yes | A method that checks if the current system is running under docker. |