pub repository
mirror.p-hatan.comyaml_edit
2.2.4A library for YAML manipulation with comment and whitespace preservation.
Readme
Dart CI pub package package publisher Coverage Status
A library for YAML manipulation while preserving comments.
Usage
A simple usage example:
import 'package:yaml_edit/yaml_edit.dart';
void main() {
final yamlEditor = YamlEditor('{YAML: YAML}');
yamlEditor.update(['YAML'], "YAML Ain't Markup Language");
print(yamlEditor);
// Expected output:
// {YAML: YAML Ain't Markup Language}
}
Example: Converting JSON to YAML (block formatted)
void main() {
final jsonString = r'''
{
"key": "value",
"list": [
"first",
"second",
"last entry in the list"
],
"map": {
"multiline": "this is a fairly long string with\nline breaks..."
}
}
''';
final jsonValue = json.decode(jsonString);
// Convert jsonValue to YAML
final yamlEditor = YamlEditor('');
yamlEditor.update([], jsonValue);
print(yamlEditor.toString());
}
Testing
Testing is done in two strategies: Unit testing (/test/editor_test.dart) and
Golden testing (/test/golden_test.dart). More information on Golden testing
and the input/output format can be found at /test/testdata/README.md.
These tests are automatically run with pub run test.
Limitations
- Users are not allowed to define tags in the modifications.
- Map keys will always be added in the flow style.
Changelog
2.2.4
- Removes comments associated with a node when
removeis called.-
v2.2.3and earlier.## Before edit --- key: value # These # dangling # should be # removed. # Safe next: - value # These # should be # removed. # Safe - next# After edit: # 1. YamlEditor.remove(['key']) # 2. YamlEditor.remove(['next', 0]) --- # dangling # should be # removed. # Ignored next: # should be # removed. # Safe - next -
v2.2.4and later (same string as above)# After edit: # 1. YamlEditor.remove(['key']) # 2. YamlEditor.remove(['next', 0]) --- # Ignored next: # Safe - next
-
2.2.3
- Fix alphabetical ordering when inserting into a single-element maps. (#2258)
2.2.2
-
Suppress warnings previously printed to
stdoutwhen parsing YAML internally. -
Fix error thrown when inserting duplicate keys to different maps in the same list. (#69)
-
Fix error thrown when inserting in nested list using
spliceListmethod (#83) -
Fix error thrown when string has spaces when applying
ScalarStyle.FOLDED. (#41). Resolves ([#86]). -
Require Dart 3.1
-
Move to
dart-lang/toolsmonorepo.
2.2.1
- Require Dart 3.0
- Fix removal of last key in blockmap when key has no value (#55).
2.2.0
-
Fix inconsistent line endings when inserting maps into a document using
\r\n. (#65) -
AliasErroris changed toAliasExceptionand exposed in the public API.All node-mutating methods on
YamlEditor, i.e.update(),appendToList(),prependToList(),insertIntoList(),spliceList(),remove()will now throw an exception instead of an error when encountering an alias on the path to modify.This allows catching and handling when this is happening.
2.1.1
- Require Dart 2.19
2.1.0
- Breaking
wrapAsYamlNode(value, collectionStyle, scalarStyle)will applycollectionStyleandscalarStylerecursively when wrapping a children ofMapandList. While this may change the style of the YAML documents written by applications that rely on the old behavior, such YAML documents should still be valid. Hence, we hope it is reasonable to make this change in a minor release. - Fix for cases that can't be encoded correctly with
scalarStyle: ScalarStyle.SINGLE_QUOTED. - Fix YamlEditor
appendToListandinsertIntoListfunctions inserts new item into next yaml item rather than at end of list. (#23)
2.0.3
- Updated the value of the pubspec
repositoryfield.
2.0.2
- Fix trailing whitespace after adding new key with block-value to map (#15).
- Updated
repositoryand other meta-data inpubspec.yaml.
2.0.1
- License changed to BSD, as this package is now maintained by the Dart team.
- Fixed minor lints.
2.0.0
- Migrated to null-safety.
- API will no-longer return
nullin-place of aYamlNode, instead aYamlNodewithYamlNode.value == nullshould be used. These are easily created withwrapAsYamlNode(null).
1.0.3
- Fixed bug in adding an empty map as a map value.
1.0.2
- Throws an error if the final YAML after edit is not parsable.
- Fixed bug in adding to empty map values, when it is followed by other content.
1.0.1
- Updated behavior surrounding list and map removal.
- Fixed bug in dealing with empty values.
1.0.0
- Initial release.
Installing
export PUB_HOSTED_URL=https://pub.mirror.p-hatan.com
flutter pub add yaml_editpubspec.yaml
name: yaml_edit
version: 2.2.4
description: >-
A library for YAML manipulation with comment and whitespace preservation.
repository: https://github.com/dart-lang/tools/tree/main/pkgs/yaml_edit
issue_tracker: https://github.com/dart-lang/tools/labels/package%3Ayaml_edit
topics:
- yaml
environment:
sdk: ^3.1.0
dependencies:
collection: ^1.15.0
meta: ^1.7.0
source_span: ^1.8.1
yaml: ^3.1.0
dev_dependencies:
coverage: any # we only need format_coverage, don't care what version
dart_flutter_team_lints: ^3.0.0
path: ^1.8.0
test: ^1.17.12
Version history
| Version | Published | Archive | SHA-256 |
|---|---|---|---|
| 1.0.0 | 2020-08-07T19:37:14.080145Z | Download | 7aded93a7902a8e393c3fd460a1ddab581e4d48f846721021564339aff6f9813 |
| 1.0.1 | 2020-08-25T13:05:50.554054Z | Download | 4d962e6e7734966800e4f51e59c8a0870f7742b6c58c7293805cd16c9685d39f |
| 1.0.2 | 2020-09-01T07:47:08.546240Z | Download | b48347839593c0f4d5d9ceaa9f4283ead38b4e62a9d88bcc68feb4f81bcfc013 |
| 1.0.3 | 2020-11-02T13:14:30.871551Z | Download | 384dba0fd40414893814b15c716a63e154c208d85d1501cee73b003520cc189f |
| 2.0.0 | 2021-04-28T10:44:04.976225Z | Download | 9cffdaf877d5cedfd2d1b12d060bd8dc8a8987af3817f2c1bfbafb7c5b5f5cfe |
| 2.0.1 | 2021-09-27T10:51:34.715543Z | Download | fe1124241eb38f41246dced57c847240ea63a02d42c7eae40cbb6dd05265d22f |
| 2.0.2 | 2022-03-17T11:36:22.146801Z | Download | 2caa94e8c10f2d15dace3d6c100aec8dc44865da068b9a1ad259fa88e24147bb |
| 2.0.3 | 2022-05-12T16:14:13.068110Z | Download | 4240d1b19841b8af5786121e4e357735cc2a8ffb19176bff5769d73c34e2a8a5 |
| 2.1.0 | 2023-03-02T11:41:29.108154Z | Download | 0b968021754d8fbd3e9c83563b538ee417d88b2cc587606da5615546b7ee033b |
| 2.1.1 | 2023-05-02T12:04:10.475895Z | Download | 1579d4a0340a83cf9e4d580ea51a16329c916973bffd5bd4b45e911b25d46bfd |
| 2.2.0 | 2024-02-21T16:32:24.965116Z | Download | c566f4f804215d84a7a2c377667f546c6033d5b34b4f9e60dfb09d17c4e97826 |
| 2.2.1 | 2024-05-02T13:43:43.549522Z | Download | e9c1a3543d2da0db3e90270dbb1e4eebc985ee5e3ffe468d83224472b2194a5f |
| 2.2.2 | 2024-12-20T13:48:08.944899Z | Download | fb38626579fb345ad00e674e2af3a5c9b0cc4b9bfb8fd7f7ff322c7c9e62aef5 |
| 2.2.3 | 2025-12-02T08:48:07.674594Z | Download | ec709065bb2c911b336853b67f3732dd13e0336bd065cc2f1061d7610ddf45e3 |
| 2.2.4 | 2026-02-13T07:12:23.296061Z | Download | 07c9e63ba42519745182b88ca12264a7ba2484d8239958778dfe4d44fe760488 |
Dependencies
collection "^1.15.0"
meta "^1.7.0"
source_span "^1.8.1"
yaml "^3.1.0"