lib/file/yaml/set.js
function yamlFileSet(file, keyPath, value, options) {
  if (_.isPlainObject(keyPath)) { // key is keyMapping
    if (!_.isUndefined(options)) {
      throw new Error('Wrong parameters. Cannot specify a keymapping and a value at the same time.');
    }
    if (_.isPlainObject(value)) {
      options = value;
      value = null;
    } else {
      options = {};
    }
  } else if (!_.isString(keyPath) && !_.isArray(keyPath)) {
    throw new Error('Wrong parameter `keyPath`.');
  }
  options = _.sanitize(options, {encoding: 'utf-8', retryOnENOENT: true});
  if (!exists(file)) {
    touch(file);
  }

  let content = yaml.safeLoad(read(file, _.pick(options, 'encoding')));
  if (_.isUndefined(content)) {
    content = {};
  }
  content = _setValue(content, keyPath, value);
  write(file, yaml.safeDump(content), options);
}
function yamlFileSet(file, keyPath, value, options) {
  if (_.isPlainObject(keyPath)) { // key is keyMapping
    if (!_.isUndefined(options)) {
      throw new Error('Wrong parameters. Cannot specify a keymapping and a value at the same time.');
    }
    if (_.isPlainObject(value)) {
      options = value;
      value = null;
    } else {
      options = {};
    }
  } else if (!_.isString(keyPath) && !_.isArray(keyPath)) {
    throw new Error('Wrong parameter `keyPath`.');
  }
  options = _.sanitize(options, {encoding: 'utf-8', retryOnENOENT: true});
  if (!exists(file)) {
    touch(file);
  }

  let content = yaml.safeLoad(read(file, _.pick(options, 'encoding')));
  if (_.isUndefined(content)) {
    content = {};
  }
  content = _setValue(content, keyPath, value);
  write(file, yaml.safeDump(content), options);
}
function yamlFileSet ( file , keyPath , value , options ) { if ( _ . isPlainObject ( keyPath ) ) { // key is keyMapping if ( ! _ . isUndefined ( options ) ) { throw new Error ( 'Wrong parameters. Cannot specify a keymapping and a value at the same time.' ) ; } if ( _ . isPlainObject ( value ) ) { options = value ; value = null ; } else { options = { } ; } } else if ( ! _ . isString ( keyPath ) && ! _ . isArray ( keyPath ) ) { throw new Error ( 'Wrong parameter `keyPath`.' ) ; } options = _ . sanitize ( options , { encoding : 'utf-8' , retryOnENOENT : true } ) ; if ( ! exists ( file ) ) { touch ( file ) ; } let content = yaml . safeLoad ( read ( file , _ . pick ( options , 'encoding' ) ) ) ; if ( _ . isUndefined ( content ) ) { content = { } ; } content = _setValue ( content , keyPath , value ) ; write ( file , yaml . safeDump ( content ) , options ) ; }
Set value in yaml file

@function $file~yaml/set
@param {string} file - Yaml file to write the value to
@param {string} keyPath (it can read nested keys: `'outerKey/innerKey'` or `'/outerKey/innerKey'`. `null`
or `'/'` will match all the document). Alternative format: ['outerKey', 'innerKey'].
@param {string|Number|boolean|Array|Object} value
@param {Object} [options]
@param {string} [options.encoding=utf-8] - Encoding used to read the file
@param {boolean} [options.retryOnENOENT=true] - Retry if writing files because of the parent directory does not
exists
@throws Will throw an error if the path is not a file
 
Set value in yaml file

@function $file~yaml/set²
@param {string} file - Yaml file to write the value to
@param {Object} keyMapping - key-value map to set in the file
@param {Object} [options]
@param {string} [options.encoding=utf-8] - Encoding used to read the file
@param {boolean} [options.retryOnENOENT=true] - Retry if writing files because of the parent directory does not
exists
@throws Will throw an error if the path is not a file
Set value in yaml file