1.0.4 • Published 5 years ago

bh-section v1.0.4

Weekly downloads
4
License
ISC
Repository
gitlab
Last release
5 years ago

Installation

Use npm command in order to install bh-section module:

npm install [--save] bh-section

A JSON object parser

The bh-section "class" brings parsing methods to a JSON object:

  • field(key) : return the value of the field described by "key", throw an exception if the field does not exist
  • section(key) : return a bh-section object of the field described by "key", throw an exception if the field does not exist
  • exists(key) : return true if the field does exist, otherwise false

bh-section allows to easily control extern JSON file content: a configuration file for example. Thrown exceptions give a clear message in all situations when the developer attempt to use an unexisting field.

Usage example

var SectionClass = require('bh-section');

var test = new SectionClass({
  'a' : 'a',
  'b' : 'b',
  'c' : {
    'd' : 'd'
  }
});

var a = test.field('a'); //a = 'a'
var b = test.field('b'); //b = 'b'
var c = test.section('c');
var d = c.field('d'); //d = 'd'
var x = test.field('x')// Throw exception