Compare and equate values in JavaScript, with .NET style comparison functions you can build from object keys.
npm install @tsdotnet/compareimport { compare, comparison } from '@tsdotnet/compare';
compare(1, 2); // -1
compare('b', 'a'); // 1
type Person = { name: string; age: number };
declare const people: Person[];
people.sort(comparison.fromKeys<Person>(['age', 'name'])); // by age, then namecompare uses a compareTo method when an object has one. areEqual and areEquivalent do equality checks that treat NaN as equal to itself.
ESM (import { compare, comparison } from '@tsdotnet/compare';) or CommonJS (const { compare, comparison } = require('@tsdotnet/compare');).
In a browser, without a bundler
<script src="https://cdn.jsdelivr.net/npm/@tsdotnet/type@1/dist/umd/type.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@tsdotnet/compare@1/dist/umd/compare.min.js"></script>
<script>
const { compare, comparison } = tsdotnet.compare;
</script>