is-kit

equals

Value equality with Object.is semantics; suitable for precise comparisons.

import { equals } from 'is-kit';
// Object.is semantics are preserved
equals(NaN)(NaN); // true
// Literal guards narrow discriminated unions
const isDone = equals('done' as const);
// isDone: (value: unknown) => value is 'done'
type Status = 'draft' | 'in-progress' | 'done';
function isFinished(status: Status) {
if (isDone(status)) {
// Narrowed to the literal type 'done' inside this branch
return true;
}
return false;
}
isFinished('draft'); // false
isFinished('done'); // true

equalsBy / equalsKey

Compare by derived values or by property keys when building guards.

import { equalsBy, equalsKey, isString } from 'is-kit';
// Build a comparator in two steps for clarity
const lengthOfString = equalsBy(isString)((s) => s.length);
const isLength3 = lengthOfString(3 as const);
isLength3('foo'); // true
// Key-based equality guard
const hasId1 = equalsKey('id', 1 as const);
hasId1({ id: 1 }); // true