mapsequal.js 796 B

1234567891011121314151617181920212223242526272829303132
  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/mapsequal
  7. */
  8. /**
  9. * Checks whether given {Map}s are equal, that is has same size and same key-value pairs.
  10. *
  11. * @param {Map} mapA The first map to compare.
  12. * @param {Map} mapB The second map to compare.
  13. * @returns {Boolean} `true` if given maps are equal, `false` otherwise.
  14. */
  15. export default function mapsEqual( mapA, mapB ) {
  16. if ( mapA.size != mapB.size ) {
  17. return false;
  18. }
  19. for ( const attr of mapA.entries() ) {
  20. const valA = JSON.stringify( attr[ 1 ] );
  21. const valB = JSON.stringify( mapB.get( attr[ 0 ] ) );
  22. if ( valA !== valB ) {
  23. return false;
  24. }
  25. }
  26. return true;
  27. }