read-ini
Version:
Read and parse INI or ENV files
43 lines (42 loc) • 1.44 kB
TypeScript
/**
* Type of data produced by `readIniFile` function.
*/
export type INI_Data<T> = {
[name: string]: T | {
[name: string]: T;
};
};
/**
* Full section name, which consist of the section name itself, plus optional alias.
*
* In this implementation, when a section alias is specified, it is used for namespace
* resolution instead of the section name.
*/
export type INI_Section = {
name: string;
alias?: string;
};
/**
* Callback type for optional value converter used by `readIniFile` function.
*
* Note that `section` is `undefined` when it is global.
*/
export type INI_ConvertCB<T> = (cb: {
key: string;
value: string;
section?: INI_Section;
}) => T;
/**
* Reads and parses an INI (or `./env`) file, with an optional value-type converter.
*
* - section `[name]` namespaces are supported:
* - When a section appears multiple times, its inner values are extended.
* - Sections called `global` (case-insensitive) expose global variables.
* - Sections support aliasing: `[section "alias"]`, with the alias used as
* override for the section name.
* - each variable must be in the form of `name = value`
* - spaces surrounding `=`, `value` or section names are ignored
* - the `value` is taken until the end of line
* - lines that start with `;` or `#` are skipped
*/
export declare function readIniFile<T = string>(iniFile: string, cb?: INI_ConvertCB<T>): INI_Data<T>;