@yookue/ts-lang-utils
Version:
Common lang utilities for typescript
16 lines • 491 B
JavaScript
import { toFloat } from "./toFloat";
export function compare(source, target) {
var nullGreater = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
var sourceAlias = toFloat(source),
targetAlias = toFloat(target);
if (sourceAlias === targetAlias) {
return 0;
}
if (sourceAlias === undefined) {
return nullGreater ? 1 : -1;
}
if (targetAlias === undefined) {
return nullGreater ? -1 : 1;
}
return sourceAlias > targetAlias ? 1 : -1;
}