Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a new createNode option aliasDuplicateObjects #299

Merged
merged 2 commits into from
Aug 27, 2021
Merged

Conversation

eemeli
Copy link
Owner

@eemeli eemeli commented Aug 12, 2021

Fixes #296, originally reported in #211

This adds an option aliasDuplicateObjects (default true) that does this:

const foo = { foo: 'FOO' }

const doc1 = new YAML.Document([foo, foo])
const doc2 = new YAML.Document([foo, foo], { aliasDuplicateObjects: false })

`${doc1}
---
${doc2}`
- &a1
  foo: FOO
- *a1

---
- foo: FOO
- foo: FOO

Ping @ChocolateLoverRaj, @ushuz, @dudif91. This would presumably work for you?

Copy link

@ushuz ushuz left a comment

Choose a reason for hiding this comment

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

Thank you for addressing #211

| tag | `string` | | Specify the top-level collection type, e.g. `"!!omap"`. Note that this requires the corresponding tag to be available in this document's schema. |
| Name | Type | Default | Description |
| --------------------- | --------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |
| aliasDuplicateObjects | `boolean` | `true` | During node construction, use anchors and aliases to keep strictly equal non-null objects as equivalent in YAML. |
Copy link

Choose a reason for hiding this comment

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

aliasDupplicateObjects feels too implementation-focus. I would prefer something like anchors proposed by #211, which will sit well with anchorPrefix below and is easier for users to understand IMO.

@ChocolateLoverRaj
Copy link

@eemeli whatever the option is called, it works for me.

@eemeli eemeli merged commit 49753a0 into master Aug 27, 2021
@eemeli eemeli deleted the optional-aliases branch August 27, 2021 13:04
@derolf
Copy link

derolf commented Sep 19, 2021

When will it be released?

@eemeli
Copy link
Owner Author

eemeli commented Sep 19, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add option to disable anchors in stringify
4 participants