partitionObjectByKey.js.flow 691 B

12345678910111213141516171819202122232425
  1. /**
  2. * Copyright 2015-present Facebook. All Rights Reserved.
  3. *
  4. * @providesModule partitionObjectByKey
  5. * @typechecks
  6. * @flow
  7. */
  8. 'use strict';
  9. import type Set from "./Set";
  10. var partitionObject = require("./partitionObject");
  11. /**
  12. * Partitions the enumerable properties of an object into two objects, given a
  13. * whitelist `Set` for the first object. This is comparable to
  14. * `whitelistObjectKeys`, but eventually keeping all the keys. Returns a tuple
  15. * of objects `[first, second]`.
  16. */
  17. function partitionObjectByKey(source: Object, whitelist: Set<string>): [Object, Object] {
  18. return partitionObject(source, (_, key) => whitelist.has(key));
  19. }
  20. module.exports = partitionObjectByKey;