blob: 64451862d0b9b6b7b3a6c805299caacc9b8eb85a [file] [log] [blame]
Matteo Scandolo280dcd32016-05-16 09:59:38 -07001'use strict';
2
3var _ = require('lodash');
4
5/*----------------------------------------------------------------------------*/
6
7/**
8 * Creates a hash object. If a `properties` object is provided, its own
9 * enumerable properties are assigned to the created object.
10 *
11 * @memberOf util
12 * @param {Object} [properties] The properties to assign to the object.
13 * @returns {Object} Returns the new hash object.
14 */
15function Hash(properties) {
16 return _.transform(properties, function(result, value, key) {
17 result[key] = (_.isPlainObject(value) && !(value instanceof Hash))
18 ? new Hash(value)
19 : value;
20 }, this);
21}
22
23Hash.prototype = Object.create(null);
24
25module.exports = {
26 'Hash': Hash
27};