diff --git a/invert.js b/invert.js index 3cb243054..1078a2534 100644 --- a/invert.js +++ b/invert.js @@ -1,3 +1,5 @@ +const toString = Object.prototype.toString + /** * Creates an object composed of the inverted keys and values of `object`. * If `object` contains duplicate values, subsequent values overwrite @@ -17,6 +19,9 @@ function invert(object) { const result = {} Object.keys(object).forEach((value, key) => { + if (value != null && typeof value.toString != 'function') { + value = toString.call(value) + } result[value] = key }) return result