Esempio n. 1
0
'use strict';

import through from 'through2';
import path from 'path';
import gutil, {PluginError} from 'gulp-util'
import jsyaml from 'js-yaml';
import extend  from 'extend';
import BufferStreams from 'bufferstreams';
const PLUGIN_NAME = 'gulp-yaml-validate';

import yaml from 'js-yaml';
import {init} from 'check-type';
const check = init();

const yaml2json = (buffer, options) => {
    const htmlRe = /(<([^>]+)>)/ig;
    let contents = buffer.toString('utf8');
    if(options.html && htmlRe.test(contents)) {
      throw new Error('YML cannot contain HTML');
    } else {
      let ymlDocument = options.safe ? jsyaml.safeLoad(contents) : jsyaml.load(contents);
      return new Buffer(JSON.stringify(ymlDocument, options.replacer, options.space));
    }
};

module.exports = function(options) {
  var options = extend({
    safe: false,
    html: false,
    replacer: null,
    space: null
'use strict';

var _ = require('lodash');
var check = require('check-type');

check.init(_);

check.init({
  isLintResult: function(value) {
    return check(value).is('object') && check(value).is.not('array') &&
      _.every(value, function(result, path) {
        return check(path).is('string') && check(result).is('arrayOfString');
      });
  },

  isArrayOfString: function(value) {
    if (check(value).is.not('array')) {
      return false;
    }
    return _.every(value, _.isString);
  }
});

module.exports = check;