Matteo Scandolo | 280dcd3 | 2016-05-16 09:59:38 -0700 | [diff] [blame^] | 1 | 'use strict'; |
| 2 | |
| 3 | var _ = 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 | */ |
| 15 | function 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 | |
| 23 | Hash.prototype = Object.create(null); |
| 24 | |
| 25 | module.exports = { |
| 26 | 'Hash': Hash |
| 27 | }; |