UNPKG

@fastly/js-compute

Version:

JavaScript SDK and CLI for building JavaScript applications on [Fastly Compute](https://www.fastly.com/products/edge-compute/serverless).

29 lines (28 loc) 763 B
import { stat, rename, copyFile, unlink } from 'node:fs/promises'; export async function isFile(path) { const stats = await stat(path); return stats.isFile(); } export async function isDirectory(path) { const stats = await stat(path); return stats.isDirectory(); } export async function moveFile(src, dest) { try { await rename(src, dest); } catch (err) { if (!isErrnoException(err) || err.code !== 'EXDEV') { throw err; } // Cross-device move: copy + delete await copyFile(src, dest); await unlink(src); } } function isErrnoException(err) { return (typeof err === 'object' && err !== null && 'code' in err && typeof err.code === 'string'); }