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

virvar

v1.0.2

Published

Simple environment variable utility

Downloads

7

Readme

npm version Build status

Install

npm install --save virvar

Tested with Node >= 0.12

Use

// process.env = {
//   STRING_VAL: 'http://localhost',
//   INT_VAL: '3000',
//   FLOAT_VAL: '33.333',
//   BOOL_VAL1: 'true',
//   BOOL_VAL2: 'yes',
//   BOOL_VAL3: '1',
//   BOOL_VAL3: 'false',
//   JSON_VAL: '{"a":1,"b":2,"c":3}',
//   ARRAY_VAL: 'item1,item2,item3'
// }

var vv = require('virvar');

console.log(vv('STRING_VAL')); // 'http://localhost'
console.log(vv('MISSING_VAL', true)); // throws Error
console.log(vv('INT_VAL', false, 'i')); // 3000
console.log(vv('FLOAT_VAL', false, 'f')); // 33.333
console.log(vv('BOOL_VAL1', false, 'b')); // true
console.log(vv('BOOL_VAL2', false, 'b')); // true
console.log(vv('BOOL_VAL3', false, 'b')); // true
console.log(vv('BOOL_VAL4', false, 'b')); // false
console.log(vv('JSON_VAL', false, 'j')); // { a: 1, b: 2, c: 3 }
console.log(vv('ARRAY_VAL', false, 'a')); // [ 'item1', 'item2', 'item3' ]

vv(name, required, type)

Returns the value of the environment variable, optionally parsing it into the given type. Throws an error if the required parameter is truthy and the value is loosely equal to null (before conversion).

name

Type: string

The name of the environment variable.

required

Type: boolean Default: false

When true, an Error is thrown if the variable is not set.

type

Type: string

By default, a string is returned. That string can be parsed into a different type by passing one of these values:

  • 'a' Parses a comma-separated string into an array
  • 'b' Parses the value into a boolean
  • 'f' Parses the value into a float (using parseFloat)
  • 'i' Parses the value into an integer (using parseInt)
  • 'j' Parses the value into an object (using JSON.parse)

Why virvar?

Because environment variable.

🙃