UNPKG

docutils-ts

Version:

Port of the Python Docutils library to TypeScript

27 lines (26 loc) 783 B
import Input from './input.js'; import { fileSystem } from '../core.js'; export default class FileInput extends Input { constructor(args) { super(args); this.data = ''; } async read() { this.logger.silly('read'); const data = await fileSystem.readFile(this.sourcePath, { encoding: this.encoding || 'utf-8' }); return data.toString(); } async readlines() { this.logger.silly('readlines'); const data = await this.read(); if (typeof data === 'string') { return data.split('\n'); } else if (Array.isArray(data)) { return data; } else { return Promise.reject(new Error('FileInput: source is not a string or array')); } } }