{"version":3,"file":"exists.mjs","names":[],"sources":["../../../../../../@warlock.js/fs/src/exists.ts"],"sourcesContent":["import { access, stat } from \"node:fs/promises\";\nimport { accessSync, statSync } from \"node:fs\";\n\n/**\n * Check whether a path exists, REGARDLESS of type — resolves `true` for both\n * files and directories, `false` only when nothing is there (ENOENT).\n *\n * Pick the right check for the job:\n *   - `pathExistsAsync`      — anything at this path (file OR directory).\n *   - `fileExistsAsync`      — exists AND is a regular file.\n *   - `directoryExistsAsync` — exists AND is a directory.\n *\n * @example\n * if (await pathExistsAsync(\"/var/data\")) {\n *   // something is there — could be a file or a folder\n * }\n */\nexport async function pathExistsAsync(path: string): Promise<boolean> {\n  try {\n    await access(path);\n    return true;\n  } catch {\n    return false;\n  }\n}\n\nexport function pathExists(path: string): boolean {\n  try {\n    accessSync(path);\n    return true;\n  } catch {\n    return false;\n  }\n}\n\n/**\n * Check whether a path exists AND is a regular file. Resolves `false` for a\n * directory — use `directoryExistsAsync` for folders, or `pathExistsAsync`\n * when the type does not matter.\n *\n * @example\n * if (await fileExistsAsync(\"/etc/config.json\")) {\n *   const raw = await readFile(\"/etc/config.json\", \"utf8\");\n * }\n */\nexport async function fileExistsAsync(path: string): Promise<boolean> {\n  try {\n    return (await stat(path)).isFile();\n  } catch {\n    return false;\n  }\n}\n\nexport function fileExists(path: string): boolean {\n  try {\n    return statSync(path).isFile();\n  } catch {\n    return false;\n  }\n}\n\n/**\n * Check whether a path exists AND is a directory. Resolves `false` for a\n * regular file — use `fileExistsAsync` for files, or `pathExistsAsync` when\n * the type does not matter.\n *\n * @example\n * if (await directoryExistsAsync(\"/var/uploads\")) {\n *   const entries = await readdir(\"/var/uploads\");\n * }\n */\nexport async function directoryExistsAsync(path: string): Promise<boolean> {\n  try {\n    return (await stat(path)).isDirectory();\n  } catch {\n    return false;\n  }\n}\n\nexport function directoryExists(path: string): boolean {\n  try {\n    return statSync(path).isDirectory();\n  } catch {\n    return false;\n  }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAiBA,eAAsB,gBAAgB,MAAgC;CACpE,IAAI;EACF,MAAM,OAAO,IAAI;EACjB,OAAO;CACT,QAAQ;EACN,OAAO;CACT;AACF;AAEA,SAAgB,WAAW,MAAuB;CAChD,IAAI;EACF,WAAW,IAAI;EACf,OAAO;CACT,QAAQ;EACN,OAAO;CACT;AACF;;;;;;;;;;;AAYA,eAAsB,gBAAgB,MAAgC;CACpE,IAAI;EACF,QAAQ,MAAM,KAAK,IAAI,EAAC,CAAE,OAAO;CACnC,QAAQ;EACN,OAAO;CACT;AACF;AAEA,SAAgB,WAAW,MAAuB;CAChD,IAAI;EACF,OAAO,SAAS,IAAI,CAAC,CAAC,OAAO;CAC/B,QAAQ;EACN,OAAO;CACT;AACF;;;;;;;;;;;AAYA,eAAsB,qBAAqB,MAAgC;CACzE,IAAI;EACF,QAAQ,MAAM,KAAK,IAAI,EAAC,CAAE,YAAY;CACxC,QAAQ;EACN,OAAO;CACT;AACF;AAEA,SAAgB,gBAAgB,MAAuB;CACrD,IAAI;EACF,OAAO,SAAS,IAAI,CAAC,CAAC,YAAY;CACpC,QAAQ;EACN,OAAO;CACT;AACF"}