2016-05-16 13:33:49 +02:00
|
|
|
'use strict';
|
|
|
|
|
2017-05-13 13:25:33 +02:00
|
|
|
const _ = require('lodash');
|
2016-05-16 13:33:49 +02:00
|
|
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a hash object. If a `properties` object is provided, its own
|
2017-05-13 13:25:33 +02:00
|
|
|
* enumerable properties are assigned to the created hash.
|
2016-05-16 13:33:49 +02:00
|
|
|
*
|
|
|
|
* @memberOf util
|
2017-05-13 13:25:33 +02:00
|
|
|
* @param {Object} [properties] The properties to assign to the hash.
|
2016-05-16 13:33:49 +02:00
|
|
|
* @returns {Object} Returns the new hash object.
|
|
|
|
*/
|
|
|
|
function Hash(properties) {
|
2017-05-13 13:25:33 +02:00
|
|
|
return _.transform(properties, (result, value, key) => {
|
2016-05-16 13:33:49 +02:00
|
|
|
result[key] = (_.isPlainObject(value) && !(value instanceof Hash))
|
|
|
|
? new Hash(value)
|
|
|
|
: value;
|
|
|
|
}, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
Hash.prototype = Object.create(null);
|
|
|
|
|
2017-05-13 13:25:33 +02:00
|
|
|
/**
|
|
|
|
* This method throws any error it receives.
|
|
|
|
*
|
|
|
|
* @memberOf util
|
|
|
|
* @param {Object} [error] The error object.
|
|
|
|
*/
|
|
|
|
function pitch(error) {
|
|
|
|
if (error != null) {
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-16 13:33:49 +02:00
|
|
|
module.exports = {
|
2017-05-13 13:25:33 +02:00
|
|
|
Hash,
|
|
|
|
pitch
|
2016-05-16 13:33:49 +02:00
|
|
|
};
|