Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
exotic / dist / types / collection / fromObjToMap.js
Size: Mime:
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
// import { hasOwnProp } from 'exotic/types/attributes/properties'
const properties_1 = require("../attributes/properties");
/**
 * Object into a Map
 * @since 5.0.0-beta.6
 * @memberOf cast
 *
 * @name objToMap
 * @alias objectToMap
 *
 * @param  {*} obj cast to Map
 * @return {Map} Map(x)
 *
 * Object.keys(obj).forEach(key => map.set(key, obj[key]))
 * @TODO use `forOwn`
 * @TODO can just use obj.hasOwnProp again?
 *
 * {@link https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Object/entries#Converting_an_Object_to_a_Map mozilla-obj-to-map}
 * @see {@link mozilla-obj-to-map}
 *
 * @example
 *
 *    const obj = {eh: 0}
 *    const map = objToMap(obj)
 *
 *    map.has('eh')
 *    //=> true
 *
 *    map.get('eh')
 *    //=> 0
 *
 *    map.size
 *    //=> 1
 *
 */
const objToMap = (obj) => {
    const map = new Map();
    // eslint-disable-next-line
    for (const prop in obj)
        properties_1.hasOwnProp(obj, prop) && map.set(prop, obj[prop]);
    return map;
};
exports.objToMap = objToMap;
exports.default = objToMap;
//# sourceMappingURL=fromObjToMap.js.map