UNPKG

@xcrap/parser

Version:

Xcrap Parser is a package of the Xcrap framework, it was developed to take care of the data extraction part of text files (currently supporting only HTML and JSON) using declarative models.

23 lines (22 loc) 734 B
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Parser = void 0; const node_fs_1 = __importDefault(require("node:fs")); class Parser { constructor(source) { this.source = source; } async parseModel(parsingModel) { return await parsingModel.parse(this.source); } static async loadFile(path, options = { encoding: "utf-8" }) { const fileContent = await node_fs_1.default.promises.readFile(path, options); return Reflect.construct(this, [fileContent.toString()]); } } exports.Parser = Parser;