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

boca

v0.1.1

Published

Zero-config environment variable parser for twelve-factor apps

Downloads

32

Readme

boca

npm npm bundle size npm install size maintainability code coverage vulnerabilities dependencies

  • 💻 Environment variables. Parses environment variables using your project's package.json name as a default prefix!
  • 📁 Nested variables. Environment variable names are split by __ and transformed into nested objects automatically!
  • 💯 Zero configuration. Boca works out-of-the-box using sensible defaults with no configuration required!
  • 💪 TypeScript. Fully typed and self-documenting!

🚀 Quick Start

Install

# npm
npm i boca

# or yarn
yarn add boca

Import

// ESM / TypeScript
import { $parse } from "boca";

// or CommonJS
const { $parse } = require("boca");

Parse

// process.env = { BOCA_HOST: '0.0.0.0', BOCA_PORT: '3000' }
const config = $parse({ prefix: 'boca' });

console.log(JSON.stringify(config));
// => { "host": "0.0.0.0", "port": 3000 }

📃 Default Values

See options.defaults.

📤 Default Export

$parse is also exported as the default member so you can import Boca and parse your environment variables in one line:

const config = require("boca")();

💪 TypeScript Generics

$parse supports generics so you can have type definitions for your parsed environment variables:

const config = $parse<{ host: string; port: number }>();
// => config.host and config.port now have type definitions

⚙ Options

You can supply options to $parse to configure Boca's parsing behaviour.

options.defaults

Any default values that should be used if an environment variable is not found.

options.format

Please see read-env's documentation on this option as that is the underlying library used by Boca to parse environment variables.

options.includePrefix

Whether the environment variable name prefix should be included or removed after being parsed by Boca.

By default, this is false (so the prefix is removed).

options.prefix

This is the prefix that will be used to filter out environment variables.

@ characters are removed, and - and / characters are replaced with _ to support NPM scoped package names.

For example, if the supplied prefix is @moducate/houston, Boca will look for environment variables prefixed with MODUCATE_HOUSTON_.

By default, your project's package.json name or current working directory name is used.

options.sanitize

Please see read-env's documentation on this option as that is the underlying library used by Boca to parse environment variables.

options.separator

The separator used to identify and transform nested objects.

If set to false, nested objects are disabled.

By default, the separator for nested objects is __.

options.source

The source to read environment variables from.

By default, process.env is used.

⚖ License

Boca is licensed under the MIT License.

Attribution

Boca's banner background is sourced from SVGBackgrounds.com.