Gathering detailed insights and metrics for rc-config-loader
Gathering detailed insights and metrics for rc-config-loader
Gathering detailed insights and metrics for rc-config-loader
Gathering detailed insights and metrics for rc-config-loader
Load config from .{product}rc.{json,yml,js} file
npm install rc-config-loader
96.6
Supply Chain
100
Quality
75.8
Maintenance
100
Vulnerability
99.6
License
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
60 Stars
66 Commits
6 Forks
3 Watching
1 Branches
7 Contributors
Updated on 18 Aug 2024
Minified
Minified + Gzipped
TypeScript (89.6%)
JavaScript (10.13%)
Shell (0.27%)
Cumulative downloads
Total Downloads
Last day
-7.1%
130,419
Compared to previous day
Last week
2.8%
713,918
Compared to previous week
Last month
11.9%
2,859,287
Compared to previous month
Last year
15%
36,014,805
Compared to previous year
Load config from .{product}rc.{json,yml,js}
file.
It is a Node.js library for loading .textlintrc
, .eslintrc
, .stylelintrc
etc...
Find and load a configuration object from:
package.json
property if it is needed.<product>rc
or .<product>rc.json
or .<product>rc.js
or.<product>rc.yml
, .<product>rc.yaml
.d.ts
rc
contains shabang in .js
filesync
optionIf you want to async support and customize loader, recommended to use cosmiconfig.
Install with npm:
npm install rc-config-loader
1export interface rcConfigLoaderOption { 2 // does look for `package.json` 3 packageJSON?: 4 | boolean 5 | { 6 fieldName: string; 7 }; 8 // if config file name is not same with packageName, set the name 9 configFileName?: string; 10 // treat default(no ext file) as some extension 11 defaultExtension?: string | string[]; 12 // where start to load 13 cwd?: string; 14} 15/** 16 * Find and load rcfile, return { config, filePath } 17 * If not found any rcfile, throw an Error. 18 * @param {string} pkgName 19 * @param {rcConfigLoaderOption} [opts] 20 * @returns {{ config: Object, filePath:string } | undefined} 21 */ 22export declare function rcFile<R extends {}>(pkgName: string, opts?: rcConfigLoaderOption): { 23 config: R; 24 filePath: string; 25} | undefined; 26
rcFile
return { config, filePath }
object.
config
: it is config objectfilePath
: absolute path to config fileNote:
rcFile
function return undefined
if the config file is not foundrcFile
throw an Error if the config file content is malformed (causing a parsing error)Recommenced usage:
1import { rcFile } from "rc-config-loader" 2 3function loadRcFile(rcFileName){ 4 try { 5 const results = rcFile(rcFileName); 6 // Not Found 7 if (!results) { 8 return {}; 9 } 10 return results.config; 11 } catch (error) { 12 // Found it, but it is parsing error 13 return {} ; // default value 14 } 15} 16// load config 17const config = loadRcFile("your-application"); 18console.log(config); // => rcfile content
It will check these files and return config file if found it.
.your-applicationrc.json
.your-applicationrc.yml
.your-applicationrc.yaml
.your-applicationrc.js
package.json
packageJSON
option is enabled1import { rcFile } from "rc-config-loader"
2// load .eslintrc from current dir
3console.log(rcFile("eslint"));
4
5// load .eslintrc from specific path
6console.log(rcFile("eslint", {
7 configFileName: `${__dirname}/test/fixtures/.eslintrc`
8}));
9/*
10config: { extends: 'standard',
11 rules:
12 { 'comma-dangle': [ 2, 'always-multiline' ],
13 'arrow-parens': [ 2, 'as-needed' ] } }
14filePath: ${__dirname}/test/fixtures/.eslintrc
15 */
16
17// load property from package.json
18console.log(rcFile("rc-config-loader", {
19 packageJSON: {
20 fieldName: "directories"
21 }
22}));
23/*
24config: { test: 'test' }
25filePath: /path/to/package.json
26 */
27
28// load .eslintrc from specific dir
29console.log(rcFile("eslint", {
30 cwd: `${__dirname}/test/fixtures`
31}));
32
33// load specific filename from current dir
34console.log(rcFile("travis", {configFileName: ".travis"}));
35/*
36config: { sudo: false, language: 'node_js', node_js: 'stable' }
37filePath: /path/to/.travis
38 */
39
40// try to load as .json, .yml, js
41console.log(rcFile("bar", {
42 configFileName: `${__dirname}/test/fixtures/.barrc`,
43 defaultExtension: [".json", ".yml", ".js"]
44}));
45
46// try to load as foobar, but .foobarrc is not found
47console.log(rcFile("foorbar")); // => undefined
48
49// try to load as .json, but it is not json
50// throw SyntaxError
51try {
52 rcFile("unknown", {
53 // This is not json
54 configFileName: `${__dirname}/test/fixtures/.unknownrc`,
55 defaultExtension: ".json"
56 })
57} catch (error) {
58 console.log(error);
59 /*
60 SyntaxError: Cannot read config file: /test/fixtures/.unknownrc
61 */
62}
See Releases page.
Install devDependencies and Run npm test
:
npm i -d && npm test
Pull requests and stars are always welcome.
For bugs and feature requests, please create an issue.
git checkout -b my-new-feature
git commit -am 'Add some feature'
git push origin my-new-feature
MIT © azu
Difference
defaultExtension
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
security policy file detected
Details
Reason
4 existing vulnerabilities detected
Details
Reason
Found 6/25 approved changesets -- score normalized to 2
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More