gcanti / gcanti/parser-ts

Add hexDigit combinator

Open
#63 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
196
Forks
19
PR merge metrics
No merged PRs in 30d

Description

## 🚀 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](https://hackage.haskell.org/package/parsec-3.1.17.0/docs/src/Text.Parsec.Char.html#hexDigit) and [Purescript](https://github.com/purescript-contrib/purescript-parsing/blob/v10.0.0/src/Parsing/String/Basic.purs#L58-L58)

### Suggested Solution

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

const hexDigit: P.Parser = 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 |

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in the parser-ts/char module, where character combinators are exported, and inspect nearby combinator tests if present. Compare the suggested isHexDigit and hexDigit behavior with existing character parsers. Done means the core library exports hexDigit, accepts 0-9 and a-f case-insensitively, rejects other characters, and has coverage for that behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers
Issue type
Feature
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.