Skip to content

Commit

Permalink
Preparations for the initial release (example, readme, etc.)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexei-sintotski committed Dec 4, 2019
1 parent 5f9d233 commit 6b0f9f7
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 5 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
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
60 changes: 59 additions & 1 deletion README.md
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,
});
```
1 change: 1 addition & 0 deletions dev/dart_quality_checks.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down
45 changes: 45 additions & 0 deletions example/main.dart
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));
}
8 changes: 8 additions & 0 deletions example/pubspec.yaml
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: ..
2 changes: 1 addition & 1 deletion lib/src/json2yaml.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

import 'package:json2yaml/src/internal/render_to_yaml.dart';

/// Yaml formatting control
/// Yaml formatting control options
enum YamlStyle {
generic,
pubspecYaml,
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
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

Expand Down

0 comments on commit 6b0f9f7

Please sign in to comment.