@xcrap/factory
Version:
Xcrap Factory is a set of utilities for dynamically creating instances of clients, extractors, and parsing models, making it easier to configure and extend scraping and parsing pipelines.
13 lines (12 loc) • 468 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.createClient = createClient;
function createClient({ config: { allowedClients }, type, options }) {
if (!(type in allowedClients)) {
throw new Error(`'${type.toString()}' is not a valid type of client!`);
}
const clientClass = allowedClients[type];
const clientInstance = new clientClass(options);
return clientInstance;
}
exports.default = createClient;