Download backend/src/utils.ts from tfrere-projects/research-article-template-editor2: direct link, hf CLI and curl.
- Browser
- Download file 780 Bytes
-
https://huggingface.co/spaces/tfrere-projects/research-article-template-editor2/resolve/main/backend/src/utils.ts
- Command line
-
hf download hf://spaces/tfrere-projects/research-article-template-editor2/backend/src/utils.ts
-
curl -L -o utils.ts https://huggingface.co/spaces/tfrere-projects/research-article-template-editor2/resolve/main/backend/src/utils.ts
780 Bytes
| import { join, dirname } from "path"; | |
| import { fileURLToPath } from "url"; | |
| const __dirname = dirname(fileURLToPath(import.meta.url)); | |
| const DEFAULT_DATA_DIR = join(__dirname, "..", "data"); | |
| let _dataDir: string | undefined; | |
| /** Override DATA_DIR for testing. Pass undefined to reset to default. */ | |
| export function setDataDir(dir: string | undefined) { | |
| _dataDir = dir; | |
| } | |
| export function getDataDir(): string { | |
| return _dataDir ?? process.env.DATA_DIR ?? DEFAULT_DATA_DIR; | |
| } | |
| /** @deprecated Use getDataDir() instead */ | |
| export const DATA_DIR = DEFAULT_DATA_DIR; | |
| export function sanitizeName(name: string): string { | |
| return name.replace(/[^a-zA-Z0-9_-]/g, "_"); | |
| } | |
| export function docPath(name: string): string { | |
| return join(getDataDir(), `${sanitizeName(name)}.yjs`); | |
| } | |