Major updates to core

This commit is contained in:
Logan Cusano
2024-02-10 15:10:35 -05:00
parent d563021866
commit 9c46792959
22 changed files with 977 additions and 156 deletions

View File

@@ -1,5 +1,7 @@
import { networkInterfaces } from 'os';
import { createHash, randomBytes } from 'crypto';
import { promises, constants } from 'fs';
import { dirname } from "path";
/**
* Check to see if the input is a valid JSON string
@@ -7,7 +9,7 @@ import { createHash, randomBytes } from 'crypto';
* @param {*} str The string to check for valud JSON
* @returns {true|false}
*/
export function isJsonString (str) {
export const isJsonString = (str) => {
try {
JSON.parse(str);
} catch (e) {
@@ -16,12 +18,25 @@ export function isJsonString (str) {
return true;
}
/**
* Check to see if a path exists, creating it if it does not
* @returns {undefined}
*/
export const ensureDirectoryExists = async (filePath) => {
const directory = dirname(filePath);
try {
await promises.access(directory, constants.F_OK);
} catch (error) {
await promises.mkdir(directory, { recursive: true });
}
};
/**
* Generate a unique ID for a given device, this will also be unique on the same device at a different time.
* @returns {string} A generated unique ID
*/
export function generateUniqueID () {
export const generateUniqueID = () => {
const netInterfaces = networkInterfaces();
let macAddress = '';