JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 709564
  • Score
    100M100P100Q186438F
  • License MIT

load config file from .{product}rc.{json,yml,js}

Package Exports

  • rc-config-loader

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (rc-config-loader) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

rc-config-loader Build Status

Load config from .{product}rc.{json,yml,js} file.

It is a Node.js library for loading .textlintrc, .eslintrc, .stylelintrc etc...

Features

Find and load a configuration object from:

  • a package.json property if it is needed
  • a JSON or YAML, JS "rc file"
    • .<product>rc or .<product>rc.json or .<product>rc.js or.<product>rc.yml, .<product>rc.yaml
  • TypeScript support
    • Includes .d.ts

Difference

with MoOx/rc-loader

  • Safe API
    • rc contains shabang in .js file
  • Enhance Error message

with cosmiconfig

Install

Install with npm:

npm install rc-config-loader

Usage

API

export interface rcConfigLoaderOption {
    // does look for `package.json`
    packageJSON?: boolean | {
        fieldName: string;
    };
    // if config file name is not same with packageName, set the name
    configFileName?: string;
    // treat default(no ext file) as some extension
    defaultExtension?: string | string[];
    // where start to load
    cwd?: string;
}
export default function rcConfigLoader(packageName: string, options?: rcConfigLoaderOption): Object;

rcConfigLoader return { config, filePath } object.

  • config: it is config object
  • filePath: absolute path to config file

If not found config file, return undefined.

Example

"use strict";
const rcfile = require("rc-config-loader");
// load .eslintrc from current dir
console.log(rcfile("eslint"));

// load .eslintrc from specific path
console.log(rcfile("eslint", {
    configFileName: `${__dirname}/test/fixtures/.eslintrc`
}));
/*
config: { extends: 'standard',
  rules:
   { 'comma-dangle': [ 2, 'always-multiline' ],
     'arrow-parens': [ 2, 'as-needed' ] } }
filePath: ${__dirname}/test/fixtures/.eslintrc
 */

// load property from pacakge.json
console.log(rcfile("rc-config-loader", {
    packageJSON: {
        fieldName: "directories"
    }
}));
/*
config: { test: 'test' }
filePath: /path/to/package.json
 */

// load .eslintrc from specific dir
console.log(rcfile("eslint", {
    cwd: `${__dirname}/test/fixtures`
}));

// load specific filename from current dir
console.log(rcfile("travis", {configFileName: ".travis"}));
/*
config: { sudo: false, language: 'node_js', node_js: 'stable' }
filePath: /path/to/.travis
 */

// try to load as .json, .yml, js
console.log(rcfile("bar", {
    configFileName: `${__dirname}/test/fixtures/.barrc`,
    defaultExtension: [".json", ".yml", ".js"]
}));

// try to load as .json, but it is not json
// throw Error
try {
    rcfile("unknown", {
        // This is not json
        configFileName: `${__dirname}/test/fixtures/.unknownrc`,
        defaultExtension: ".json"
    })
} catch (error) {
    console.log(error);
    /*
    SyntaxError: Cannot read config file: /test/fixtures/.unknownrc
    */
}

Users

Changelog

See Releases page.

Running tests

Install devDependencies and Run npm test:

npm i -d && npm test

Contributing

Pull requests and stars are always welcome.

For bugs and feature requests, please create an issue.

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D

Author

License

MIT © azu

Acknowledgement

Difference

  • support multiple defaultExtension