@oazmi/kitchensink - v0.9.13
    Preparing search index...

    Function ensureDir

    • creates a nested directory if it does not already exist. only supported on system runtime (i.e. RUNTIME.DENO, RUNTIME.BUN, or RUNTIME.NODE).

      Parameters

      • runtime_enum: RUNTIME
      • dir_path: string | URL

      Returns Promise<void>

      an error is thrown if something other than a folder already existed at the provided path.

      import { assertEquals, assertObjectMatch } from "jsr:@std/assert"

      const
      runtime_id = identifyCurrentRuntime(),
      my_dir = new URL(import.meta.resolve("../temp/a/b/c/")),
      my_dir2 = new URL(import.meta.resolve("../temp/a/"))

      await ensureDir(runtime_id, my_dir)

      // the directory now exists
      assertObjectMatch((await statEntry(runtime_id, my_dir))!, {
      isFile: false,
      isDirectory: true,
      isSymlink: false,
      })

      // deleting the base directory (recursively)
      assertEquals(await removeEntry(runtime_id, my_dir2, { recursive: true }), true)

      // the directory no longer exists
      assertEquals(await statEntry(runtime_id, my_dir), undefined)
      assertEquals(await statEntry(runtime_id, my_dir2), undefined)