/
Damber
/
hakaton_telegram
Обзор
Документация
Войти
/
Damber
/
hakaton_telegram
Код
Запросы
0
Задачи
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
classes/CustomDocument.js
34 строки
1012 B
Nikita
fix: errors
22 сен 2024, 09:25
22 сен 2024, 09:25
c4d16ba
Код
Авторство
О чём код?
import * as fs from "fs"; import mammoth from 'mammoth' import {parse} from 'himalaya' export class CustomDocument { docJson docText bufferFile options = { styleMap: [ "p[style-name='Section Title'] => h1:fresh", "p[style-name='Subsection Title'] => h2:fresh", // "b => p:fresh", // "a => p:fresh", ] }; // constructor(file='.assets/file_2.docx') { // this.bufferFile = fs.readFileSync(file); // } constructor(buffer) { this.bufferFile = buffer; } async readDocument() { const html = await mammoth.convertToHtml({buffer: this.bufferFile}, this.options) const res = await mammoth.extractRawText({buffer: this.bufferFile}) if(res.value) this.docText = res.value this.docJson = await parse(html.value) } static async readCustomDocument(path) { const res = await mammoth.extractRawText({path: path}) if(res.value) return res.value } }