Skip to content

Commit 7084141

Browse files
authored
docs: update docs with options type and examples (#19)
1 parent 8dda4d4 commit 7084141

2 files changed

Lines changed: 47 additions & 17 deletions

File tree

README.md

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -39,34 +39,45 @@ npm add browserslist-load-config -D
3939

4040
### loadConfig
4141

42-
```ts
43-
import { loadConfig } from "browserslist-load-config";
42+
Loads the browserslist configuration from the specified file or directory, returns the browserslist config of specified environment.
4443

45-
// Pass a path to the configuration file
46-
const config = loadConfig({
44+
- **Type:**
45+
46+
```ts
47+
type LoadConfigOptions = {
48+
/**
49+
* Specify the path to the configuration file
50+
* If both `config` and `path` are provided, `config` will be used
51+
*/
52+
config?: string;
4753
/**
4854
* Specify the directory where the configuration file is located
4955
*/
50-
path: "./path/to/project/root",
51-
56+
path?: string;
5257
/**
5358
* Specify the environment to load
5459
* @default "production"
5560
*/
61+
env?: string;
62+
};
63+
64+
function loadConfig(opts: LoadConfigOptions): string[] | undefined;
65+
```
66+
67+
- **Example:**
68+
69+
```ts
70+
import { loadConfig } from "browserslist-load-config";
71+
72+
// Pass a path to the configuration file
73+
const config = loadConfig({
74+
path: "./path/to/project/root",
5675
env: "production",
5776
});
5877

5978
// Pass a browserslist config directly
6079
const config = loadConfig({
61-
/**
62-
* Specify the directory where the configuration file is located
63-
*/
64-
path: "./path/to/project/root",
65-
66-
/**
67-
* Specify the environment to load
68-
* @default "production"
69-
*/
80+
config: "./path/to/project/root/.browserslistrc",
7081
env: "production",
7182
});
7283

@@ -78,10 +89,18 @@ console.log(config);
7889
*/
7990
```
8091

81-
If both `config` and `path` are provided, `config` will be used.
82-
8392
### findConfig
8493

94+
Finds the browserslist configuration file in the specified directory, returns the resolved browserslist config object.
95+
96+
- **Type:**
97+
98+
```ts
99+
function findConfig(from: string): Record<string, string[]> | undefined;
100+
```
101+
102+
- **Example:**
103+
85104
```ts
86105
import { findConfig } from "browserslist-load-config";
87106

src/index.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,19 @@ export function findConfig(from: string): Record<string, string[]> | undefined {
216216
}
217217

218218
export type LoadConfigOptions = {
219+
/**
220+
* Specify the path to the configuration file
221+
* If both `config` and `path` are provided, `config` will be used
222+
*/
219223
config?: string;
224+
/**
225+
* Specify the directory where the configuration file is located
226+
*/
220227
path?: string;
228+
/**
229+
* Specify the environment to load
230+
* @default "production"
231+
*/
221232
env?: string;
222233
};
223234

0 commit comments

Comments
 (0)