objecttomap.js 528 B

123456789101112131415161718192021222324252627
  1. /**
  2. * @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /**
  6. * @module utils/objecttomap
  7. */
  8. /**
  9. * Transforms object to map.
  10. *
  11. * const map = objectToMap( { 'foo': 1, 'bar': 2 } );
  12. * map.get( 'foo' ); // 1
  13. *
  14. * @param {Object} obj Object to transform.
  15. * @returns {Map} Map created from object.
  16. */
  17. export default function objectToMap( obj ) {
  18. const map = new Map();
  19. for ( const key in obj ) {
  20. map.set( key, obj[ key ] );
  21. }
  22. return map;
  23. }