Skip to content

Keep-sorted Feature Enhancement (Map and Array) #33

Open
@wll8

Description

@wll8

Clear and concise description of the problem

Add sorting for items in Map and Array.

Suggested solution

Support for Strings in Arrays

If there is support for objects in arrays, I believe it is also necessary to support strings in arrays.

Before implementation

// @keep-sorted
const arr = [
  `b`,
  `a`,
  `c`,
]

After implementation

// @keep-sorted
const arr = [
  `a`,
  `b`,
  `c`,
]

Currently, I can only use it like this

// @keep-sorted
const arr = objToArr({
  b: true,
  a: true,
  c: true,
})

Support for Map

Before

// @keep-sorted
const map = new Map([
  [`c`, `cc`],
  [`a`, `aa`],
])

After

// @keep-sorted
const map = new Map([
  [`a`, `aa`],
  [`c`, `cc`],
])

Adjust Sorting Rules

Expect the order a before a.b, rather than after, using ASCII ascending order.

Current Sorting

// @keep-sorted
const obj = {
  'a.1': true,
  'a': true,
  'b': true,
  'c': true,
}

Expected Sorting

// @keep-sorted
const obj = {
  'a': true,
  'a.1': true,
  'a.2': true,
  'b': true,
  'c': true,
}

If it conflicts with the currently implemented sorting method, could sorting be supported as a parameter?

Alternative

No response

Additional context

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions