Sha256: 8674a71d73acae182a5c0875e7317713550bb0b69822e1b4ced80eb53cf926d8

Contents?: true

Size: 1.93 KB

Versions: 28

Compression:

Stored size: 1.93 KB

Contents

//      
'use strict';

const os = require('os');
const createExplorer = require('./createExplorer');
const loaders = require('./loaders');

module.exports = cosmiconfig;

function cosmiconfig(
  moduleName        ,
  options   
                         
                     
                                 
                                      
                     
                    
                                                       
   
) {
  options = options || {};
  const defaults = {
    packageProp: moduleName,
    searchPlaces: [
      'package.json',
      `.${moduleName}rc`,
      `.${moduleName}rc.json`,
      `.${moduleName}rc.yaml`,
      `.${moduleName}rc.yml`,
      `.${moduleName}rc.js`,
      `${moduleName}.config.js`,
    ],
    ignoreEmptySearchPlaces: true,
    stopDir: os.homedir(),
    cache: true,
    transform: identity,
  };
  const normalizedOptions                  = Object.assign(
    {},
    defaults,
    options,
    {
      loaders: normalizeLoaders(options.loaders),
    }
  );

  return createExplorer(normalizedOptions);
}

cosmiconfig.loadJs = loaders.loadJs;
cosmiconfig.loadJson = loaders.loadJson;
cosmiconfig.loadYaml = loaders.loadYaml;

function normalizeLoaders(rawLoaders         )          {
  const defaults = {
    '.js': { sync: loaders.loadJs, async: loaders.loadJs },
    '.json': { sync: loaders.loadJson, async: loaders.loadJson },
    '.yaml': { sync: loaders.loadYaml, async: loaders.loadYaml },
    '.yml': { sync: loaders.loadYaml, async: loaders.loadYaml },
    noExt: { sync: loaders.loadYaml, async: loaders.loadYaml },
  };

  if (!rawLoaders) {
    return defaults;
  }

  return Object.keys(rawLoaders).reduce((result, ext) => {
    const entry = rawLoaders && rawLoaders[ext];
    if (typeof entry === 'function') {
      result[ext] = { sync: entry, async: entry };
    } else {
      result[ext] = entry;
    }
    return result;
  }, defaults);
}

function identity(x) {
  return x;
}

Version data entries

28 entries across 27 versions & 9 rubygems

Version Path
optimacms-0.1.61 spec/dummy/node_modules/cosmiconfig/dist/index.js
disco_app-0.18.0 test/dummy/node_modules/cosmiconfig/dist/index.js
disco_app-0.18.2 test/dummy/node_modules/cosmiconfig/dist/index.js
disco_app-0.16.1 test/dummy/node_modules/cosmiconfig/dist/index.js
disco_app-0.15.2 test/dummy/node_modules/cosmiconfig/dist/index.js
disco_app-0.18.4 test/dummy/node_modules/cosmiconfig/dist/index.js
disco_app-0.18.1 test/dummy/node_modules/cosmiconfig/dist/index.js
disco_app-0.12.7.pre.puma.pre.3 test/dummy/node_modules/cosmiconfig/dist/index.js
disco_app-0.14.0 test/dummy/node_modules/cosmiconfig/dist/index.js
disco_app-0.13.6.pre.puma.pre.3 test/dummy/node_modules/cosmiconfig/dist/index.js
tang-0.2.1 spec/tang_app/node_modules/cosmiconfig/dist/index.js
groonga-client-model-6.0.0 test/apps/rails6.1.3/node_modules/cosmiconfig/dist/index.js
groonga-client-model-6.0.0 test/apps/rails6.0.3.5/node_modules/cosmiconfig/dist/index.js
ruby2js-4.0.4 lib/tasks/testrails/node_modules/cosmiconfig/dist/index.js
ruby2js-4.0.3 lib/tasks/testrails/node_modules/cosmiconfig/dist/index.js
tang-0.2.0 spec/tang_app/node_modules/cosmiconfig/dist/index.js
tang-0.1.0 spec/tang_app/node_modules/cosmiconfig/dist/index.js
tang-0.0.9 spec/tang_app/node_modules/cosmiconfig/dist/index.js
enju_library-0.3.8 spec/dummy/node_modules/cosmiconfig/dist/index.js
jester-data-8.0.0 node_modules/cosmiconfig/dist/index.js