UNPKG

dir-is-case-sensitive

Version:

Returns true, if the specified directory is case sensitive

38 lines 999 B
import { promises as fs } from 'fs'; import { pathTemp } from 'path-temp'; export async function dirIsCaseSensitive(dir, silent = true) { const tempFile = pathTemp(dir).toLowerCase(); try { await fs.writeFile(tempFile, '', 'utf8'); } catch (err) { if (silent) { return; } throw err; } try { await fs.stat(tempFile.toUpperCase()); // If the file in different casing is FOUND, // then the directory is case insensitive return false; } catch (err) { if (err.code === 'ENOENT') { // If the file in different casing is NOT FOUND, // then the directory is case sensitive return true; } if (silent) { return; } throw err; } finally { // The temp file is removed fs.unlink(tempFile).catch((err) => { // Errors are ignored }); } } //# sourceMappingURL=index.js.map