src/lib/index.js
function requireAll(schemaDir, options, callback) {
  debug("loading schemas");
  if (!callback) {
    callback = options;
    options = {};
  }
  const opts = _.assign({
    extensions: ["json"],
  }, options);

  let files;
  try {
    files = fs.readdirSync(schemaDir);
  } catch(errReaddir) {
    return callback(errReaddir);
  }

  let schemas = [];

  for (let index = 0; index < files.length; index++) {
    const file = files[index];
    const ext = path.extname(file).slice(1);

    if (opts.extensions.indexOf(ext) === -1) {
      continue;
    }

    const abspath = path.join(schemaDir, file);
    let schema;

    // try load the schema! If it fails, stop immediately
    try {
      schema = require(abspath);
    } catch (errRequire) {
      return callback(errRequire);
    }

    schema.filepath = abspath;
    schemas.push(schema);
  }

  return callback(null, schemas);
}
function requireAll(schemaDir, options, callback) {
  debug("loading schemas");
  if (!callback) {
    callback = options;
    options = {};
  }
  const opts = _.assign({
    extensions: ["json"],
  }, options);

  let files;
  try {
    files = fs.readdirSync(schemaDir);
  } catch(errReaddir) {
    return callback(errReaddir);
  }

  let schemas = [];

  for (let index = 0; index < files.length; index++) {
    const file = files[index];
    const ext = path.extname(file).slice(1);

    if (opts.extensions.indexOf(ext) === -1) {
      continue;
    }

    const abspath = path.join(schemaDir, file);
    let schema;

    // try load the schema! If it fails, stop immediately
    try {
      schema = require(abspath);
    } catch (errRequire) {
      return callback(errRequire);
    }

    schema.filepath = abspath;
    schemas.push(schema);
  }

  return callback(null, schemas);
}
function requireAll ( schemaDir , options , callback ) { debug ( "loading schemas" ) ; if ( ! callback ) { callback = options ; options = { } ; } const opts = _ . assign ( { extensions : [ "json" ] , } , options ) ; let files ; try { files = fs . readdirSync ( schemaDir ) ; } catch ( errReaddir ) { return callback ( errReaddir ) ; } let schemas = [ ] ; for ( let index = 0 ; index < files . length ; index ++ ) { const file = files [ index ] ; const ext = path . extname ( file ) . slice ( 1 ) ; if ( opts . extensions . indexOf ( ext ) === - 1 ) { continue ; } const abspath = path . join ( schemaDir , file ) ; let schema ; // try load the schema! If it fails, stop immediately try { schema = require ( abspath ) ; } catch ( errRequire ) { return callback ( errRequire ) ; } schema . filepath = abspath ; schemas . push ( schema ) ; } return callback ( null , schemas ) ; }
Loads all the Schemas into memory.

@param  {String} schemaDir - path to directory holding schemas
@param  {Object} [options]
@param  {String[]} [options.extensions=["json"]] Extension of schema files
@param  {Function} callback - callback(err, schemas)
Loads all the Schemas into memory .