1.0.4 • Published 4 years ago

sort-helper v1.0.4

Weekly downloads
7
License
ISC
Repository
github
Last release
4 years ago

Sort Helper

npm npm

sort-helper is a micro-library providing some helpers to enhance expressivity when sorting arrays of objects, using the syntax items.sort(by(column, ...otherColumns)), with several way to indicate columns:

  • By key: persons.sort(by('lastName', 'firstName')),
  • By selector: dates.sort(by(x => x.toISOString())),
  • In descending order: [3, 2, 4, 1].sort(by(desc(n => n)))[3, 2, 1, 0],
  • Ignoring case: ['B', 'D', 'c', 'a'].sort(by(ignoreCase(x => x))).join('')'aBcD'.

This library is conceptually similar to thenBy (which I recommend also 👍), with these differences:

  • An approach more functional than object-oriented (see thenBy fluent API),
  • A syntax a bit terser and as much readable.
    • When the pipe operator will be supported, the syntax will feel even more natural for desc and ignoreCase 🎉 : sort(by('releaseDate' |> desc, 'author' |> ignoreCase)).
  • Fully implemented in TypeScript, to benefit from type safety and type expressivity.

☝️ Note : this is a quick implementation, an advanced proof of concept. It may need enhancements regarding edge cases and performance.

1.0.4

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago