Download next.js/packages/next/src/lib/file-exists.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 691 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/packages/next/src/lib/file-exists.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/next.js/packages/next/src/lib/file-exists.ts
-
curl -L -o file-exists.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/packages/next/src/lib/file-exists.ts
691 Bytes
| import { existsSync, promises } from 'fs' | |
| import isError from './is-error' | |
| export enum FileType { | |
| File = 'file', | |
| Directory = 'directory', | |
| } | |
| export async function fileExists( | |
| fileName: string, | |
| type?: FileType | |
| ): Promise<boolean> { | |
| try { | |
| if (type === FileType.File) { | |
| const stats = await promises.stat(fileName) | |
| return stats.isFile() | |
| } else if (type === FileType.Directory) { | |
| const stats = await promises.stat(fileName) | |
| return stats.isDirectory() | |
| } | |
| return existsSync(fileName) | |
| } catch (err) { | |
| if ( | |
| isError(err) && | |
| (err.code === 'ENOENT' || err.code === 'ENAMETOOLONG') | |
| ) { | |
| return false | |
| } | |
| throw err | |
| } | |
| } | |