Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/shaggy-bars-hear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'devalue': patch
---

fix: correctly differentiate between +0 and -0
4 changes: 2 additions & 2 deletions src/stringify.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ export function stringify(value, reducers) {
throw new DevalueError(`Cannot stringify a function`, keys);
}

if (indexes.has(thing)) return indexes.get(thing);

if (thing === undefined) return UNDEFINED;
if (Number.isNaN(thing)) return NAN;
if (thing === Infinity) return POSITIVE_INFINITY;
if (thing === -Infinity) return NEGATIVE_INFINITY;
if (thing === 0 && 1 / thing < 0) return NEGATIVE_ZERO;

if (indexes.has(thing)) return indexes.get(thing);

const index = p++;
indexes.set(thing, index);

Expand Down
6 changes: 6 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,12 @@ const fixtures = {
js: '["a","b","c"]',
json: '[[1,2,3],"a","b","c"]'
},
{
name: 'Array where negative zero appears after normal zero',
value: [0, -0],
js: '[0,-0]',
json: '[[1,-6],0]'
},
{
name: 'Array (empty)',
value: [],
Expand Down