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

eznv

v1.3.0

Published

Env Management without the fuss

Downloads

4

Readme

NPM Build Status Coverage Status

EZNVEasy Env Management

Getting started

Install the package

npm i --save eznv

Define a Schema

EZNV uses a schema object to validate an env file and to determine the type of the resulting object.

  import EZ from 'eznv'

  const schema = EZ.Schema({
    NUM: EZ.Number({
      default: 0,
      minimum: 0,
      maximum: 10
    })
  })

Load the ENV

  const config = await schema.load()

  // or to load synchronously

  const config = schema.loadSync()

Load Options

The following are options passable to schema.load and schema.loadSync.

|option|type|default|description| |------|----|-------|-----------| |cwd|string|process.cwd()|Path to the default directory to search for your schema file and env file| |file|string|.env|Path, relative to cwd or absolute, to the env file| |mode|file_first | no_file | file_only|file_first|configure whether use the file only, process.env only, or both |matchCase|boolean|false|use exact case matching for variable names. Ignores case by default. |

Schema Properties

The EZ.Schema function takes as an argument a dictionary of property definitions. There are four different property definitions you can create. EZ.Number, EZ.String, EZ.Integer, and EZ.Boolean. Each type allows for different options to control validation.

Common Validator Properties

|Option|Description| |---|---| |default|A default value to use when the property is missing| |required|Should the property be required. Defaults to true|

Number Validator Properties

EZ.Number will define a number property.

|Option|Description| |---|---| |minimum|The value must be greater than or equal to this number.| |exclusiveMinimum|The value must be strictly greater than this number.| |maximum|The value must be less than or equal to this number.| |exclusiveMaximum|The value must be strictly less than this number.|

Integer Validator Properties

EZ.Integer will define an integer property.

|Option|Description| |---|---| |minimum|The value must be greater than or equal to this number.| |maximum|The value must be less than or equal to this number.|

String Validator Properties

EZ.String will define a string property.

|Option|Description| |---|---| |minLength|The value must have length greater than or equal to this number.| |maxLength|The value must have length less than or equal to this number.| |pattern|The value must match this regular expression|

Boolean Validator Properties

EZ.Boolean will define a string property.

|Option|Description| |---|---| |truthyValues|An array of strings to consider true| |falseyValues|An array of strings to consider false| |strictCase|Should matching against truthy and falsey values consider case? Defaults to false|

Env Files

The supported format for env files is fairly standard. Here's a quick overview.

Variables

Variable names must start with a letter and contain only letters, numbers, and underscores.

Assignments

Setting a value to a variable in the env file is done in bash style, with the variable name on the left, an equal sign, and the value on the right.

SOME_STRING=this is a value

Values

The right side of an assignment can take two different forms; a literal string or a quoted string.

Quoted Values

Quoted values begin and end with either a single or double quote. By defining a value within quotes it will be allowed to include the escaped character sequences for newline ( \n ), tab ( \t ), character-return ( \r ), form-feed ( \f ), and unicode character ( \u0000 ) (where 0000 is a hex sequence for the desired character). This also means that the escape character ( \ ) and either double ( " ) or single quote ( ' ) character must be escaped in quoted values. Finally, the dollar sign ( $ ) can be escaped to prevent it being used for variable substitution.

Literal Values

These are interpreted without any escape sequences or variable substitution. They are also trimmed of any whitespace preceeding or following the value.

Variable Substitution

Quoted values can include other variables either from within the env file or from the system environment. To do this, the dollar sign character ( $ ) is used to indicate a substitution when followed by a valid variable name.

OTHER_STRING="SOME VALUE"
SOME_STRING="$OTHER_STRING"

# Gives SOME_STRING === "SOME VALUE"

When the position of the substitution is immeditately followed by other valid variable name characters, you will need to wrap the variable name in curly braces to distinguish it.

OTHER_STRING="SOME "
SOME_STRING="${OTHER_STRING}VALUE"

# Gives SOME_STRING === "SOME VALUE"

Comments

Anything to the right of a hash sign ( # ) are interpreted as comments and ignored by the parser, as long as the hash is not within quotes.

SOME_STRING="# this is not ignored" # this is ignored

# this is also ignored