Skip to content

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

@sebslon

Description

@sebslon

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 :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions