[![npm version][npm-version-src]][npm-version-href] [![npm version][codecov-src]][codecov-href] [![Master Workflow][workflow-src]][workflow-href] [![Known Vulnerabilities][snyk-src]][snyk-href] [![Conventional Commits][conventional-src]][conventional-href
npm install envix[![npm version][npm-version-src]][npm-version-href]
[![npm version][codecov-src]][codecov-href]
[![Master Workflow][workflow-src]][workflow-href]
[![Known Vulnerabilities][snyk-src]][snyk-href]
[![Conventional Commits][conventional-src]][conventional-href]
This library simplifies reading, transforming, and requiring environment variables across runtimes like Node.js, Deno, Bun.js, Browser, and more.
Table of Contents
- Installation
- Usage
- write
- read
- readArray
- readBool
- readFloat
- readInt
- readNumber
- readNumberArray
- Contributing
- License
``bash`
npm install envix --save
`typescript
import { write } from 'envix';
write('foo', 'bar');
`
`typescript
import { read, write } from 'envix';
write('foo', 'bar');
read('foo'); // string | undefined
// bar
read('bar', 'baz'); // string
// baz
`
typescript
import { readArray, write } from 'envix';write('foo', 'bar,baz');
readArray('foo'); // string[] | undefined
// ['bar', 'baz']
readArray('bar', ['foo']); // string[]
// ['foo']
`$3
The readBool method makes it possible to read an environment variable as a boolean.
A fallback value can be defined as the second argument.`typescript
import { readBool, write } from 'envix';write('foo', 'true');
readBool('foo'); // boolean | undefined
// true
readBool('bar', false); // boolean
// false
`$3
The readFloat method makes it possible to read an environment variable as a float.
A fallback value can be defined as the second argument.`typescript
import { readFloat, write } from 'envix';write('foo', '1');
readFloat('foo'); // number | undefined
// 1.0
readFloat('bar', 2.0); // number
// 2.0
`$3
The readInt method makes it possible to read an environment variable as a integer.
A fallback value can be defined as the second argument.`typescript
import { readInt, write } from 'envix';write('foo', '1.0');
readInt('foo'); // number | undefined
// 1
readInt('bar', 2); // number
// 2
`$3
The readNumber method makes it possible to read an environment variable as a number.
A fallback value can be defined as the second argument.`typescript
import { readNumber, write } from 'envix';write('foo', '1.0');
readNumber('foo'); // number | undefined
// 1.0
readNumber('bar', 2.0); // number
// 2.0
`$3
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.`typescript
import { readNumberArray, write } from 'envix';write('foo', '1.0,2.1');
readNumberArray('foo'); // number[] | undefined
// [1.0,2.1]
readNumberArray('bar', [2,3]); // number[]
// [2,3]
``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.
Made with 💚
Published under MIT License.
[npm-version-src]: https://badge.fury.io/js/envix.svg
[npm-version-href]: https://npmjs.com/package/envix
[codecov-src]: https://codecov.io/gh/Tada5hi/envix/branch/master/graph/badge.svg?token=4KNSG8L13V
[codecov-href]: https://codecov.io/gh/Tada5hi/envix
[workflow-src]: https://github.com/Tada5hi/envix/workflows/CI/badge.svg
[workflow-href]: https://github.com/Tada5hi/envix
[snyk-src]: https://snyk.io/test/github/Tada5hi/envix/badge.svg?targetFile=package.json
[snyk-href]: https://snyk.io/test/github/Tada5hi/envix?targetFile=package.json
[conventional-src]: https://img.shields.io/badge/Conventional%20Commits-1.0.0-%23FE5196?logo=conventionalcommits&logoColor=white
[conventional-href]: https://conventionalcommits.org