Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Evan Shortiss <[email protected]>
  • Loading branch information
DigiPie and evanshortiss authored Nov 10, 2020
1 parent 67d7927 commit 45b7f75
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 25 deletions.
26 changes: 13 additions & 13 deletions API.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# API

This document lists all API methods `env-var` has.
A complete listing of the `env-var` API.

## Structure

Expand Down Expand Up @@ -35,7 +35,7 @@ This document lists all API methods `env-var` has.

## from(values, extraAccessors, logger)

This function is useful if you are not in a typical Node.js environment, or for
This function is useful if you are not in a typical Node.js environment, want to set defaults, or for
testing. It allows you to generate an `env-var` instance that reads from the
given `values` instead of the default `process.env` Object.

Expand Down Expand Up @@ -71,8 +71,8 @@ function yourLoggerFn (varname, str) {

This function has two behaviours:

1. Calling with a string argument will make it read that value from the environment
2. If no string argument is passed it will return the entire environment object
1. Passing a string argument will read that value from the environment
2. If no argument is passed it will return the entire environment object

Examples:

Expand All @@ -88,7 +88,7 @@ const allVars = env.get()

### variable

A variable is returned by calling `env.get(varname)`. It exposes the following
A variable is returned when `env.get(varname)` is called. It exposes the following
functions to validate and access the underlying value, set a default, or set
an example value:

Expand Down Expand Up @@ -118,10 +118,10 @@ env-var: "ADMIN_EMAIL" is a required variable, but it was not set. An example
of a valid value would be "[email protected]"
```

#### default(string)
#### default(defaultValue: string)

Allows a default value to be provided for use if the desired environment
variable is not set in the program environment.
variable is not set in the program environment, i.e not present on `process.env`.

Example:

Expand All @@ -134,7 +134,7 @@ const POOL_SIZE = env.get('POOL_SIZE').default('10').asIntPositive()

#### required(isRequired = true)

Ensure the variable is set on *process.env*. If the variable is not set, or is
Ensure the variable is set on `process.env`. If the variable is not set, or is
set to an empty value, this function will cause an `EnvVarError` to be thrown
when you attempt to read the value using `asString` or a similar function.

Expand Down Expand Up @@ -238,11 +238,11 @@ parsing fails.

#### asJsonArray()

The same as _asJson_ but checks that the data is a JSON Array, e.g. [1,2].
The same as _asJson_ but verifies that the data is a JSON Array, e.g. [1,2].

#### asJsonObject()

The same as _asJson_ but checks that the data is a JSON Object, e.g. {a: 1}.
The same as _asJson_ but verifies that the data is a JSON Object, e.g. {a: 1}.

#### asPortNumber()

Expand All @@ -260,7 +260,7 @@ passed for `flags` is passed as the second argument to the `RegExp` constructor.

Return the variable value as a String. Throws an exception if value is not a
String. It's highly unlikely that a variable will not be a String since all
*process.env* entries you set in bash are Strings by default.
`process.env` entries you set in bash are Strings by default.

#### asUrlObject()

Expand All @@ -272,7 +272,7 @@ see the [Node.js URL docs](https://nodejs.org/docs/latest/api/url.html#url_class

Verifies that the variable is a valid URL string and returns the validated
string. The validation is performed by passing the URL string to the
[Node.js URL constructor](https://nodejs.org/docs/latest/api/url.html#url_class_url).
WHATWG URL constructor.

Note that URLs without paths will have a default path `/` appended when read, e.g.
`https://api.acme.org` would become `https://api.acme.org/`. Always use URL
Expand Down Expand Up @@ -483,4 +483,4 @@ env.get('ADMIN').asEmail()
```

You can view an example of composing built-in accessors made available by
`env.accessors` in an extra accessor at *examples/custom-accessor.js*.
`env.accessors` in an extra accessor at *examples/custom-accessor.js*.
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
<div align="center">

[![NPM version](https://img.shields.io/npm/v/env-var.svg?style=flat)](https://www.npmjs.com/package/env-var)
[![Typescript](https://badgen.net/npm/types/env-var)](http://www.Typescriptlang.org/)
[![TypeScript](https://badgen.net/npm/types/env-var)](http://www.typescriptlang.org/)
[![License](https://badgen.net/npm/license/env-var)](https://opensource.org/licenses/MIT)
[![Travis CI](https://travis-ci.org/evanshortiss/env-var.svg?branch=master)](https://travis-ci.org/evanshortiss/env-var)
[![Coverage Status](https://coveralls.io/repos/github/evanshortiss/env-var/badge.svg?branch=master)](https://coveralls.io/github/evanshortiss/env-var?branch=master)
[![npm downloads](https://img.shields.io/npm/dm/env-var.svg?style=flat)](https://www.npmjs.com/package/env-var)
[![Known Vulnerabilities](https://snyk.io//test/github/evanshortiss/env-var/badge.svg?targetFile=package.json)](https://snyk.io//test/github/evanshortiss/env-var?targetFile=package.json)


Verification, sanitization, and type coercion for environment variables in Node.js. Supports Typescript!
Verification, sanitization, and type coercion for environment variables in Node.js and web applications. Supports TypeScript!
<br>
<br>
</div>
Expand All @@ -20,16 +20,16 @@ Verification, sanitization, and type coercion for environment variables in Node.
* 🧹 Clean and simple code, as [shown here](https://gist.github.com/evanshortiss/0cb049bf676b6138d13384671dad750d).
* 🚫 [Fails fast](https://en.wikipedia.org/wiki/Fail-fast) if your environment is misconfigured.
* 👩‍💻 Friendly error messages and example values for better debugging experience.
* 🎉 Typescript support provides compile time safety and better developer experience.
* 📦 Can be used for non-NodeJS projects such as [React and React-native projects](https://github.com/evanshortiss/env-var/pull/138).
* 🎉 TypeScript support provides compile time safety and better developer experience.
* 📦 Support for frontend projects, e.g in React, React Native, Angular, etc.

## Documentation structure
## Contents

- [API.md](API.md): The full API set for `env-var`
- [CHANGELOG.md](CHANGELOG.md)
- [CODE_OF_CONDUCT.md](CODE_OF_CONDUCT.md)
- [CONTRIBUTING.md](CONTRIBUTING.md)
- [EXAMPLE.md](EXAMPLE.md): Example usage of `env-var`
- [API](API.md): The full API set for `env-var`
- [Changelog](CHANGELOG.md)
- [Code of Conduct](CODE_OF_CONDUCT.md)
- [Contributing](CONTRIBUTING.md)
- [Examples](EXAMPLE.md): Example usage of `env-var`
- [README.md](README.md): General and key information on this project

## Install
Expand All @@ -48,7 +48,7 @@ yarn add env-var

## Getting started

You can use `env-var` in both Javascript and Typescript!
You can use `env-var` in both JavaScript and TypeScript!

### Javascript example

Expand All @@ -71,7 +71,7 @@ const PASSWORD = env.get('DB_PASSWORD')
const PORT = env.get('PORT').default('5432').asPortNumber()
```

### Typescript example
### TypeScript example

```ts
import * as env from 'env-var';
Expand Down

0 comments on commit 45b7f75

Please sign in to comment.