Spaces:
Paused
Paused
Download node_modules/@huggingface/hub/src/utils/sub-paths.ts from Leon4gr45/nova-header-nav: direct link, hf CLI and curl.
- Browser
- Download file 949 Bytes
-
https://huggingface.co/spaces/Leon4gr45/nova-header-nav/resolve/main/node_modules/%40huggingface/hub/src/utils/sub-paths.ts
- Command line
-
hf download hf://spaces/Leon4gr45/nova-header-nav/node_modules/@huggingface/hub/src/utils/sub-paths.ts
-
curl -L -o sub-paths.ts https://huggingface.co/spaces/Leon4gr45/nova-header-nav/resolve/main/node_modules/%40huggingface/hub/src/utils/sub-paths.ts
949 Bytes
| import { readdir, stat } from "node:fs/promises"; | |
| import { fileURLToPath, pathToFileURL } from "node:url"; | |
| /** | |
| * Recursively retrieves all sub-paths of a given directory up to a specified depth. | |
| */ | |
| export async function subPaths( | |
| path: URL, | |
| maxDepth = 10, | |
| ): Promise< | |
| Array<{ | |
| path: URL; | |
| relativePath: string; | |
| }> | |
| > { | |
| const state = await stat(path); | |
| if (!state.isDirectory()) { | |
| return [{ path, relativePath: "." }]; | |
| } | |
| const files = await readdir(path, { withFileTypes: true }); | |
| const ret: Array<{ path: URL; relativePath: string }> = []; | |
| for (const file of files) { | |
| const filePath = pathToFileURL(fileURLToPath(path) + "/" + file.name); | |
| if (file.isDirectory()) { | |
| ret.push( | |
| ...(await subPaths(filePath, maxDepth - 1)).map((subPath) => ({ | |
| ...subPath, | |
| relativePath: `${file.name}/${subPath.relativePath}`, | |
| })), | |
| ); | |
| } else { | |
| ret.push({ path: filePath, relativePath: file.name }); | |
| } | |
| } | |
| return ret; | |
| } | |