UNPKG

cfdi40

Version:

Libreria para crear y sellar xml cfdi V4.0

62 lines (54 loc) 1.1 kB
'use strict' const fs = require('fs') class FileSystem{ /** * * @param action */ static manageDirectoryTemp (action) { const dir = './tmp' if (!fs.existsSync(dir)){ if (action === 'create') { fs.mkdirSync(dir) } } else { if (action === 'delete') { FileSystem.deleteFolderRecursive(dir) } } } /** * * @param path */ static deleteFolderRecursive (path) { if (fs.existsSync(path)) { fs.readdirSync(path).forEach((file, index) => { const curPath = path + '/' + file if (fs.lstatSync(curPath).isDirectory()) { deleteFolderRecursive(curPath) } else { fs.unlinkSync(curPath) } }) fs.rmdirSync(path) } } /** * * @returns {string} */ static generateNameTemp () { let fileNameTemp = Math.floor(100000 + Math.random() * 900000) return fileNameTemp.toString() } /** * * @param file * @returns {*} */ static readFileSync (file) { return fs.readFileSync(file, 'utf8') } } module.exports = FileSystem