Skip to main content
torch.js has not been released yet.
torch.js logotorch.js logotorch.js
PlaygroundContact
Login
Documentation
IntroductionType SafetyTensor ExpressionsTensor IndexingEinsumEinopsAutogradTraining a ModelProfiling & MemoryPyTorch MigrationBest PracticesRuntimesPerformancePyTorch CompatibilityBenchmarksDType Coverage
torch.js· 2026
LegalTerms of UsePrivacy Policy
/
/
  1. docs
  2. Spark
  3. spark
  4. parsePath

spark.parsePath

function parsePath(path: string): { username: string; project: string; filename: string }

Parse a torchjs.org file path into username, project, and filename components.

Files on torchjs.org use a hierarchical path format: username/project/path/to/file. This function splits the path into its components for validation and URL building.

This is a utility function used internally. In most cases, you'll pass paths directly to functions like load, save, or exists.

Parameters

pathstring
Path in format "username/project/filename" or "username/project/path/to/file" - Leading slashes are optional and will be removed - Must contain at least username and project (3 parts minimum)

Returns

{ username: string; project: string; filename: string }– Object containing parsed path components: - username - The user who owns the file - project - The project containing the file - filename - The relative path within the project (can contain subdirectories)

Examples

// Parse a simple filename
const { username, project, filename } = spark.parsePath('kasumi/mnist/model.pt');
// Result: { username: 'kasumi', project: 'mnist', filename: 'model.pt' }

// Parse nested path
const result = spark.parsePath('kasumi/gpt2/checkpoints/epoch-10.pt');
// Result: { username: 'kasumi', project: 'gpt2', filename: 'checkpoints/epoch-10.pt' }

// Leading slash is optional
const result2 = spark.parsePath('/kasumi/mnist/weights.pt');
// Result: { username: 'kasumi', project: 'mnist', filename: 'weights.pt' }
Previous
MessageTarget
Next
RpcHandler