Skip to content

feat(yaml/unstable): allow to add custom types for parse and stringify#6841

Merged
kt3k merged 2 commits intodenoland:mainfrom
lumeland:main
Oct 7, 2025
Merged

feat(yaml/unstable): allow to add custom types for parse and stringify#6841
kt3k merged 2 commits intodenoland:mainfrom
lumeland:main

Conversation

@oscarotero
Copy link
Copy Markdown
Contributor

@oscarotero oscarotero commented Oct 5, 2025

This change introduce a new option to add custom types for parse and stringify functions of YAML, which can fix #5680.

For example:

import { parse, type ImplicitType } from "@std/yaml";

const smile: ImplicitType = {
  tag: "tag:custom:smile",
  resolve: (data): boolean => data === "=)",
  construct: (): string => "🙂",
  predicate: (data): data is string => data === "🙂",
  kind: "scalar",
  represent: (): string => "=)",
};

const yaml = `
title: =)
tags:
  - =)
  - bar
`

const result = parse(yaml, { extraTypes: [ smile ] }
console.assert(result.title === "🙂");

@oscarotero oscarotero requested a review from kt3k as a code owner October 5, 2025 23:26
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Oct 5, 2025

CLA assistant check
All committers have signed the CLA.

@github-actions github-actions Bot added the yaml label Oct 5, 2025
@oscarotero oscarotero changed the title YAML: Allow to add custom types for parse and stringify feat(yaml) Allow to add custom types for parse and stringify Oct 5, 2025
@codecov
Copy link
Copy Markdown

codecov Bot commented Oct 5, 2025

Codecov Report

❌ Patch coverage is 70.00000% with 15 lines in your changes missing coverage. Please review.
✅ Project coverage is 94.11%. Comparing base (b58b295) to head (73da044).
⚠️ Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
yaml/unstable_parse.ts 58.33% 15 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6841      +/-   ##
==========================================
- Coverage   94.18%   94.11%   -0.07%     
==========================================
  Files         575      578       +3     
  Lines       42446    42604     +158     
  Branches     6742     6775      +33     
==========================================
+ Hits        39977    40098     +121     
- Misses       2419     2455      +36     
- Partials       50       51       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@kt3k
Copy link
Copy Markdown
Contributor

kt3k commented Oct 6, 2025

We have policy of accepting new feature as unstable first https://github.com/denoland/std/blob/main/.github/CONTRIBUTING.md#new-features-in-stable-packages-version--100

Can you copy parse.ts to unstable_parse.ts and make these changes to there? (Also map ./unstable-parse to ./unstable_parse.ts, that enables users to import it via jsr:@std/yaml/unstable-parse

@oscarotero oscarotero changed the title feat(yaml) Allow to add custom types for parse and stringify feat(yaml/unstable) Allow to add custom types for parse and stringify Oct 6, 2025
@oscarotero
Copy link
Copy Markdown
Contributor Author

@kt3k I moved everything to the unstable files (the unstable_stringify.ts already existed so I just had to create unstable_parse.ts) and all lint issues caused by private types are fixed. The only thing Ieft is the PR title, but I have no idea how to fix it.

@kt3k kt3k changed the title feat(yaml/unstable) Allow to add custom types for parse and stringify feat(yaml/unstable): allow to add custom types for parse and stringify Oct 7, 2025
Copy link
Copy Markdown
Contributor

@kt3k kt3k left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Comment thread yaml/_type.ts
export type RepresentFn<D> = (data: D, style?: StyleVariant) => string;

/**
* A type definition for a YAML node.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for documenting this!

@kt3k kt3k merged commit dca626c into denoland:main Oct 7, 2025
19 of 21 checks passed
@devingfx
Copy link
Copy Markdown

devingfx commented Nov 5, 2025

Why create a whole copy of each modules just to re-export stuff? instead of just make the module _schema.ts public...

Let people access this schema module and they can even hack the original schemas... (Just needs a "At your own risk" notice).

I feel this PR a bit overkill for initial goal ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

YAML: Allow to store dates without time

4 participants