Skip to content

Commit

Permalink
feat(rails-status): add JSDoc (#679)
Browse files Browse the repository at this point in the history
  • Loading branch information
mxdvl authored Nov 27, 2023
1 parent 76b278d commit 063f781
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/rails-status.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/** Status order: later elements have higher precedence. */
const statusOrder = [
'deprecated',
'experimental',
Expand All @@ -6,6 +7,12 @@ const statusOrder = [
'stable'
]

/**
* Get the latest status, based on the order of precedence
*
* @param {readonly string[]} statuses list of status to pick from
* @returns {string | null} latest status if valid, `null` otherwise
*/
export const latestStatusFrom = (statuses) => {
let highestRank = -1
let latestStatus = null
Expand All @@ -22,6 +29,13 @@ export const latestStatusFrom = (statuses) => {
return latestStatus
}

/**
* Compare function, which is compatible with #Array.sort.
*
* @param {string} first
* @param {string} second
* @returns {1 | 0 | -1} sorting order
*/
export const compareStatuses = (first, second) => {
const firstRank = statusOrder.indexOf(first)
const secondRank = statusOrder.indexOf(second)
Expand Down

0 comments on commit 063f781

Please sign in to comment.