util-map-includes.js 574 B

12345678910111213141516171819
  1. 'use strict';
  2. var identity = require('../nodes/identity.js');
  3. function mapIncludes(ctx, items, search) {
  4. const { uniqueKeys } = ctx.options;
  5. if (uniqueKeys === false)
  6. return false;
  7. const isEqual = typeof uniqueKeys === 'function'
  8. ? uniqueKeys
  9. : (a, b) => a === b ||
  10. (identity.isScalar(a) &&
  11. identity.isScalar(b) &&
  12. a.value === b.value &&
  13. !(a.value === '<<' && ctx.schema.merge));
  14. return items.some(pair => isEqual(pair.key, search));
  15. }
  16. exports.mapIncludes = mapIncludes;