8
0

objecttomap.js 510 B

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