lib/dirio.js
function _handleConvert(stat, dest, source, callback) {
  // "dest" arg is optional
  if (typeof source === 'function') {
    callback = source;
    source = dest;
    dest = null;
  }

  // assert input params
  assert.ok(
    dest === null || typeof dest === 'string',
    'Invalid type of argument "dest", expected "null" or "string", ' +
    'but is "' + (typeof dest) + '"'
  );
  assert.equal(
    typeof(callback),
    'function',
    'Invalid type of argument "callback", expected "function", ' +
    'but is "' + (typeof callback) + '"'
  );

  // perform an action according to "source" and "dest"
  switch(typeof source) {
    case 'string':
      // source is a path
      if (_isJsonPath(source)) {
        // source is meant to be a json file
        if (typeof dest === 'string') {
          // destination is meant to be a directory
          return _load2write(dest, source, callback);
        }
        // destination is meant to be a local object
        return _load(source, callback);
      }
      // source is meant to be a directory
      if (typeof dest === 'string') {
        // destination is meant to be a json file
        return _read2store(stat, dest, source, callback);
      }
      // destination is meant to be a local object
      return _read(stat, source, callback);
    case 'object':
      // source is an object
      if (_isJsonPath(dest)) {
        // destination is meant to be a json file
        return _store(dest, source, callback);
      }
      // destination is meant to be a directory
      return _write(dest, source, callback);
    default:
      // invalid source
      assert.ok(
        false,
        'Invalid type of argument "source", expected "string" or "object", ' +
        'but is "' + (typeof source) + '"'
      );
  }
}
function _handleConvert(stat, dest, source, callback) {
  // "dest" arg is optional
  if (typeof source === 'function') {
    callback = source;
    source = dest;
    dest = null;
  }

  // assert input params
  assert.ok(
    dest === null || typeof dest === 'string',
    'Invalid type of argument "dest", expected "null" or "string", ' +
    'but is "' + (typeof dest) + '"'
  );
  assert.equal(
    typeof(callback),
    'function',
    'Invalid type of argument "callback", expected "function", ' +
    'but is "' + (typeof callback) + '"'
  );

  // perform an action according to "source" and "dest"
  switch(typeof source) {
    case 'string':
      // source is a path
      if (_isJsonPath(source)) {
        // source is meant to be a json file
        if (typeof dest === 'string') {
          // destination is meant to be a directory
          return _load2write(dest, source, callback);
        }
        // destination is meant to be a local object
        return _load(source, callback);
      }
      // source is meant to be a directory
      if (typeof dest === 'string') {
        // destination is meant to be a json file
        return _read2store(stat, dest, source, callback);
      }
      // destination is meant to be a local object
      return _read(stat, source, callback);
    case 'object':
      // source is an object
      if (_isJsonPath(dest)) {
        // destination is meant to be a json file
        return _store(dest, source, callback);
      }
      // destination is meant to be a directory
      return _write(dest, source, callback);
    default:
      // invalid source
      assert.ok(
        false,
        'Invalid type of argument "source", expected "string" or "object", ' +
        'but is "' + (typeof source) + '"'
      );
  }
}
function _handleConvert ( stat , dest , source , callback ) { // "dest" arg is optional if ( typeof source === 'function' ) { callback = source ; source = dest ; dest = null ; } // assert input params assert . ok ( dest === null || typeof dest === 'string' , 'Invalid type of argument "dest", expected "null" or "string", ' + 'but is "' + ( typeof dest ) + '"' ) ; assert . equal ( typeof ( callback ) , 'function' , 'Invalid type of argument "callback", expected "function", ' + 'but is "' + ( typeof callback ) + '"' ) ; // perform an action according to "source" and "dest" switch ( typeof source ) { case 'string' : // source is a path if ( _isJsonPath ( source ) ) { // source is meant to be a json file if ( typeof dest === 'string' ) { // destination is meant to be a directory return _load2write ( dest , source , callback ) ; } // destination is meant to be a local object return _load ( source , callback ) ; } // source is meant to be a directory if ( typeof dest === 'string' ) { // destination is meant to be a json file return _read2store ( stat , dest , source , callback ) ; } // destination is meant to be a local object return _read ( stat , source , callback ) ; case 'object' : // source is an object if ( _isJsonPath ( dest ) ) { // destination is meant to be a json file return _store ( dest , source , callback ) ; } // destination is meant to be a directory return _write ( dest , source , callback ) ; default : // invalid source assert . ok ( false , 'Invalid type of argument "source", expected "string" or "object", ' + 'but is "' + ( typeof source ) + '"' ) ; } }
Asserts user input and calls appropriate lower level function to
complete the desired task.
@param {Function} stat - Function of fs module fs.stat or fs.lstat.
@param {String} [dest] - Path to destination location on file system.
@param {String | Object} source - Path to source location on file system
or object directly provided by user.
@param {Function} callback - Callback that expects a possible error
and possible result.
Asserts user input and calls appropriate lower level function to complete the desired task .