Skip to content

Commit

Permalink
Merge 736adcb into 0f18464
Browse files Browse the repository at this point in the history
  • Loading branch information
madarche committed May 9, 2020
2 parents 0f18464 + 736adcb commit da911d6
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 24 deletions.
18 changes: 12 additions & 6 deletions README.md
Expand Up @@ -15,16 +15,22 @@ when configuration goes wrong.
This repository is a monorepo for the following packages managed through
[Lerna](https://lerna.js.org/).


## Packages

- [convict](/packages/convict/) :
the main package
* [convict](/packages/convict/) :
the main package

* [convict-format-with-validator](/packages/convict-format-with-validator/)
the optional package providing the `email`, `ipaddress` and `url` formats

* [convict-format-with-moment](/packages/convict-format-with-moment/) :
the optional package providing the `duration` and `timestamp` formats


- [convict-format-with-moment](/packages/convict-format-with-moment/) :
the optional package providing the `duration` and `timestamp` formats
## Migrating

- [convict-format-with-validator](/packages/convict-format-with-validator/)
the optional package providing the `email`, `ipaddress` and `url` formats
* [Migrating from Convict 5 to 6](/packages/convict/MIGRATING_FROM_CONVICT_5_TO_6.md)


## Contributing
Expand Down
11 changes: 8 additions & 3 deletions packages/convict-format-with-moment/README.md
Expand Up @@ -18,9 +18,14 @@ An example `config.js` file:

```javascript
const convict = require('convict');
const convict_format_with_moment = require('convict-format-with-moment');

convict.addFormat(require('convict-format-with-moment').duration);
convict.addFormat(require('convict-format-with-moment').timestamp);
// Add all formats
convict.addFormats(convict_format_with_moment);

// Or add only specific formats:
// convict.addFormat(convict_format_with_moment.duration);
// etc.

// Define a schema
var config = convict({
Expand All @@ -36,7 +41,7 @@ var config = convict({

### Validation

Use Moment.js to validate:
Validation done through Moment.js:

* `duration` - milliseconds or a human readable string (e.g. 3000, "5 days")
* `timestamp` - Unix timestamps or date strings recognized by Moment.js
Expand Down
4 changes: 2 additions & 2 deletions packages/convict-format-with-moment/test/format.test.js
Expand Up @@ -2,13 +2,13 @@

const moment = require('moment')
const convict = require('convict')
const convict_format_with_moment = require('../')

describe('convict formats', function() {
let conf

test('must add "duration" and "timestamp" format with convict-format-with-moment', function() {
convict.addFormat(require('../').duration)
convict.addFormat(require('../').timestamp)
convict.addFormats(convict_format_with_moment)
})

test('must parse a config specification', function() {
Expand Down
20 changes: 8 additions & 12 deletions packages/convict-format-with-validator/README.md
@@ -1,14 +1,8 @@
# Convict-validator

[![NPM version](http://img.shields.io/npm/v/convict-format-with-validator.svg)](https://www.npmjs.org/package/convict-format-with-validator)

Format 'email', 'ipaddress' and 'url' for convict with validatorjs.

# Convict-format-with-validator

[![NPM version](http://img.shields.io/npm/v/convict-format-with-validator.svg)](https://www.npmjs.org/package/convict-format-with-validator)

[validator.js](https://github.com/validatorjs/validator.js) formats for convict.
Formats `email`, `ipaddress` and `url` for convict with [validator.js](https://github.com/validatorjs/validator.js).


## Install
Expand All @@ -24,12 +18,14 @@ An example `config.js` file:

```javascript
const convict = require('convict');
const convict_format_with_validator = require('convict-format-with-validator');

convict.addFormat(require('convict-format-with-validator').ipaddress);
convict.addFormat(require('convict-format-with-validator').port);
// Add all formats
convict.addFormats(convict_format_with_validator);

// or :
// convict.addFormats(require('convict-format-with-validator'));
// Or add only specific formats:
// convict.addFormat(convict_format_with_validator.ipaddress);
// etc.

// Define a schema
var config = convict({
Expand All @@ -51,7 +47,7 @@ var config = convict({

### Validation

Use [validator.js](https://github.com/chriso/node-validator#list-of-validation-methods) to validate:
Validation done through validator.js:

* `email`
* `ipaddress` - IPv4 and IPv6 addresses
Expand Down
3 changes: 2 additions & 1 deletion packages/convict-format-with-validator/test/format.test.js
@@ -1,12 +1,13 @@
'use strict'

const convict = require('convict')
const convict_format_with_validator = require('../')

describe('convict formats', function() {
let conf

test('must add formats ("email", "ipaddress" and "url") with convict-format-with-validator', function() {
convict.addFormats(require('../'))
convict.addFormats(convict_format_with_validator)
})

test('must parse a config specification', function() {
Expand Down
38 changes: 38 additions & 0 deletions packages/convict/MIGRATING_FROM_CONVICT_5_TO_6.md
@@ -0,0 +1,38 @@
# Migrating from Convict 5 to 6

The main goal of `convict@6.0.0` was to make it have less dependencies by
default, so to make it less impacted by security vulnerabilites in those
dependencies. So this release introduced the following BREAKING changes:

* Multi-packages split. There are now 3 packages: `convict`,
`convict-format-with-validator`, `convict-format-with-moment`
* Removal of the `json5` dependency to make it an optional

Old pre-`convict@6.0.0` code:

```javascript
const convict = require('convict')

const config = convict(config_schema)
```

New post-`convict@6.0.0` code:

```javascript
const convict = require('convict')
const convict_format_with_validator = require('convict-format-with-validator')
const convict_format_with_moment = require('convict-format-with-moment')
const json5 = require('json5')

// Use this only if you use the "email", "ipaddress" or "url" format
convict.addFormats(convict_format_with_validator)

// Use this only if you use the "duration" or "timestamp" format
convict.addFormats(convict_format_with_moment)

// Use this only if you have a .json configuration file in JSON5 format
// (i.e. with comments, etc.).
convict.addParser({extension: 'json', parse: JSON.parse})

const config = convict(config_schema)
```
9 changes: 9 additions & 0 deletions packages/convict/README.md
@@ -1,6 +1,10 @@
# Convict

[![NPM version](http://img.shields.io/npm/v/convict.svg)](https://www.npmjs.org/package/convict)
[![Dependency Status](https://david-dm.org/mozilla/node-convict.svg)](https://david-dm.org/mozilla/node-convict)
[![devDependency Status](https://david-dm.org/mozilla/node-convict/dev-status.svg)](https://david-dm.org/mozilla/node-convict#info=devDependencies)
[![Build Status](https://travis-ci.org/mozilla/node-convict.svg?branch=master)](https://travis-ci.org/mozilla/node-convict)
[![Coverage Status](https://coveralls.io/repos/github/mozilla/node-convict/badge.svg?branch=master)](https://coveralls.io/github/mozilla/node-convict?branch=master)

Convict expands on the standard pattern of configuring node.js applications in a
way that is more robust and accessible to collaborators, who may have less
Expand Down Expand Up @@ -608,3 +612,8 @@ Thanks to [browserify](http://browserify.org/), `convict` can be used for web ap

* Use [`brfs`](https://www.npmjs.com/package/brfs) to ensure the `fs.loadFileSync` schema-loading calls are inlined at build time rather than resolved at runtime (in Gulp, add `.transform(brfs)` to your browserify pipe).
* To support *"loading configuration from a `http://foo.bar/some.json` URL"*, build a thin wrapper around convict using your favorite http package (e.g. [`superagent`](https://visionmedia.github.io/superagent/)). Typically, in the success callback, call convict's `load()` on the body of the response.


## Migrating

* [Migrating from Convict 5 to 6](MIGRATING_FROM_CONVICT_5_TO_6.md)

0 comments on commit da911d6

Please sign in to comment.