UNPKG

666 BJavaScriptView Raw
1const { assign, create, defineProperties, keys } = Object;
2
3/**
4 * Create a clean Object
5 * - without a prototype
6 * - with immutable properties.
7 *
8 * @param {Object} interfaceObject
9 * @param {Object} options
10 * @return {Object}
11 */
12function dictionary(interfaceObject, options = {}) {
13 const { enumerable = true } = options;
14 const reduceInterface = (descriptors, propertyName) =>
15 assign(descriptors, {
16 [propertyName]: {
17 enumerable,
18 value: interfaceObject[propertyName],
19 },
20 });
21
22 return defineProperties(
23 create(null),
24 keys(interfaceObject).reduce(reduceInterface, create(null))
25 );
26}
27
28module.exports = dictionary;