rcfy
TypeScript icon, indicating that this package has built-in type declarations

2.1.0 • Public • Published

rcfy

Finds and loads runtime-configuration file for the current project, with precedence.

Install

npm i rcfy
# or
yarn add rcfy

Usage

This package is pure ESM, please read the esm-package.

import { findRc, loadRc } from 'rcfy'

const rcFile = await findRc('myproject')
// => root/to/project/.myproject.js

const rc = await loadRc('myproject')
// => { ... }

API

findRc

findRc(name, cwd?): Promise<string | undefined>

Finds runtime-configuration file.

import { findRc } from 'rcfy'

const rcFile = await findRc('myproject', './config')
// will finds:
// - `.myprojectrc` file in the `./config` directory.
// - `.myprojectrc.json` file in the `./config` directory.
// - `.myprojectrc.{yaml,yml}` file in the `./config` directory.
// - `.myproject.{mjs,cjs,js}` file in the `./config` directory.
// - `myproject.config.{mjs,cjs,js}` file in the `./config` directory.

Parameters

Name Type
name string
cwd string

Returns

Promise<string | undefined>


loadRc

loadRc<T = any>(name, cwd?, ...args): Promise<T>

Loads runtime-configuration file, with precedence.

import { loadRc } from 'rcfy'

const rc = await loadRc('myproject')
// will try to loads config from:
// - `myproject` field in the `package.json` file.
// - `.myprojectrc` file in the `cwd`.
// - `.myprojectrc.json` file in the `cwd`.
// - `.myprojectrc.{yaml,yml}` file in the `cwd`.
// - `.myproject.{mjs,cjs,js}` file in the `cwd`.
// - `myproject.config.{mjs,cjs,js}` file in the `cwd`.

Note: Config that found in the package.json will be merged with higher precedence.

Parameters

Name Type
name string
cwd string
...args any[]

Returns

Promise<T>


findRcSync

findRcSync(name, cwd?): string | undefined

Finds runtime-configuration file synchronously.

import { findRcSync } from 'rcfy'

const rcFile = findRcSync('myproject', './config')
// will finds:
// - `.myprojectrc` file in the `./config` directory.
// - `.myprojectrc.json` file in the `./config` directory.
// - `.myprojectrc.{yaml,yml}` file in the `./config` directory.
// - `.myproject.{cjs,js}` file in the `./config` directory.
// - `myproject.config.{cjs,js}` file in the `./config` directory.

Parameters

Name Type
name string
cwd string

Returns

string | undefined


loadRcSync

loadRcSync<T = any>(name, cwd?, ...args): T | Promise<T>

Loads runtime-configuration file synchronously, with precedence.

import { loadRcSync } from 'rcfy'

const rc = loadRcSync('myproject')
// will try to loads config from:
// - `myproject` field in the `package.json` file.
// - `.myprojectrc` file in the `cwd`.
// - `.myprojectrc.json` file in the `cwd`.
// - `.myprojectrc.{yaml,yml}` file in the `cwd`.
// - `.myproject.{cjs,js}` file in the `cwd`.
// - `myproject.config.{cjs,js}` file in the `cwd`.

Note: Config that found in the package.json will be merged with higher precedence.

Parameters

Name Type
name string
cwd string
...args any[]

Returns

T | Promise<T>

Related

  • loadee – A utility to simplify the loading of YAML, JSON, and JS files.

Contributing

We 💛  issues.

When committing, please conform to the semantic-release commit standards. Please install commitizen and the adapter globally, if you have not already.

npm i -g commitizen cz-conventional-changelog

Now you can use git cz or just cz instead of git commit when committing. You can also use git-cz, which is an alias for cz.

git add . && git cz

License

GitHub

A project by Stilearning © 2022-2024.

Dependencies (1)

Dev Dependencies (4)

Package Sidebar

Install

npm i rcfy

Weekly Downloads

2

Version

2.1.0

License

MIT

Unpacked Size

12.7 kB

Total Files

8

Last publish

Collaborators

  • bent10