UNPKG

1.43 kBSource Map (JSON)View Raw
1{"version":3,"sources":["../../lib/file-exists.ts"],"names":["fileExists","fileName","type","stats","promises","stat","isFile","isDirectory","access","constants","F_OK","err","code"],"mappings":"mEAAA,sBAEO,cAAeA,CAAAA,UAAf,CACLC,QADK,CAELC,IAFK,CAGa,CAClB,GAAI,CACF,GAAIA,IAAI,GAAK,MAAb,CAAqB,CACnB,KAAMC,CAAAA,KAAK,CAAG,KAAMC,cAASC,IAAT,CAAcJ,QAAd,CAApB,CACA,MAAOE,CAAAA,KAAK,CAACG,MAAN,EAAP,CACD,CAHD,IAGO,IAAIJ,IAAI,GAAK,WAAb,CAA0B,CAC/B,KAAMC,CAAAA,KAAK,CAAG,KAAMC,cAASC,IAAT,CAAcJ,QAAd,CAApB,CACA,MAAOE,CAAAA,KAAK,CAACI,WAAN,EAAP,CACD,CAHM,IAGA,CACL,KAAMH,cAASI,MAAT,CAAgBP,QAAhB,CAA0BQ,cAAUC,IAApC,CAAN,CACD,CACD,MAAO,KAAP,CACD,CAAC,MAAOC,GAAP,CAAY,CACZ,GAAIA,GAAG,CAACC,IAAJ,GAAa,QAAb,EAAyBD,GAAG,CAACC,IAAJ,GAAa,cAA1C,CAA0D,CACxD,MAAO,MAAP,CACD,CACD,KAAMD,CAAAA,GAAN,CACD,CACF","sourcesContent":["import { constants, promises } from 'fs'\n\nexport async function fileExists(\n fileName: string,\n type?: 'file' | 'directory'\n): Promise<boolean> {\n try {\n if (type === 'file') {\n const stats = await promises.stat(fileName)\n return stats.isFile()\n } else if (type === 'directory') {\n const stats = await promises.stat(fileName)\n return stats.isDirectory()\n } else {\n await promises.access(fileName, constants.F_OK)\n }\n return true\n } catch (err) {\n if (err.code === 'ENOENT' || err.code === 'ENAMETOOLONG') {\n return false\n }\n throw err\n }\n}\n"]}
\No newline at end of file