Miss any of our Open RFC calls?Watch the recordings here! »

This package has been deprecated

Author message:

No longer maintained.

fi-consts

1.0.1 • Public • Published

Fi Consts

Simple constant management for your application.

Installing

npm install --save fi-consts

Usage

const CONSTS = require('fi-consts');

Loading

You must first load your constants with a valid config object:

consts CONSTS = require('fi-consts');
 
CONSTS.load(config);
 
// CONSTS now has your constants!
 

Configuration

The configuration Object must have the basedir property defined as a valid path String. The debug parameter is optional.

  • basedir: This is required and must be a String. This must be the absolute path to where the consts are located.
  • debug: This option can be a Function to log with or a Boolean. If true it'll use console.log.

Example configuration

{
 
  debug = require('debug')('app:statics'),
 
  basedir: path.join(__dirname, 'consts'),
 
}

Getting values

Suppose we have this folder structure for the constants:

consts
├── other
│   ├── embedded
│   │   └── values.json
│   └── values.json
└── roles.json

Once loaded, this module will cache all your constants data into memory. To obtain a value just navigate the object. Keep in mind that all constant properties are defined in UPPER_CASE:

console.log(CONSTS.ROLES.USER); // => { VALUE: 'value1234', SLUG: 'ROLE.USER' };
console.log(CONSTS.ROLES.USER.SLUG); // => 'ROLE.USER'
console.log(CONSTS.ROLES.OTHER.EMBEDDED.VALUES); // => { VALUE_1: {...}, VALUE_2: {...}}

Install

npm i fi-consts

DownloadsWeekly Downloads

3

Version

1.0.1

License

MIT

Last publish

Collaborators

  • avatar
  • avatar