read-yaml-promise

    1.0.2 • Public • Published

    read-yaml-promise

    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

    NPM version

    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) 2014 Shinnosuke Watanabe

    Licensed under the MIT License.

    Install

    npm i read-yaml-promise

    DownloadsWeekly Downloads

    565

    Version

    1.0.2

    License

    none

    Last publish

    Collaborators

    • shinnn