envix ⚙️
This library simplifies reading, transforming, and requiring environment variables across runtimes like Node.js, Deno, Bun.js, Browser, and more.
Table of Contents
Installation
npm install envix --save
Usage
Write
The write method makes it possible to set an environment variable retrospectively for later accesses.
import { write } from 'envix';
write('foo', 'bar');
Read
The read method accepts the key of the environment variable as the first argument and an
alternative value as the second argument, which is returned if the variable does not exist.
If no argument is passed, an object with all environment variables is returned.
import { read, write } from 'envix';
write('foo', 'bar');
read('foo');
read('bar', 'baz');
Read Array
The readArray method makes it possible to read an environment variable as a string array.
A fallback value can be defined as the second argument.
import { readArray, write } from 'envix';
write('foo', 'bar,baz');
readArray('foo');
readArray('bar', ['foo']);
Read Bool
The readBool method makes it possible to read an environment variable as a boolean.
A fallback value can be defined as the second argument.
import { readBool, write } from 'envix';
write('foo', 'true');
readBool('foo');
readBool('bar', false);
Read Float
The readFloat method makes it possible to read an environment variable as a float.
A fallback value can be defined as the second argument.
import { readFloat, write } from 'envix';
write('foo', '1');
readFloat('foo');
readFloat('bar', 2.0);
Read Int
The readInt method makes it possible to read an environment variable as a integer.
A fallback value can be defined as the second argument.
import { readInt, write } from 'envix';
write('foo', '1.0');
readInt('foo');
readInt('bar', 2);
Read Number
The readNumber method makes it possible to read an environment variable as a number.
A fallback value can be defined as the second argument.
import { readNumber, write } from 'envix';
write('foo', '1.0');
readNumber('foo');
readNumber('bar', 2.0);
Read Number Array
The readNumberArray method makes it possible to read an environment variable as a number array.
A fallback value can be defined as the second argument.
import { readNumberArray, write } from 'envix';
write('foo', '1.0,2.1');
readNumberArray('foo');
readNumberArray('bar', [2,3]);
Contributing
Before starting to work on a pull request, it is important to review the guidelines for
contributing and the code of conduct.
These guidelines will help to ensure that contributions are made effectively and are accepted.
License
Made with 💚
Published under MIT License.