ryp

read-yaml-promise

Promise to read and parse a YAML file

Showing:

Popularity

Downloads/wk

529

GitHub Stars

2

Maintenance

Last Commit

6yrs ago

Contributors

0

Package

Dependencies

2

License

Type Definitions

Tree-Shakeable

No?

Categories

Readme

read-yaml-promise

NPM version Build Status Build status Coverage Status Dependency Status devDependency Status

Promise to read and parse a YAML file

var readYaml = require('read-yaml-promise');

// fixture.yaml
// - 'foo'
// - false

readYaml('fixture.yaml')
.then(function(data) {
  data; //=> ['foo', false]
})
.catch(function(err) {
  console.log(err.message);
});

Installation

Use npm.

npm install read-yaml-promise

API

var readYaml = require('read-yaml-promise');

readYaml(filePath [, options])

filePath: String (file path)
options: Object (options for js-yaml's safeLoad method and fs.readFile), or String (file encoding)
Return: Object (Promise)

When it finish reading and parsing a YAML file, it will be fulfilled with an Object of the parsed data as its first argument.

When it fails to read or parse a file, it will be rejected with an error as its first argument.

var readYaml = require('read-yaml-promise');
var FAILSAFE_SCHEMA = require('js-yaml').FAILSAFE_SCHEMA; // npm install js-yaml 

// fixture.yml (foo: true)

readYaml('fixture.yml').then(function(data) {
  typeof data.foo; //=> 'boolean'
});

readYaml('fixture.yml', {schema: FAILSAFE_SCHEMA}).then(function(contents) {
  typeof data.foo; //=> 'string'
});

options

Note that filename option is automatically specified using the first argument.

License

Copyright (c) Shinnosuke Watanabe

Licensed under the MIT License.

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100
No reviews found
Be the first to rate

Alternatives

No alternatives found

Tutorials

No tutorials found
Add a tutorial