keyOf.js.flow 979 B

12345678910111213141516171819202122232425262728293031
  1. /**
  2. * Copyright (c) 2013-present, Facebook, Inc.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. *
  7. * @providesModule keyOf
  8. */
  9. /**
  10. * Allows extraction of a minified key. Let's the build system minify keys
  11. * without losing the ability to dynamically use key strings as values
  12. * themselves. Pass in an object with a single key/val pair and it will return
  13. * you the string key of that single record. Suppose you want to grab the
  14. * value for a key 'className' inside of an object. Key/val minification may
  15. * have aliased that key to be 'xa12'. keyOf({className: null}) will return
  16. * 'xa12' in that case. Resolve keys you want to use once at startup time, then
  17. * reuse those resolutions.
  18. */
  19. var keyOf = function (oneKeyObj) {
  20. var key;
  21. for (key in oneKeyObj) {
  22. if (!oneKeyObj.hasOwnProperty(key)) {
  23. continue;
  24. }
  25. return key;
  26. }
  27. return null;
  28. };
  29. module.exports = keyOf;