convert node to static class

This commit is contained in:
Triston Armstrong 2023-12-25 22:03:37 -06:00
parent 84c657cffa
commit fd45def1bf

View File

@ -1,8 +1,9 @@
import path from 'path' import path from 'path'
import fs from "fs" import fs from "fs"
export const Node = { export class Node {
isFile: function(filename) {
static isFile = (filename) => {
try { try {
return fs.existsSync(filename) return fs.existsSync(filename)
} catch (err) { } catch (err) {
@ -10,11 +11,13 @@ export const Node = {
return false return false
} }
}, }
getFullPath: function(folderPath) {
static getFullPath = (folderPath) => {
return fs.readdirSync(folderPath).map(fn => path.join(folderPath, fn)) return fs.readdirSync(folderPath).map(fn => path.join(folderPath, fn))
}, }
getFiles: function(dir) {
static getFiles = (dir) => {
var results = []; var results = [];
var list = fs.readdirSync(dir); var list = fs.readdirSync(dir);
list.forEach(function(file) { list.forEach(function(file) {
@ -29,12 +32,13 @@ export const Node = {
} }
}); });
return results.filter(f => f.endsWith(".md")) return results.filter(f => f.endsWith(".md"))
}, }
readFileSync: function(fullPath) {
return fs.readFileSync(fullPath, "utf8")
},
getMarkdownFolder: function() { static readFileSync = (fullPath) => {
return fs.readFileSync(fullPath, "utf8")
}
static getMarkdownFolder = () => {
const notesDir = path.join(process.cwd(), 'notes') const notesDir = path.join(process.cwd(), 'notes')
if (!Node.isFile(notesDir)) { if (!Node.isFile(notesDir)) {
console.warn("Notes Directory does not seem to exist: ", notesDir) console.warn("Notes Directory does not seem to exist: ", notesDir)