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

@mx7/tenv

v1.1.0

Published

type-safe environment variable parser

Downloads

7

Readme

Type-safe .env variable parser

This package is a type-safe parser for .env files. It is built for node.js based typescript applications.

Installation

Recommending NodeJS v18.x (LTS) or later

This package cannot load the environment variables itself. You need to use something like dotenv or latest NodeJs built-in env-file loader

$ npm i @mx7/tenv
# or
$ yarn add @mx7/tenv
# or
$ pnpm add @mx7/tenv

Sample Usages

import 'dotenv/config'; // peer dependency (if you are using dotenv)
import Env from '@mx7/tenv';

const parsed = process.env as Record<string, string>;
const env = new Env(parsed); // instance of Env class

const port = env.key<number>('PORT', true).integer().unsigned().get();
// or, set a default value instead of make this required
const port = env.key<number>('PORT', 3000).integer().unsigned().get();

console.log(port); // i.e. 3000 as number

More Information

| Method | Description | Action | | ------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------- | | get() | Get the value of the environment variable. Should be called at last as chained | value withexpected type | | key() | key<T = string>(key: string, factor?: boolean \| T) Define the variable name as key & follow next: - set factor: true if it is required! - set factor: false or undefined (no need to pass) for accepting undefined value if not exists! - set factor: T (generic) as your default value | | | email() | It will validate the passed string as email | | | url() | It will validate the passed string as url.if it requires IPv6 address, do it as url({ ipv6: true }) | | | integer() | It will validate the passed value as integer | | | float() | It will validate the passed value as float | | | signed() | It will validate the passed value as signed number | | | unsigned() | It will validate the passed value as unsigned number | | | boolean() | It will validate the passed value as boolean | |

Author

Made with ❤️ by @mahabubx7

Changelogs

| Version | Released At | Description | | --------------- | ----------- | ---------------------------------------------------------------------------------------- | | v1.1.0 minor | 2024-01-31 | Minor update release v1.1 | | v1.0.0 stable | 2024-01-31 | Major stable release v1.x | | v0.7.7 stable | 2024-01-31 | First stable release with new feature => default value can attached with key() method | | v0.7.2 beta | 2024-01-31 | Added more supports and fixes small & minor issues with changes | | v0.7.0 beta | 2024-01-30 | @mx7/tenv with nodejs v18.x LTS or later compatible for type-safe .env variable parser |