/**
 * @author ale0720@163.com
 * @date 2019-06-27 13:42
 */
import JsYaml from 'js-yaml';
var SexyYamlType = new JsYaml.Type('!sexy', {
  kind: 'sequence',
  construct: function construct(data) {
    return data.map(function (string) {
      return "sexy ".concat(string);
    });
  }
});
var SEXY_SCHEMA = JsYaml.Schema.create([SexyYamlType]);
export function convert(value) {
  return JsYaml.load(value, {
    schema: SEXY_SCHEMA
  });
}
/**
 * YAML 格式校验
 * @param values
 * @returns {Array}
 */

export function checkFormat(value) {
  var result = [];

  try {
    convert(value);
  } catch (e) {
    result.push(e);
  }

  return result;
}
/**
 * 非注释改动检测
 * @param old
 * @param value
 * @param callback
 * @returns {boolean}
 */

export function changedValue(old, value, callback) {
  var hasChanged = true;

  try {
    var oldValue = convert(old || '');
    var newValue = convert(value); // 转为对象格式，可以将注释去除

    if (JSON.stringify(oldValue) === JSON.stringify(newValue)) {
      hasChanged = false;
    }
  } catch (e) {
    callback(true);
    throw new Error("\u683C\u5F0F\u9519\u8BEF\uFF1A".concat(e));
  }

  return hasChanged;
}