toKey.js 546 B

12345678910111213141516171819
  1. // @ts-nocheck
  2. import isSymbol from "./isSymbol.js";
  3. /** Used as references for various `Number` constants. */
  4. const INFINITY = 1 / 0;
  5. /**
  6. * Converts `value` to a string key if it's not a string or symbol.
  7. *
  8. * @private
  9. * @param {*} value The value to inspect.
  10. * @returns {string|symbol} Returns the key.
  11. */
  12. function toKey(value) {
  13. if (typeof value === "string" || isSymbol(value)) {
  14. return value;
  15. }
  16. const result = `${value}`;
  17. return result === "0" && 1 / value === -INFINITY ? "-0" : result;
  18. }
  19. export default toKey;