objectToMap.js 405 B

12345678910111213141516
  1. /**
  2. * convert an object into its 2D array equivalent to be turned
  3. * into an ES6 map
  4. *
  5. * @param {object} obj any object type that works with Object.keys()
  6. * @returns {Map<TODO, TODO>} an ES6 Map of KV pairs
  7. */
  8. module.exports = function objectToMap(obj) {
  9. return new Map(
  10. Object.keys(obj).map(key => {
  11. /** @type {[string, string]} */
  12. const pair = [key, obj[key]];
  13. return pair;
  14. })
  15. );
  16. };