-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Preparations for the initial release (example, readme, etc.)
- Loading branch information
1 parent
5f9d233
commit 6b0f9f7
Showing
7 changed files
with
117 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<String, dynamic> json, { | ||
YamlStyle yamlStyle = YamlStyle.generic, | ||
}); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
name: example | ||
|
||
environment: | ||
sdk: ">=2.5.0 <3.0.0" | ||
|
||
dependencies: | ||
json2yaml: | ||
path: .. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
name: json2yaml | ||
description: A new Flutter package project. | ||
version: 0.0.1 | ||
version: 1.0.0 | ||
author: Alexei Sintotski <[email protected]> | ||
homepage: https://github.com/alexei-sintotski/json2yaml | ||
|
||
|