Code coverage report for ReactFlux/lib/constants.js

Statements: 100% (21 / 21)      Branches: 100% (10 / 10)      Functions: 100% (2 / 2)      Lines: 100% (21 / 21)      Ignored: none     

All files » ReactFlux/lib/ » constants.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 381 1 1   1   1   10 1     9   9 1     8 5     8 8   15 1     14 14 14 14   7      
var _forEach = require('lodash-node/modern/collection/forEach');
var _isArray = require('lodash-node/modern/lang/isArray');
var _isString = require('lodash-node/modern/lang/isString');
 
var cfgs = require('./configs').constants.get();
 
module.exports = function (constants, prefix) {
 
	if (!_isArray(constants)) {
		throw new Error('createConstants expects first parameter to be an array of strings');
	}
 
	prefix = prefix || '';
 
	if (!_isString(prefix)) {
		throw new Error('createConstants expects second parameter string');
	}
 
	if (prefix.length > 0) {
		prefix += cfgs.separator;
	}
 
	var ret = {};
	_forEach(constants, function (constant) {
 
		if (!_isString(constant)) {
			throw new Error('createConstants expects all constants to be strings');
		}
 
		ret[constant] = prefix + constant;
		ret[constant + '_' + cfgs.successSuffix] = prefix + constant + cfgs.separator + cfgs.successSuffix;
		ret[constant + '_' + cfgs.failSuffix] = prefix + constant + cfgs.separator + cfgs.failSuffix;
		ret[constant + '_' + cfgs.afterSuffix] = prefix + constant + cfgs.separator + cfgs.afterSuffix;
	});
	return ret;
 
};