UNPKG

nuxt-openapi-docs-module

Version:

A module for Nuxt.js to generate pages from OpenAPI specifications

21 lines (20 loc) 549 B
import fs from "fs"; import { extname, join } from "path"; import * as yaml from "js-yaml"; import fetch from "sync-fetch"; export class FileHandler { loadYamlFile(folder, fileName) { let yamlData = ""; if (fileName.startsWith("http")) { yamlData = fetch(fileName).text(); } else { const extension = extname(fileName); if (!extension) { fileName += ".yaml"; } const filePath = join(folder, fileName); yamlData = fs.readFileSync(filePath, "utf8"); } return yaml.load(yamlData); } }