JSPM

exact-order

0.1.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 5
  • Score
    100M100P100Q30255F
  • License MIT

Dead simple module for ordering by an explicit order weighing in at ~1.3KB.

Package Exports

  • exact-order

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (exact-order) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Exact Order

Dead simple module for ordering by an explicit order weighing in at 1.3KB.

💡 Useful for when you have an array of dynamic data, but you need to sort by a set order, rather than a natural sort order, such as alphabetically or numerically.

npm i exact-order --save

Travis   Coveralls   npm   License MIT

Getting Started

Simply pass in either an array or map of the set order. For sorting on multiple properties you're able to pass in a map with multiple keys – with the relevance being from top-to-bottom.

import as from 'exact-order';

// Primitives.
[1, 2, 3].sort(as([2, 1, 3])); // [2, 1, 3]

// Complex nested.
[{ value: 1 }, { value: 2 }, { value: 3 }].sort(as({
    value: [2, 1, 3]
})); // [{ value: 2 }, { value: 1 }, { value: 3 }]