New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

load-config-folder

Package Overview
Dependencies
Maintainers
0
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

load-config-folder

Load the config in the folder as a plain object.

latest
Source
npmnpm
Version
2.0.0
Version published
Weekly downloads
17
-29.17%
Maintainers
0
Weekly downloads
 
Created
Source

load-config-folder npm

Build Status Code Climate Test Coverage downloads license

Load the config from folder as a plain object.

  • The config file format can be registered.
  • The registered file format order is the search order.
  • the virtual file system can be specfied: loadConfig.setFileSystem(fs)
    • fs.path = require('path.js/lib/path').path for the virtual POSIX path.
      • you must set the path first before call setFileSystem.

The load-config-folder is similar to the load-config-file. But it will load the configuration from the folder with a specified file name, you can use addConfig to set the specified config file name(it's a basename).

Usage

import loadConfig, { FolderConfig } from 'load-config-folder'
import yaml from 'js-yaml'
import cson from 'cson'

//the config file basename for the folder.
FolderConfig.addConfig(['_config']);
FolderConfig.register(['.yaml', '.yml'], yaml.safeLoad);
FolderConfig.register('.cson', cson.parseCSONString.bind(cson));
FolderConfig.register('.json', JSON.parse);

//Synchronously load config for the folder.
//it will search folder/_config.yaml, folder/_config.yml, folder/_config.cson, folder/_config.json
//the first exist file will be loaded.
//the default encoding is "utf8" if no encoding.
//loadConfig('config', {encoding: 'ascii'})
//the non-enumerable "$cfgPath" property added.
console.log(loadConfig('./folder'));

//Asynchronously load config from file
loadConfig('./folder', function(err, result){
  if (err) {
    console.log('error:', err);
  } else {
    console.log(result);
  }
})

let result = await loadConfig('./folder', true)
result = await FolderConfig.load('./folder')
result = FolderConfig.loadSync('./folder')

API

import { FolderConfig } from 'load-config-folder'
  • FolderConfig.setFileSystem(fs): set your favour file system. defaults to 'fs'.
    • the "file system" must implement readFile(path[, options], done) and readFileSync(path[, options])
  • load(dir, options, done): Asynchronously load config from dir
    • return the plain object and the $cfgPath property added if suceesful.
  • loadSync(dir, options): Synchronously load config from dir
    • return the plain object and the $cfgPath property added if suceesful.

License

MIT

Keywords

load

FAQs

Package last updated on 29 Aug 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts