keyOf.js 974 B

1234567891011121314151617181920212223242526272829303132
  1. "use strict";
  2. /**
  3. * Copyright (c) 2013-present, Facebook, Inc.
  4. *
  5. * This source code is licensed under the MIT license found in the
  6. * LICENSE file in the root directory of this source tree.
  7. *
  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 keyOf(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;