{"id":13495409,"url":"https://github.com/azu/rc-config-loader","last_synced_at":"2026-02-27T09:25:34.346Z","repository":{"id":17344238,"uuid":"81713127","full_name":"azu/rc-config-loader","owner":"azu","description":"Load config from .{product}rc.{json,yml,js} file","archived":false,"fork":false,"pushed_at":"2023-06-13T22:40:50.000Z","size":247,"stargazers_count":62,"open_issues_count":2,"forks_count":6,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-30T00:07:55.592Z","etag":null,"topics":["config","javascript","load","package","rc"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/azu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"azu"}},"created_at":"2017-02-12T08:34:22.000Z","updated_at":"2025-02-03T22:28:27.000Z","dependencies_parsed_at":"2024-06-18T14:01:02.521Z","dependency_job_id":null,"html_url":"https://github.com/azu/rc-config-loader","commit_stats":{"total_commits":58,"total_committers":9,"mean_commits":6.444444444444445,"dds":0.2931034482758621,"last_synced_commit":"945ba90843af96dae3fd2bcfbebfa9f31010cb06"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/azu%2Frc-config-loader","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/azu%2Frc-config-loader/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/azu%2Frc-config-loader/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/azu%2Frc-config-loader/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/azu","download_url":"https://codeload.github.com/azu/rc-config-loader/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247419860,"owners_count":20936012,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["config","javascript","load","package","rc"],"created_at":"2024-07-31T19:01:34.417Z","updated_at":"2026-02-27T09:25:34.317Z","avatar_url":"https://github.com/azu.png","language":"TypeScript","funding_links":["https://github.com/sponsors/azu"],"categories":["javascript","TypeScript"],"sub_categories":[],"readme":"# rc-config-loader [![Actions Status: test](https://github.com/azu/rc-config-loader/workflows/test/badge.svg)](https://github.com/azu/rc-config-loader/actions?query=workflow%3A\"test\")\n\nLoad config from `.{product}rc.{json,yml,js}` file.\n\nIt is a Node.js library for loading `.textlintrc`, `.eslintrc`, `.stylelintrc` etc...\n\n## Features\n\nFind and load a configuration object from:\n\n- a `package.json` property if it is needed\n- a JSON or YAML, JS \"rc file\"\n    - `.\u003cproduct\u003erc` or `.\u003cproduct\u003erc.json` or `.\u003cproduct\u003erc.js` or`.\u003cproduct\u003erc.yml`, `.\u003cproduct\u003erc.yaml`\n- TypeScript support\n    - Includes `.d.ts`\n\n## Difference\n\n### with [MoOx/rc-loader](https://github.com/MoOx/rc-loader \"MoOx/rc-loader\")\n\n- Safe API\n    - `rc` contains shabang in `.js` file\n- Enhance Error message\n\n### with [cosmiconfig](https://github.com/davidtheclark/cosmiconfig \"cosmiconfig\")\n\n- \u003cdel\u003eSync loading\u003c/del\u003e\n    - [cosmiconfig@3+](https://github.com/davidtheclark/cosmiconfig/blob/master/CHANGELOG.md#300) support `sync` option\n- \u003cdel\u003eBuilt-in TypeScript support\u003c/del\u003e\n    - [comisconfig@6*](https://github.com/davidtheclark/cosmiconfig/blob/master/CHANGELOG.md#600) is written by TypeScript\n\nIf you want to async support and customize loader, recommended to use [cosmiconfig](https://github.com/davidtheclark/cosmiconfig).\n\n## Install\n\nInstall with [npm](https://www.npmjs.com/):\n\n    npm install rc-config-loader\n\n## Usage\n\n### API\n\n```ts\nexport interface rcConfigLoaderOption {\n    // does look for `package.json`\n    packageJSON?:\n        | boolean\n        | {\n              fieldName: string;\n          };\n    // if config file name is not same with packageName, set the name\n    configFileName?: string;\n    // treat default(no ext file) as some extension\n    defaultExtension?: string | string[];\n    // where start to load\n    cwd?: string;\n}\n/**\n * Find and load rcfile, return { config, filePath }\n * If not found any rcfile, throw an Error.\n * @param {string} pkgName\n * @param {rcConfigLoaderOption} [opts]\n * @returns {{ config: Object, filePath:string } | undefined}\n */\nexport declare function rcFile\u003cR extends {}\u003e(pkgName: string, opts?: rcConfigLoaderOption): {\n    config: R;\n    filePath: string;\n} | undefined;\n\n```\n\n`rcFile` return `{ config, filePath }` object.\n\n- `config`: it is config object\n- `filePath`: absolute path to config file\n\n**Note:**\n \n- `rcFile` function return `undefined` if the config file is not found\n- `rcFile` throw an Error if the config file content is malformed (causing a parsing error)\n\nRecommenced usage:\n\n```js\nimport { rcFile } from \"rc-config-loader\"\n\nfunction loadRcFile(rcFileName){\n    try {\n        const results = rcFile(rcFileName);\n        // Not Found\n        if (!results) {\n            return {};\n        }\n        return results.config;\n    } catch (error) {\n        // Found it, but it is parsing error\n        return {} ; // default value\n    }\n}\n// load config\nconst config = loadRcFile(\"your-application\");\nconsole.log(config); // =\u003e rcfile content\n```\n\nIt will check these files and return config file if found it.\n\n- `.your-applicationrc.json`\n- `.your-applicationrc.yml`\n- `.your-applicationrc.yaml`\n- `.your-applicationrc.js`\n- [optional] `package.json`\n  - if `packageJSON` option is enabled\n\n### Example\n\n```js\nimport { rcFile } from \"rc-config-loader\"\n// load .eslintrc from current dir\nconsole.log(rcFile(\"eslint\"));\n\n// load .eslintrc from specific path\nconsole.log(rcFile(\"eslint\", {\n    configFileName: `${__dirname}/test/fixtures/.eslintrc`\n}));\n/*\nconfig: { extends: 'standard',\n  rules:\n   { 'comma-dangle': [ 2, 'always-multiline' ],\n     'arrow-parens': [ 2, 'as-needed' ] } }\nfilePath: ${__dirname}/test/fixtures/.eslintrc\n */\n\n// load property from package.json\nconsole.log(rcFile(\"rc-config-loader\", {\n    packageJSON: {\n        fieldName: \"directories\"\n    }\n}));\n/*\nconfig: { test: 'test' }\nfilePath: /path/to/package.json\n */\n\n// load .eslintrc from specific dir\nconsole.log(rcFile(\"eslint\", {\n    cwd: `${__dirname}/test/fixtures`\n}));\n\n// load specific filename from current dir\nconsole.log(rcFile(\"travis\", {configFileName: \".travis\"}));\n/*\nconfig: { sudo: false, language: 'node_js', node_js: 'stable' }\nfilePath: /path/to/.travis\n */\n\n// try to load as .json, .yml, js\nconsole.log(rcFile(\"bar\", {\n    configFileName: `${__dirname}/test/fixtures/.barrc`,\n    defaultExtension: [\".json\", \".yml\", \".js\"]\n}));\n\n// try to load as foobar, but .foobarrc is not found\nconsole.log(rcFile(\"foorbar\")); // =\u003e undefined\n\n// try to load as .json, but it is not json\n// throw SyntaxError\ntry {\n    rcFile(\"unknown\", {\n        // This is not json\n        configFileName: `${__dirname}/test/fixtures/.unknownrc`,\n        defaultExtension: \".json\"\n    })\n} catch (error) {\n    console.log(error);\n    /*\n    SyntaxError: Cannot read config file: /test/fixtures/.unknownrc\n    */\n}\n```\n\n## Users\n\n- [textlint](https://github.com/textlint/textlint \"textlint\")\n\n## Changelog\n\nSee [Releases page](https://github.com/azu/rc-config-loader/releases).\n\n## Running tests\n\nInstall devDependencies and Run `npm test`:\n\n    npm i -d \u0026\u0026 npm test\n\n## Contributing\n\nPull requests and stars are always welcome.\n\nFor bugs and feature requests, [please create an issue](https://github.com/azu/rc-config-loader/issues).\n\n1. Fork it!\n2. Create your feature branch: `git checkout -b my-new-feature`\n3. Commit your changes: `git commit -am 'Add some feature'`\n4. Push to the branch: `git push origin my-new-feature`\n5. Submit a pull request :D\n\n## Author\n\n- [github/azu](https://github.com/azu)\n- [twitter/azu_re](https://twitter.com/azu_re)\n\n## License\n\nMIT © azu\n\n## Acknowledgement\n\n- [zkochan/rcfile: Loads library configuration in all possible ways](https://github.com/zkochan/rcfile \"zkochan/rcfile: Loads library configuration in all possible ways\")\n\n**Difference**\n\n- support multiple `defaultExtension`  \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fazu%2Frc-config-loader","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fazu%2Frc-config-loader","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fazu%2Frc-config-loader/lists"}