diff options
| author | Ruben Beltran del Rio <git@r.bdr.sh> | 2024-02-14 16:58:56 +0100 |
|---|---|---|
| committer | Ruben Beltran del Rio <git@r.bdr.sh> | 2024-02-14 16:58:56 +0100 |
| commit | 6cd62e795e3716aa0cbd2d1ff8c1b3a345803563 (patch) | |
| tree | f35cfd157529d890d8d5e8e4280c9d44d77a5e01 /lib/utils.js | |
| parent | 02f408c24d82d1fac4e55c146c4fa57cbdcdeca4 (diff) | |
Use modules, use XDG dirs
Diffstat (limited to 'lib/utils.js')
| -rw-r--r-- | lib/utils.js | 48 |
1 files changed, 23 insertions, 25 deletions
diff --git a/lib/utils.js b/lib/utils.js index 24b9407..25d204a 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -1,36 +1,34 @@ -const { access, constants, mkdir, rm } = require('fs/promises'); -const { kFileNotFoundError } = require('./constants'); +import { access, constants, mkdir, rm } from 'fs/promises'; +import { kFileNotFoundError } from './constants.js'; // File system utilities -module.exports = { - async rmIfExists(location) { +export async function rmIfExists(location) { - try { - await access(location, constants.F_OK); - await rm(location, { recursive: true }); + try { + await access(location, constants.F_OK); + await rm(location, { recursive: true }); + } + catch (error) { + if (error.code === kFileNotFoundError) { + return; } - catch (error) { - if (error.code === kFileNotFoundError) { - return; - } - throw error; - } - }, + throw error; + } +} - async ensureDirectoryExists(directory) { +export async function ensureDirectoryExists(directory) { - try { - await access(directory); + try { + await access(directory); + } + catch (error) { + if (error.code === kFileNotFoundError) { + await mkdir(directory, { recursive: true }); + return; } - catch (error) { - if (error.code === kFileNotFoundError) { - await mkdir(directory, { recursive: true }); - return; - } - throw error; - } + throw error; } -}; +} |