denoland / denoland/std

yaml: add option for using Maps instead of objects for mappings

Open
#7,283 1 comment 1 reaction 0 assignees View on GitHub
Dominant language
TypeScript
Stars
3.6k
Forks
681
PR merge metrics
No merged PRs in 30d

Description

**Is your feature request related to a problem? Please describe.**

JS objects are limited to string and symbol keys. If one needs different key types, there's `Map`.

YAML is capable of mappings that have non-string keys. It's a niche use case, sure, but one I have! I'm using number keys to map events that trigger at certain milestones in my data model:

```yaml
milestones:
3: A3
6: D4
9: G3
```

Right now, I have to re-parse the numbers and convert it into a `Map`. An easy one-liner, but unnecessary IMO!

Another ugly use case that I don't personally have, but I guess is valid

I hope one never does this, but...

```yaml
mapping:
2: technically
"2": valid 😔
```

**Describe the solution you'd like**

Add a boolean option to `ParseOptions`, `useMaps`, defaulting to false.

**Describe alternatives you've considered**

Just putting up with converting the objects 🤷

Contributor guide

Open the contributing guide

Research direction

Start at the YAML parser's ParseOptions entry point and trace how mappings are converted into JavaScript objects. Review the existing parser tests for mapping behavior, then add coverage for the useMaps option, including non-string and colliding numeric/string keys; done means the default remains unchanged and enabled parsing produces Maps.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
tooling
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
62/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.