read-yaml-promise
v1.0.2
Published
Promise to read and parse a YAML file
Downloads
7,720
Maintainers
Readme
read-yaml-promise
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
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) 2014 Shinnosuke Watanabe
Licensed under the MIT License.