npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

load-config-folder

v2.0.0

Published

Load the config in the folder as a plain object.

Downloads

27

Readme

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