yaml_writer

v2.1.0

A library to write YAML documents, supporting Object encoding and 'dart:convert' 'Converter'.

Package archive: https://pubdev.letsnova.ru/api/archives/yaml_writer/2.1.0.tar.gz

Installdart pub add yaml_writer

Readme

yaml_writer

pub package Null Safety Codecov Dart CI GitHub Tag New Commits Last Commits Pull Requests Code size License

A library to write YAML documents, supporting Object encoding and dart:convert Converter.

Usage

A simple usage example:

import 'package:yaml_writer/yaml_writer.dart';
                
                void main() {
                  final yamlWriter = YamlWriter();
                
                  final yamlDoc = yamlWriter.write({
                    'name': 'Joe',
                    'ids': [10, 20, 30],
                    'desc': 'This is\na multiline\ntext',
                    'enabled': true,
                  });
                
                  print(yamlDoc);
                }
                

OUTPUT:

name: 'Joe'
                ids: 
                  - 10
                  - 20
                  - 30
                desc: |-
                    This is
                    a multiline
                    text
                enabled: true
                

YAML Strings

The writer will try to encode strings using the best format depending on the text, avoiding to escape " and using | for multiline texts.

Encoding Objects

You can use YAMLWriter.toEncodable to convert an Object to an encodable version, similar to what is done by dart:convert JsonEncoder.

If YAMLWriter.toEncodable is not set, it will try to call toJson().

Features and bugs

Please file feature requests and bugs at the issue tracker.

Author

Graciliano M. Passos: gmpassos@GitHub.

Liplum: liplum@GitHub

License

Dart free & open-source license.

Changelog

2.1.0

  • Refactored string quoting: enhanced the handling of unquoted strings.
  • Resolved an issue where empty strings were not supported when using unquoted strings.
  • Introduced YamlWriter.config() as a new constructor, along with the YamlWriterConfig class.

2.0.1

  • Remove unnecessary trailing spaces from keys with values declared on a new line.

  • test: ^1.25.8

  • coverage: ^1.10.0

2.0.0

# BEFORE:
                field:
                  - 
                    - 5
                    - 2
                  - 
                    a: 3
                    b: 6
                
                # AFTER:
                field:
                  - - 5
                    - 2
                  - a: 3
                    b: 6
                
  • Update min Dart SDK version constraint from 2.12.0 to 3.0.0
  • Update lints: ^2.0.1 to lints: ^3.0.0

BREAKING CHANGES:

  • YAMLWriter renamed to YamlWriter (Effective Dart reference).
  • Deprecated identSize property is removed. Use indentSize instead.
  • toEncodable property is removed. Use constructor parameter instead (YamlWriter#toEncodable).

1.0.3

  • YAMLWriter:
    • Added allowUnquotedStrings.
    • Rename identSize to indentSize.
    • Deprecate identSize field.
  • lints: ^2.0.1
  • test: ^1.22.0
  • dependency_validator: ^3.2.2
  • coverage: ^1.6.1

1.0.2

  • Fixed serialization of an empty List to []
  • Updated GitHub CI.
  • lints: ^2.0.0
  • test: ^1.17.12
  • dependency_validator: ^3.2.0
  • coverage: ^1.1.0

1.0.1

  • Improve pubspec.yaml description.
  • Improve README.

1.0.0

  • Initial version.