@anolilab/rc

中文文档
4.0.9发布于 2026/09/09MITTypeScriptESM + CJS构建来源已验证近 30 天下载 11万

The runtime configuration loader.

原始使用文档
文档目录14 节
  1. The runtime configuration loader.
  2. Install
  3. Usage
  4. Api
  5. Standards
  6. Api Docs
  7. Functions
  8. rc()
  9. Related
  10. Supported Node.js Versions
  11. Contributing
  12. Credits
  13. Made with ❤️ at Anolilab
  14. License
rc

The runtime configuration loader.


typescript-image mit licence npm downloads Chat PRs Welcome


Daniel Bannert's open source work is supported by the community on GitHub Sponsors


Install

npm install @anolilab/rc
yarn add @anolilab/rc
pnpm add @anolilab/rc

Usage

The main function provided by this module is rc. It allows you to load configuration settings for your application from different sources.

import { rc } from "@anolilab/rc";

const { config, files } = rc("npm");

// returns a merged config object with all found npmrc files and a files list what files where found.

Api

  • name (string): The application name. This is used to locate configuration files and environment variables.
  • options (object, optional): An object with the following properties:
    • config (string, optional): Path to a specific configuration file.
    • cwd (string, optional): The current working directory to start searching for configuration files. Defaults to process.cwd().
    • defaults (object, optional): Default configuration values.
    • home (string, optional): The home directory to use. Defaults to os.homedir().
    • stopAt (string, optional): Directory to stop searching for configuration files.

Standards

Given your application name (appname), rc will look in all the obvious places for configuration.

  • The defaults object you passed in
  • /etc/${appname}/config
  • /etc/${appname}rc
  • $HOME/.config/${appname}/config
  • $HOME/.config/${appname}
  • $HOME/.${appname}/config
  • $HOME/.${appname}rc
  • a local .${appname}/config and .${appname}rc and all found looking in ../../../ ../../ ../ ./ etc.
  • if you passed environment variable ${appname}_config then from that file
  • if you passed options.config variable, then from that file
  • environment variables prefixed with ${appname}_ or use "__" to indicate nested properties
    (e.g. appname_foo__bar__baz => foo.bar.baz)

All configuration sources that were found will be flattened into one object, in this exact order.

Api Docs

@anolilab/rc

Functions

rc()

function rc(name, options?): object;

Defined in: index.ts:193

Aggregates configuration from multiple sources (defaults, configuration files, and environment variables) into a single object, following the same resolution logic as the original rc npm package.

The resolution order is (highest precedence last):

  1. options.defaults – default values supplied by the caller
  2. Configuration files discovered by getConfigFiles
  3. Environment variables that start with ${name}_ (nested via __)

The function also returns the list of configuration file paths that were read while resolving the configuration. No mutation is performed on any of the discovered files – they are only read.

Parameters

name

string

The base name of the application (used to derive env-var prefix and file names).

options?

Optional behaviour switches.

config?

string

Explicit path to a configuration file that should be merged last.

cwd?

string

Working directory to start searching for local configuration files.

defaults?

Record<string, any>

Default configuration values that act as the lowest precedence.

home?

string

Home directory to look for user-level configuration files. Defaults to the current user home directory.

stopAt?

string

Absolute path that acts as a boundary when traversing up the directory tree.

Returns

object

An object containing the final merged config and the ordered list of files that were considered.

config
config: Record<string, any>;
files
files: string[];
  • rc - The non-configurable configuration loader for lazy people.

Supported Node.js Versions

Libraries in this ecosystem make the best effort to track Node.js’ release schedule. Here’s a post on why we think this is important.

Contributing

If you would like to help take a look at the list of issues and check our Contributing guidelines.

Note: please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.

Credits

Made with ❤️ at Anolilab

This is an open source project and will always remain free to use. If you think it's cool, please star it 🌟. Anolilab is a Development and AI Studio. Contact us at [email protected] if you need any help with these technologies or just want to say hi!

License

The anolilab rc is open-sourced software licensed under the MIT

版本与发布记录

@anolilab/rc 共发布 34 个版本,首次发布于 2024/05/23;过去 12 个月发布了 16 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
4.0.9latest2026/09/091 个月前
4.0.82026/09/081 个月前
4.0.72026/08/202 个月前
4.0.62026/08/202 个月前
4.0.52026/07/233 个月前
4.0.42026/06/214 个月前

其他发布通道:alpha → 3.2.1-alpha.2。

关于 @anolilab/rc 的常见问题

@anolilab/rc 是什么?

The runtime configuration loader.

如何安装 @anolilab/rc?

在项目目录运行 npm install @anolilab/rc,或使用 pnpm add / yarn add / bun add。

@anolilab/rc 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@anolilab/rc 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@anolilab/rc 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js ^22.14.0 || >=24.10.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@anolilab/rc 可以商用吗?

@anolilab/rc 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@anolilab/rc 的下载量有多少?

根据 npm 官方下载统计,@anolilab/rc 在 2026/10/06 – 2026/11/04 这 30 天内被下载 109,813 次,日均约 3,660 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@anolilab/rc 还在维护吗?

最新版本 4.0.9 发布于 2026/09/09(1 个月前);至今共发布 34 个版本,其中过去 12 个月发布了 16 个;首次发布于 2024/05/23。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。