parser-ts icon indicating copy to clipboard operation
parser-ts copied to clipboard

Add hexDigit combinator

Open rhoskal opened this issue 2 years ago • 0 comments

🚀 Feature request

Current Behavior

Currently there is no hexadecimal digit combinator available in parser-ts/char.

Desired Behavior

The "core" library export a hexDigit combinator since it's quite common e.g. Haskell and Purescript

Suggested Solution

const isHexDigit: (c: Char) => boolean = (c) =>
  "0123456789abcdef".indexOf(c.toLowerCase()) !== -1;

const hexDigit: P.Parser<Char, Char> = P.expected(P.sat(isHexDigit), "a hex digit");

Who does this impact? Who is this for?

All users, regardless of skill would benefit from this. Not dependant on TS version.

Describe alternatives you've considered

It's easy enough to build this yourself and put into your own codebase. I've done so while attempting to port over my own uuid and mac address parsers written in Purescript.

Additional context

Your environment

Software Version(s)
fp-ts 2.16.1
parser-ts 0.7.0
TypeScript 5.2.2

rhoskal avatar Oct 06 '23 16:10 rhoskal