Skip to content

Wrong info with maximumBreadth and arrays #60

@yvele

Description

@yvele

I noticed that maximumBreadth behaves correctly for objects, but not for arrays.

For objects, everything works as expected:

const stringify = configure({ maximumBreadth: 2 });

stringify({ 1:1, 2:2, 3:3 });
// ✅ '{"1":1,"2":2,"...":"1 item not stringified"}'

But with arrays, the behavior is inconsistent:

const stringify = configure({ maximumBreadth: 2 });

stringify([1, 2]);
// ✅ '[1,2]'

stringify([1, 2, 3]);
// ❌ '[1,2]'
//    - missing info that 1 item was not stringified

stringify([1, 2, 3, 4]);
// ❌ '[1,2,"... 1 item not stringified"]'
//    - count is wrong (should be `"… 2 items not stringified"`)

This results in missing information and an incorrect ellipsis element.

I made a PR with a fix:

Let me know if you want adjustments or extra tests.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions