diff --git a/CHANGELOG.md b/CHANGELOG.md index ac07159..eff3b9e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,3 @@ -## [0.0.1] - TODO: Add release date. +## [1.0.0] - Initial release -* TODO: Describe initial release. +* Initial release supporting pubspec.yaml and pubspec.lock formatting styles diff --git a/README.md b/README.md index 57caeac..caabbe7 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,60 @@ -# json2yaml +# json2yaml [![Build Status](https://travis-ci.org/alexei-sintotski/json2yaml.svg?branch=master)](https://travis-ci.org/alexei-sintotski/json2yaml) [![codecov](https://codecov.io/gh/alexei-sintotski/json2yaml/branch/master/graph/badge.svg)](https://codecov.io/gh/alexei-sintotski/json2yaml) [![pubspec_lock version](https://img.shields.io/pub/v/json2yaml?label=json2yaml)](https://pub.dev/packages/json2yaml) Dart package to render JSON data to YAML + +## json2yaml() + +json2yaml is function called to format Json as Yaml. + +``` + const developerData = { + 'name': "Martin D'vloper", + 'job': 'Developer', + 'skill': 'Elite', + 'employed': true, + 'foods': ['Apple', 'Orange', 'Strawberry', 'Mango'], + 'languages': { + 'perl': 'Elite', + 'python': 'Elite', + 'pascal': 'Lame', + }, + 'education': '4 GCSEs\n3 A-Levels\nBSc in the Internet of Things' + }; + + print(json2yaml(developerData)); +``` + +This function is implemented in a very basic and maybe a naive way, please let me know if it does not work for you. + +## Usage + +To use json2yaml, add the following dependency to pubspec.yaml: + +``` +dependencies: + json2yaml: ^1.0.0 +``` + +## Advanced usage: Yaml formatting styles + +json2yaml supports an optional argument to customize Yaml formatting for different use cases. +At the moment, it supports three styles: +- YamlStyle.generic (default) -- generic Yaml rendering +- YamlStyle.pubspecYaml -- Yaml formatting style mimicking pubspec.yaml files +- YamlStyle.pubspecLock -- Yaml formatting style mimicking pubspec.lock files generated by Dart pub + +Yaml style is supplied as an optional argument of json2yaml(). + +``` +/// Yaml formatting control options +enum YamlStyle { + generic, + pubspecYaml, + pubspecLock, +} + +/// Converts JSON to YAML representation +String json2yaml( + Map json, { + YamlStyle yamlStyle = YamlStyle.generic, +}); +``` diff --git a/dev/dart_quality_checks.sh b/dev/dart_quality_checks.sh index 36e4ef7..036cbd2 100755 --- a/dev/dart_quality_checks.sh +++ b/dev/dart_quality_checks.sh @@ -1,5 +1,6 @@ #!/bin/bash -ex +dart example/main.dart dartanalyzer --fatal-hints . pub run test pub run dependency_validator --ignore=functional_data_generator,sum_types_generator,test_coverage diff --git a/example/main.dart b/example/main.dart new file mode 100644 index 0000000..3803b2c --- /dev/null +++ b/example/main.dart @@ -0,0 +1,45 @@ +/* + * MIT License + * + * Copyright (c) 2019 Alexei Sintotski + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +import 'package:json2yaml/json2yaml.dart'; + +// ignore_for_file: avoid_print + +void main() { + const developerData = { + 'name': "Martin D'vloper", + 'job': 'Developer', + 'skill': 'Elite', + 'employed': true, + 'foods': ['Apple', 'Orange', 'Strawberry', 'Mango'], + 'languages': { + 'perl': 'Elite', + 'python': 'Elite', + 'pascal': 'Lame', + }, + 'education': '4 GCSEs\n3 A-Levels\nBSc in the Internet of Things' + }; + + print(json2yaml(developerData)); +} diff --git a/example/pubspec.yaml b/example/pubspec.yaml new file mode 100644 index 0000000..006c9a0 --- /dev/null +++ b/example/pubspec.yaml @@ -0,0 +1,8 @@ +name: example + +environment: + sdk: ">=2.5.0 <3.0.0" + +dependencies: + json2yaml: + path: .. diff --git a/lib/src/json2yaml.dart b/lib/src/json2yaml.dart index e5e066f..0d35f51 100644 --- a/lib/src/json2yaml.dart +++ b/lib/src/json2yaml.dart @@ -24,7 +24,7 @@ import 'package:json2yaml/src/internal/render_to_yaml.dart'; -/// Yaml formatting control +/// Yaml formatting control options enum YamlStyle { generic, pubspecYaml, diff --git a/pubspec.yaml b/pubspec.yaml index 476054b..c46412c 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: json2yaml description: A new Flutter package project. -version: 0.0.1 +version: 1.0.0 author: Alexei Sintotski homepage: https://github.com/alexei-sintotski/json2yaml