Add some more argument validation

This commit is contained in:
David Payr
2024-12-29 02:21:54 +01:00
parent b7d8c526da
commit cc87dbfcf9
12 changed files with 340 additions and 39 deletions
+10
View File
@@ -24,6 +24,16 @@ export class Input {
_format: InputFormat | null = null;
constructor(options: InputOptions) {
if (!options || typeof options !== 'object') {
throw new TypeError('options must be an object.');
}
if (!Array.isArray(options.formats) || options.formats.some(x => !(x instanceof InputFormat))) {
throw new TypeError('options.formats must be an array of InputFormat.');
}
if (!(options.source instanceof Source)) {
throw new TypeError('options.source must be a Source.');
}
this._formats = options.formats;
this._source = options.source;
this._mainReader = new Reader(options.source);