objecttomap.js 697 B

1234567891011121314151617181920212223242526272829
  1. /**
  2. * @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  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. * **Note**: For mixed data (`Object` or `Iterable`) there's a dedicated {@link module:utils/tomap~toMap} function.
  15. *
  16. * @param {Object} obj Object to transform.
  17. * @returns {Map} Map created from object.
  18. */
  19. export default function objectToMap( obj ) {
  20. const map = new Map();
  21. for ( const key in obj ) {
  22. map.set( key, obj[ key ] );
  23. }
  24. return map;
  25. }