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 fs from "fs"
export const Node = {
isFile: function(filename) {
export class Node {
static isFile = (filename) => {
try {
return fs.existsSync(filename)
} catch (err) {
@ -10,11 +11,13 @@ export const Node = {
return false
}
},
getFullPath: function(folderPath) {
}
static getFullPath = (folderPath) => {
return fs.readdirSync(folderPath).map(fn => path.join(folderPath, fn))
},
getFiles: function(dir) {
}
static getFiles = (dir) => {
var results = [];
var list = fs.readdirSync(dir);
list.forEach(function(file) {
@ -29,12 +32,13 @@ export const Node = {
}
});
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')
if (!Node.isFile(notesDir)) {
console.warn("Notes Directory does not seem to exist: ", notesDir)