Buckets:
| import path from "path" | |
| import { createContext, useContext, type ParentProps } from "solid-js" | |
| import { abbreviateHome } from "../runtime" | |
| import { useTuiPaths } from "./runtime" | |
| const context = createContext<{ | |
| path: () => string | |
| format: (input?: string) => string | |
| }>() | |
| export function PathFormatterProvider(props: ParentProps<{ path: string | undefined }>) { | |
| const paths = useTuiPaths() | |
| return ( | |
| <context.Provider | |
| value={{ | |
| path: () => props.path || paths.cwd, | |
| format: (input) => formatPath(input, props.path || paths.cwd, paths.home), | |
| }} | |
| > | |
| {props.children} | |
| </context.Provider> | |
| ) | |
| } | |
| export function usePathFormatter() { | |
| const value = useContext(context) | |
| if (!value) throw new Error("PathFormatter context must be used within a PathFormatterProvider") | |
| return value | |
| } | |
| function formatPath(input: string | undefined, base: string, home: string) { | |
| if (typeof input !== "string" || !input) return "" | |
| const absolute = path.isAbsolute(input) ? input : path.resolve(base, input) | |
| const relative = path.relative(base, absolute) | |
| if (!relative) return "." | |
| if (relative !== ".." && !relative.startsWith(".." + path.sep)) return relative | |
| return abbreviateHome(absolute, home) | |
| } | |
Xet Storage Details
- Size:
- 1.24 kB
- Xet hash:
- 5ac1f34f64448a9cbd451651e5e749f3110065d655bb3bda3cf58b52df88dbb6
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.