Socket
Socket
Sign inDemoInstall

c12

Package Overview
Dependencies
7
Maintainers
1
Versions
40
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.1.0 to 0.1.1

22

dist/index.d.ts

@@ -37,7 +37,14 @@ interface DotenvOptions {

declare type ConfigT = Record<string, any>;
interface LoadConfigOptions<T extends ConfigT = ConfigT> {
interface InputConfig extends Record<string, any> {
}
interface ResolvedConfig<T extends InputConfig = InputConfig> {
config: T;
cwd: string;
configFile: string;
layers: ResolvedConfig<T>[];
}
interface LoadConfigOptions<T extends InputConfig = InputConfig> {
name?: string;
cwd?: string;
configFile?: false | string;
configFile?: string;
rcFile?: false | string;

@@ -49,9 +56,4 @@ globalRc?: boolean;

}
interface ResolvedConfig<T extends ConfigT = ConfigT> {
config: T;
configPath?: string;
env?: Record<string, any>;
}
declare function loadConfig<T extends ConfigT = ConfigT>(opts: LoadConfigOptions<T>): Promise<ResolvedConfig<T>>;
declare function loadConfig<T extends InputConfig = InputConfig>(opts: LoadConfigOptions<T>): Promise<ResolvedConfig<T>>;
export { ConfigT, DotenvOptions, Env, LoadConfigOptions, ResolvedConfig, loadConfig, loadDotenv, setupDotenv };
export { DotenvOptions, Env, InputConfig, LoadConfigOptions, ResolvedConfig, loadConfig, loadDotenv, setupDotenv };
{
"name": "c12",
"version": "0.1.0",
"version": "0.1.1",
"description": "Smart Config Loader",

@@ -32,2 +32,3 @@ "repository": "unjs/c12",

"dotenv": "^14.3.2",
"gittar": "^0.1.1",
"jiti": "^1.12.14",

@@ -34,0 +35,0 @@ "mlly": "^0.4.1",

@@ -8,3 +8,3 @@ # c12

> Smart Config Loader
> Smart Configuration Loader

@@ -17,2 +17,3 @@ ## Features

- `.env` support with [dotenv](https://www.npmjs.com/package/dotenv)
- Support extending nested configurations from multiple local or git sourecs

@@ -47,3 +48,7 @@ ## Usage

```js
// Get loaded config
const { config } = await loadConfig({})
// Get resolved config and extended layers
const { config, configFile, layers } = await loadConfig({})
```

@@ -60,2 +65,3 @@

5. default config passed by options
6. Extended config layers

@@ -100,2 +106,81 @@ ## Options

## Extending configuration
If resolved config contains a `extends` key, it will be used to extend configuration.
Extending can be nested and each layer can extend from one base or more.
Final config is merged result of extended options and user options with [unjs/defu](https://github.com/unjs/defu).
Each item in extends, is a string that can be either an absolute or relative path to current config file pointing to a config file for extending or directory containing config file.
If it starts with either of `github:`, `gitlab:`, `bitbucket:` or `https:`, c12 autmatically clones it.
For custom merging strategies, you can directly access each layer with `layers` property.
**Example:**
```js
// config.ts
export default {
colors: {
primary: 'user_primary'
},
extends: [
'./theme',
'./config.dev.ts'
]
}
```
```js
// config.dev.ts
export default {
dev: true
}
```
```js
// theme/config.ts
export default {
extends: '../base',
colors: {
primary: 'theme_primary',
secondary: 'theme_secondary'
}
}
```
```js
// base/config.ts
export default {
colors: {
primary: 'base_primary'
text: 'base_text'
}
}
```
Loaded configuration would look like this:
```js
{
dev: true,
colors: {
primary: 'user_primary',
secondary: 'theme_secondary',
text: 'base_text'
}
}
```
Layers:
```js
[
{ config: /* theme config */, configFile: /* path/to/theme/config.ts */, cwd: /* path/to/theme */ },
{ config: /* base config */, configFile: /* path/to/base/config.ts */, cwd: /* path/to/base */ },
{ config: /* dev config */, configFile: /* path/to/config.dev.ts */, cwd: /* path/ */ },
]
```
## 💻 Development

@@ -102,0 +187,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc