forked from DebaucheryLibrarian/traxxx
23 lines
421 B
JavaScript
Executable File
23 lines
421 B
JavaScript
Executable File
'use strict';
|
|
|
|
const fs = require('fs');
|
|
|
|
async function getFileEntries(location) {
|
|
if (!location) {
|
|
throw new Error('No filepath provided');
|
|
}
|
|
|
|
const file = await fs.promises.readFile(location, 'utf-8');
|
|
const entries = file.split(/\n/).map((entry) => {
|
|
try {
|
|
return JSON.parse(entry);
|
|
} catch (error) {
|
|
return entry.trim();
|
|
}
|
|
}).filter(Boolean);
|
|
|
|
return entries;
|
|
}
|
|
|
|
module.exports = getFileEntries;
|