@micrio/tiler-base
Version:
The base Micrio client-side tiler package used by the Micrio CLI and GUI tools
27 lines (26 loc) • 945 B
JavaScript
import { promises as fs } from 'node:fs';
import path from 'path';
export const sanitize = (f, outDir) => f.replace(/\\+/g, '/').replace(outDir + '/', '');
/** Check if a file exists */
export const fsExists = async (filePath) => {
try {
await fs.access(filePath);
return true; // File exists
}
catch (error) {
return false; // File does not exist
}
};
/** Walk through a directory and all of its recursive subdirectories and return all files in it */
export async function walkSync(name) {
const ret = [], entry = await fs.lstat(name).catch(() => { });
if (entry)
if (entry.isDirectory())
for (const file of await fs.readdir(name))
ret.push(...await walkSync(path.join(name, file)));
else
ret.push(name);
return ret;
}
/** Convert a julian date to a timestamp */
export const jdToTime = (jd) => Math.floor((jd - 2440587.5) * 86400000);