@upyo/core
Version:
Simple email sending library for Node.js, Deno, Bun, and edge functions
25 lines (23 loc) • 789 B
JavaScript
//#region src/priority.ts
/**
* Compares two priority levels and returns a number indicating their
* relative order.
*
* @example Sorting priorities
* ```ts
* import { comparePriority, type Priority } from "@upyo/core/priority";
* const priorities: Priority[] = ["normal", "low", "high"];
* priorities.sort(comparePriority);
* console.log(priorities); // ["high", "normal", "low"]
* ```
*
* @param a The first priority to compare.
* @param b The second priority to compare.
* @return A negative number if `a` is less than `b`, a positive number
* if `a` is greater than `b`, and zero if they are equal.
*/
function comparePriority(a, b) {
return a === b ? 0 : a === "high" ? -1 : b === "high" ? 1 : a === "low" ? 1 : -1;
}
//#endregion
exports.comparePriority = comparePriority;