-
-
Notifications
You must be signed in to change notification settings - Fork 772
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
Support option to keep comments from YAML input #689
Comments
You might want to try https://github.com/eemeli/yaml instead |
Thanks for the hint! 👍 Using "yaml" worked: import {ParsedNode, parseDocument, YAMLMap, YAMLSeq} from 'yaml';
function sortDeep(node: ParsedNode | null): void {
if (node instanceof YAMLMap) {
node.items.sort((itemA, itemB) => (itemA.key < itemB.key ? -1 : itemA.key > itemB.key ? 1 : 0));
node.items.forEach(item => sortDeep(item.value));
} else if (node instanceof YAMLSeq) {
node.items.forEach(item => sortDeep(item));
}
}
const document = parseDocument(yamlString);
sortDeep(document.contents);
console.log(document.toString()); |
any update on this issue? as a basic library, "yaml" has more requirements, like: eemeli/yaml#394, it should be compatible with lower node or webpack version. |
7 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It was brought to my attention that "js-yaml" removes comments from sorted YAML code. I created a little snippet which proves that: https://runkit.com/bennyn/js-yaml-comment
Output:
Is there the possibility to add an option to protect comments?
The text was updated successfully, but these errors were encountered: