Skip to content

Commit 994b8e7

Browse files
authored
fix: numeric for negative numbers (#291)
1 parent 2aaaece commit 994b8e7

File tree

4 files changed

+9
-1
lines changed

4 files changed

+9
-1
lines changed

src/index.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,8 @@ for (const parser of supportedParsers) {
606606
test(`${parser}: validates a sorted JSON object with a numeric custom sort`, async (t) => {
607607
const fixture = {
608608
first: 'first',
609+
'-100': null,
610+
'-42': null,
609611
0: null,
610612
3: null,
611613
20: null,
@@ -641,11 +643,13 @@ for (const parser of supportedParsers) {
641643
const fixture = {
642644
z: null,
643645
a: null,
646+
'-42': null,
644647
b: null,
645648
0: null,
646649
100: null,
647650
first: 'first',
648651
20: null,
652+
'-100': null,
649653
3: null,
650654
exampleNestedObject: {
651655
z: null,

src/index.test.ts.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,8 @@ Generated by [AVA](https://avajs.dev).
353353
> Snapshot 1
354354
355355
`{␊
356+
"-100": null,␊
357+
"-42": null,␊
356358
"0": null,␊
357359
"3": null,␊
358360
"20": null,␊
@@ -378,6 +380,8 @@ Generated by [AVA](https://avajs.dev).
378380
> Snapshot 1
379381
380382
`{␊
383+
"-100": null,␊
384+
"-42": null,␊
381385
"0": null,␊
382386
"3": null,␊
383387
"20": null,␊

src/index.test.ts.snap

12 Bytes
Binary file not shown.

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ function lexicalSort(a: string, b: string): number {
2929
return 0;
3030
}
3131

32-
const integerPrefixRegex = /^(\d+)/u;
32+
const integerPrefixRegex = /^(-?\d+)/u;
3333

3434
/**
3535
* Numeric sort function for strings, meant to be used as the sort

0 commit comments

Comments
 (0)