Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: When sorting object with Date, Set (JS objects) they are vanished #222

Open
sebslon opened this issue Apr 22, 2024 · 0 comments · May be fixed by #223
Open

[BUG]: When sorting object with Date, Set (JS objects) they are vanished #222

sebslon opened this issue Apr 22, 2024 · 0 comments · May be fixed by #223

Comments

@sebslon
Copy link

sebslon commented Apr 22, 2024

Hey, I've spotted that when you use sorting on object which has values like Date, Set etc. they are vanished (they are set to {} - empty object)

Simple reproduction

const obj = {
  a: 1,
  b: 2,
  c: new Date(),
  d: [
    {
      a: 1,
      c: 3,
      b: 2,
      z: 26,
      set: new Set([1, 2, 3]),
      date: {
        from: new Date(),
        to: new Date(),
      },
    },
  ],
}

const sortedObj = sortObject(obj);

result:

{
  "a": 1,
  "b": 2,
  "c": {},
  "d": [
    {
      "a": 1,
      "b": 2,
      "c": 3,
      "date": {
        "from": {},
        "to": {}
      },
      "set": {},
      "z": 26
    }
  ]
}

expected result:

{
  a: 1,
  b: 2,
  c: 2024-04-22T15:13:16.020Z,
  d: [
    {
      a: 1,
      b: 2,
      c: 3,
      date: { from: 2024-04-22T15:13:16.020Z, to: 2024-04-22T15:13:16.020Z },
      set: Set(3) { 1, 2, 3 },
      z: 26
    }
  ]
}

I'm not sure if this is a bug or feature but I'll open a PR soon for this and leave it up to you to decide whether to merge this :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant