Hand Range Notation
Convert poker hand range notation to and from actual poker hands.
Installation
Add @poker-apprentice/hand-range-notation
as a dependency.
Usage
expandNotation
This function is used to parse a string representing a hand range notation. If a hand range notation cannot be parsed, it will throw an InvalidHandRangeNotationError
.
const hands = expandNotation('AKs');
console.log(hands);
const hands = expandNotation('AKo');
console.log(hands);
const hands = expandNotation('AK');
console.log(hands);
const hands = expandNotation('AcKd');
console.log(hands);
const hands = expandNotation('TT');
console.log(hands);
const hands = expandNotation('AKs-A2s');
const hands = expandNotation('KQo-KJo');
const hands = expandNotation('AK-AT');
const hands = expandNotation('99-22');
const hands = expandNotation('AT+');
const hands = expandNotation('ATs+');
const hands = expandNotation('TT+');
const hands = expandNotation('ATs+, 99-22, AA, KQ, KJs, AcTd');
notate
This function is used to generate a hand range notation string representing a collection of hands.
Only two-card Texas Hold'em hands are supported. Providing hands of any other length will result in an InvalidHandError
being thrown.
const notation = notate([
['As', 'Ks'],
['Ah', 'Kh'],
['Ad', 'Kd'],
['Ac', 'Kc'],
['As', 'Qs'],
['Ah', 'Qh'],
['Ad', 'Qd'],
['Ac', 'Qc'],
['Js', 'Jh'],
['Js', 'Jd'],
['Js', 'Jc'],
['Jh', 'Jd'],
['Jh', 'Jc'],
['Jd', 'Jc'],
['Ts', 'Th'],
['Ts', 'Td'],
['Ts', 'Tc'],
['Th', 'Td'],
['Th', 'Tc'],
['Td', 'Tc'],
]);
console.log(notation);
normalizeNotation
This function converts the provided notation into a predictable/deterministic format.
const notation = normalizeNotation('AKs,TT,QAo,AA'));
console.log(notation);
const hands = expandNotation('7d2c,3h2s,KQo,AQo,AKo,ATs+,TT+,A2s-A5s');
const notation = notate(hands);
console.log(notation);