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

x3-env

v1.0.2

Published

A env file reader written in Typescript.

Downloads

3

Readme

Intro

This is an environment file and value parsing piece of npm package. It aims to replace dotenv for me and anyone eager and brave enough to use it. It supports many features I missed.

The default export of this module is a function named env that takes an object with either file or content as field, where file must be a path and content must be either an utf8 Buffer or a string.

I build this, because dotenv does not support following:

TEST1=sgnirts driew tcelloc I
TEST2=I collect weird strings $TEST1

Or following:

HOME="$HOME$USERPOFILE"

This might not be cool but it's possible.

It does following:

  • Allow single quoted, double quoted and unquoted values
  • Parse variables within double quoted variable values or unquoted variable values
    • This is also true for all other variables in process.env
  • Not parse variables within single quoted variables
  • For content, this only supports utf8. Other formats have to be converted before. (e.g. by iconv-lite)
  • Parsed values will be spilled into process.env
  • Parsed values will be returned by the Promise

Usage

env({file: "/path/"});

or

env({content: "TEST=true"});

or

env({content: Buffer.from([106, 117, 115, 116, 107, 105, 100, 100, 105, 110, 103, 61, 116, 104, 105, 115, 105, 115, 110, 111, 114, 101, 97, 108, 101, 120, 97, 109, 112, 108, 101])});

Mind the d.ts:

export default function env({file, content}: {
    file?: string;
    content?: string | Buffer;
}): Promise<Map<string, string>>;

Examples:

const {env} = require("x3-env");
env({content:"IWANTTHISVAR=ichangedmymind"});

console.log(`I want following value: ${process.env("IWANTTHISVAR")}`);

Or

/**
 * .env.bootstrap content is:
 * HOME=$HOME$USERPROFILE
 * LOCAL_NOT_FOUND_ERROR=".env.local was not found
 * Please create $HOME/.env.local!"
 */
const {env} = require("x3-env");
const { existsSync } = require("fs");
const { join } = require("path");
env({ file: join(__dirname, ".env.bootstrap") });
if (existsSync(join(process.env["HOME"], ".env")))
	env({ file: join(process.env["HOME"], ".env") })
else
	throw new Error(process.env["LOCAL_NOT_FOUND_ERROR"]);