Files
node-factorio-recipes/src/utils.ts
Sebastian Seedorf 940149cec8 First working version
2022-08-08 23:12:11 +02:00

13 lines
351 B
TypeScript

export function isNonNullable<T>(any: T): any is NonNullable<T> {
return any !== undefined && any !== null
}
export function sortByProperty<T>(transform: (val: T) => number | string): (a: T, b: T) => number {
return (a, b) => {
const a2 = transform(a)
const b2 = transform(b)
if (a2 > b2) return 1
return a2 === b2 ? 0 : -1
}
}