diff --git a/CHANGELOG.md b/CHANGELOG.md index 9801d3f..0c16e2a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## v2.4.3 + +- Fixed replacer function receiving array keys as number instead of string + ## v2.4.2 - Improved ESM TypeScript types. diff --git a/index.js b/index.js index 36a1dc8..bd2aa1d 100644 --- a/index.js +++ b/index.js @@ -266,11 +266,11 @@ function configure (options) { const maximumValuesToStringify = Math.min(value.length, maximumBreadth) let i = 0 for (; i < maximumValuesToStringify - 1; i++) { - const tmp = stringifyFnReplacer(i, value, stack, replacer, spacer, indentation) + const tmp = stringifyFnReplacer(String(i), value, stack, replacer, spacer, indentation) res += tmp !== undefined ? tmp : 'null' res += join } - const tmp = stringifyFnReplacer(i, value, stack, replacer, spacer, indentation) + const tmp = stringifyFnReplacer(String(i), value, stack, replacer, spacer, indentation) res += tmp !== undefined ? tmp : 'null' if (value.length - 1 > maximumBreadth) { const removedKeys = value.length - maximumBreadth - 1 diff --git a/test.js b/test.js index f8e4f95..1321c3c 100644 --- a/test.js +++ b/test.js @@ -317,6 +317,7 @@ test('replacer removing elements and indentation', function (assert) { test('replacer removing all elements', function (assert) { const replacer = function (k, v) { + assert.type(k, 'string') if (k !== '') return return k }