Yaml Magic | Coderz Product

yaml_magic

Last updated:

0 purchases

yaml_magic Image
yaml_magic Images

Free

Languages

Categories

Add to Cart

Description:

yaml magic

YamlMagic #

YamlMagic is a Dart & Flutter package that provides utilities for working with YAML files. It allows you to load, modify (edit and manipulate), and save YAML files seamlessly.
Features #

Convert a Dart Map object into a YAML document as a String.
Load YAML files and access their key-value pairs.
Add or update key-value pairs in the YAML document.
Save the changes made to the YAML file.

Installation #
Add the following dependency to your pubspec.yaml file:
dependencies:
yaml_magic: ^1.0.5
copied to clipboard
Usage #
Import the yaml_magic package in your Dart file:
import 'package:yaml_magic/yaml_magic.dart';
copied to clipboard
Loading a YAML File #
To load a YAML file, use the load method of the YamlMagic class:
final yamlMagic = YamlMagic.load('path/to/file.yaml');
copied to clipboard
Accessing Values #
You can access the values in the YAML document using the index operator ([]). The key path in the YAML document is provided as the index:
var value = yamlMagic['key'];
copied to clipboard
Modifying Values #
To add or update a value in the YAML document, use the index operator ([]=):
yamlMagic['new_key'] = 'new_value';
copied to clipboard
Adding Comments #
Two ways to add comments to your YAML document using the addComment method or by nesting a YamlComment object within a key-value pair.
yamlMagic.addComment(YamlComment('Comment text content here!'));
// or
yamlMagic['new_key'] = {
...YamlComment('Comment text content here!').toMap(),
'foo': 'bar',
};
copied to clipboard
Adding Break Lines #
Two ways to add break lines to your YAML document using the addBreakLine method or by nesting a YamlBreakLine object within a key-value pair.
yamlMagic.addBreakLine(YamlBreakLine(count: 1));
// or
yamlMagic['new_key'] = {
...YamlBreakLine(count: 1).toMap(),
'foo': 'bar',
};
copied to clipboard
Saving Changes #
To save the changes made to the YAML document, use the save method:
await yamlMagic.save();
copied to clipboard
Example #
Here's a simple example that demonstrates the basic usage of the YamlMagic package:
import 'package:yaml_magic/yaml_magic.dart';

void main() async {
final yamlMagic = YamlMagic.load('path/to/file.yaml');
yamlMagic['new_key'] = 'new_value';
await yamlMagic.save();
}
copied to clipboard
Author #
itisnajim, itisnajim@gmail.com
License #
YamlMagic is available under the MIT license. See the LICENSE file for more info.

License:

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product: (if this is empty don't purchase this product)

Customer Reviews

There are no reviews.