The "@humanwhocodes/config-array" is a JavaScript package that manages configurations based on glob-pattern matching of filenames. Created by Nicholas C. Zakas, this package helps streamline the process of configuration that may get complicated over time. It is capable of representing all configurations, including overrides, by a single array where each item is a config object. Glob patterns within files
and ignores
properties from each config object are used to calculate a configuration for a given file.
To use the "@humanwhocodes/config-array", first, you need to install the package through either npm or Yarn:
npm install @humanwhocodes/config-array --save
or
yarn add @humanwhocodes/config-array
Then, you can import the ConfigArray
constructor and create a new instance by passing in an array of configs and an options object:
import { ConfigArray } from "@humanwhocodes/config-array";
const configFilename = path.resolve(process.cwd(), "my.config.js");
const { default: rawConfigs } = await import(configFilename);
const configs = new ConfigArray(rawConfigs, {
basePath: process.cwd(),
schema: mySchema
});
To normalize your configuration array before use, call the normalize()
method and pass in a context object:
await configs.normalize({
name: "MyApp"
});
You can use the getConfig()
method on the normalized array and pass on the filename to get a config for:
const fileConfig = configs.getConfig(path.resolve(process.cwd(), "package.json"));
The "@humanwhocodes/config-array" doesn't have separate documentation. All information on how to use this package can be found directly in the readme file on its GitHub project page here. This includes examples of different ways for specifying schemas, determining ignored paths and employing caching mechanisms, etc., are all comprehensively contained in the readme.