2020-07-15 01:24:47 +00:00
|
|
|
'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');
|
2022-04-07 14:06:38 +00:00
|
|
|
const entries = file.split(/\n/).map((entry) => {
|
|
|
|
try {
|
|
|
|
return JSON.parse(entry);
|
|
|
|
} catch (error) {
|
|
|
|
return entry.trim();
|
|
|
|
}
|
|
|
|
}).filter(Boolean);
|
2020-07-15 01:24:47 +00:00
|
|
|
|
|
|
|
return entries;
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = getFileEntries;
|