yaml-js-include
Version:
Extension for yaml-js library to be able to include files/directories in yaml files
58 lines (57 loc) • 2.67 kB
TypeScript
/// <reference types="node" />
import * as yaml from 'js-yaml';
import { IncludeDirOptions } from './dir';
import { IncludeDirSeqOptions } from './seq';
/** A wrapper around YAML loader to enable including of files or directories */
export declare class YamlInclude {
private readonly _directoryOptions?;
private readonly _seqOptions?;
private readonly _encoding;
private _baseFile;
/**
* Creates a new instance
* @param _directoryOptions Default options for directory include
* @param _seqOptions Default options for directory as array include
* @param _encoding Encoding of files.
*/
constructor(_directoryOptions?: Partial<IncludeDirOptions>, _seqOptions?: Partial<IncludeDirSeqOptions>, _encoding?: BufferEncoding);
/**
* Reads a YAML file and parses it's content using include schema
* @param filePath Path to the file to read
* @param baseSchema Determines the base schema for YAML parse. @default yaml.DEFAULT_SCHEMA
* @typeParam T - Type of the expected result object
* @returns Parsed file content
*/
load<T>(filePath: string, baseSchema?: yaml.Schema): T;
/**
* Reads a YAML file asynchronously and parses it's content using include schema
* @param filePath Path to the file to read
* @param baseSchema Determines the base schema for YAML parse. @default yaml.DEFAULT_SCHEMA
* @typeParam T - Type of the expected result object
* @returns Parsed file content
*/
loadAsync<T>(filePath: string, baseSchema?: yaml.Schema): Promise<T>;
/**
* Parses a YAML content using include schema
* @param src YAML as string
* @param basePath Base path for the include schema
* @param baseSchema Determines the base schema for YAML parse. @default yaml.DEFAULT_SCHEMA
* @typeParam T - Type of the expected result object
* @returns Parsed file content
*/
parse<T>(src: string, basePath: string, baseSchema?: yaml.Schema): T;
/** Sets a base file path for resolving files or directories */
set basePath(filePath: string);
/** Gets a base file path for resolving files or directories */
get basePath(): string;
/** Gets default encoding for reading the files */
get encoding(): BufferEncoding;
/** Gets default directory include options */
get directoryOptions(): Partial<IncludeDirOptions> | undefined;
/** Gets default directory as array include options */
get seqOptions(): Partial<IncludeDirSeqOptions> | undefined;
/** Gets include types for the YAML schema */
get types(): yaml.Type[];
/** Gets a schema for YAML */
get schema(): yaml.Schema;
}