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

@leptonite/environment-parser

v1.1.0

Published

get and validate values from environment variables

Downloads

4,337

Readme

@leptonite/environment-parser

@leptonite/environment-parser helps getting and validating values from environment variables.

// create an EnvironmentParser for the environment of this process
const envParser = new EnvironmentParser();

// create an EnvironmentParser for a custom environment
const customEnvParser = new EnvironmentParser({
   SOME: 'value',
   FOO: 'bar',
});


// get mandatory string value
// throws Error if VAR is not set
const mandatoryString = envParser.getString('VAR');

// get and validate mandatory string value
// throws Error if VAR is not set or does not match the given pattern
const validatedMandatoryString = envParser.getString('VAR', /^[a-zA-Z0-9]{10,20}$/u);

// get optional string value
// returns undefined if VAR is not set
const optionalString = envParser.getOptionalString('VAR');

// get and validate optional string value
// returns undefined if VAR is not set
// throws Error if VAR does not match the given pattern
const validatedOptionalString = envParser.getOptionalString('VAR', /^[a-zA-Z0-9]{10,20}$/u);


// get mandatory integer value
// throws Error if VAR is not set
const mandatoryInteger = envParser.getInteger('VAR');

// get and validate mandatory integer value
// throws Error if VAR is not set or does not meet the given requirements
const validatedMandatoryInteger = envParser.getInteger('VAR', { min: 1, max: 999 });

// get optional integer value
// returns undefined if VAR is not set
const optionalInteger = envParser.getOptionalInteger('VAR');

// get and validate optional integer value
// returns undefined if VAR is not set
// throws Error if VAR does not match the given pattern
const validatedOptionalInteger = envParser.getOptionalInteger('VAR', { min: 1, max: 999 });


// get mandatory string value and validate it against the given options
// throws Error if VAR is not set or does not match one of the given options
const mandatoryOption = envParser.getOneOf('VAR', ['option1', 'option2']);

// get optional string value and validate it against the given options
// returns undefined if VAR is not set
// throws Error if VAR does not match one of the given options
const optionalOption = envParser.getOptionalOneOf('VAR', ['option1', 'option2']);

The getOptionalString(), getOptionalInteger() and getOptionalOneOf() methods don’t support default values. Use envParser.getOptionalString('VAR') ?? 'default' instead.