_toKey.js 523B

12345678910111213141516171819202122
  1. var isSymbol = require('./isSymbol');
  2. /** Used as references for various `Number` constants. */
  3. var INFINITY = 1 / 0;
  4. /**
  5. * Converts `value` to a string key if it's not a string or symbol.
  6. *
  7. * @private
  8. * @param {*} value The value to inspect.
  9. * @returns {string|symbol} Returns the key.
  10. */
  11. function toKey(value) {
  12. if (typeof value == 'string' || isSymbol(value)) {
  13. return value;
  14. }
  15. var result = (value + '');
  16. return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
  17. }
  18. module.exports = toKey;