nconf-strip-json-comments

0.1.0 • Public • Published

nconf-strip-json-comments Build Status

A tiny module enabling nconf to parse commented JSON files.

  {
    // User data
    "user": "contact@hoffonline.com", // an email address
    "password": "Freedom",

    // General setup
    "environment": "production",    // or "stage", "development"

    ...
  }

Comments in JSON files can be helpful e.g. in configuration files. However, comments are not part of the JSON format and standard JSON tools such as JSON.parse can't handle commented files. Instead, tools like jsonminify or strip-json-comments are required. This module enables the nconf module to parse commented JSON files using strip-json-comments.

Usage

Enable nconf to parse commented JSON files by default:

  var nconf = require('nconf');
  require('nconf-strip-json-comments')(nconf);

  nconf.file('path_to_some_commented_JSON_');

Note that this will enable extended parsing globally, that is, for all occurrences of nconf (also in nested modules).

You can also use the module's extended JSON format explicitly:

  var nconf = require('nconf');
  var commentedJsonFormat = require('nconf-strip-json-comments').format;

  nconf.file({file: 'path_to_some_commented_JSON_', format: commentedJsonFormat});

To disable a previously globally enabled parsing, use restore():

  ...
  require('nconf-strip-json-comments').restore(nconf);

License

nconf-strip-json-comments is licensed under the BSD 3-Clause License.

Package Sidebar

Install

npm i nconf-strip-json-comments

Weekly Downloads

0

Version

0.1.0

License

BSD-3-Clause

Last publish

Collaborators

  • thirtified