mapsequal.js 651 B

123456789101112131415161718192021222324252627282930
  1. /**
  2. * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  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. * @returns {Boolean} `true` if given maps are equal, `false` otherwise.
  12. */
  13. export default function mapsEqual( mapA, mapB ) {
  14. if ( mapA.size != mapB.size ) {
  15. return false;
  16. }
  17. for ( const attr of mapA.entries() ) {
  18. const valA = JSON.stringify( attr[ 1 ] );
  19. const valB = JSON.stringify( mapB.get( attr[ 0 ] ) );
  20. if ( valA !== valB ) {
  21. return false;
  22. }
  23. }
  24. return true;
  25. }