wttp-core
Version:
Core contracts, interfaces, and TypeScript types for the Web3 Transfer Protocol (WTTP).
52 lines • 2.3 kB
TypeScript
/**
* Path normalization utilities for WTTP protocol
*
* These utilities handle the soft enforcement of web semantics by normalizing
* paths for consistent storage while preserving semantic meaning through headers.
*/
/**
* Normalizes a path by ensuring leading slash and handling trailing slashes based on directory status
*
* This implements "soft semantic enforcement" where:
* - Storage layer: Consistent, normalized paths with trailing slashes for directories
* - Presentation layer: Semantic trailing slashes preserved for directories
* - Behavior layer: Headers determine actual functionality (directory vs file)
*
* @param path - The path to normalize
* @param isDirectory - Optional flag indicating if the path represents a directory
* @returns Normalized path with trailing slash for directories (including root "/")
* @throws Error if path is malformed (multiple consecutive slashes, etc.)
*/
export declare function normalizePath(path: string, isDirectory?: boolean): string;
/**
* Checks if a path represents a directory based on trailing slash
* This is used for presentation/UX purposes only
*
* @param originalPath - The original path before normalization
* @returns True if the path had a trailing slash (indicating directory intent)
*/
export declare function pathIndicatesDirectory(originalPath: string): boolean;
export declare function pathIndicatesRelative(originalPath: string): boolean;
/**
* Adds trailing slash for display purposes when path represents a directory
* Used by client tools for UX consistency
*
* @param normalizedPath - The normalized path
* @param isDirectory - Whether this path should be displayed as a directory
* @returns Path with trailing slash added if it's a directory
*/
export declare function displayPath(normalizedPath: string, isDirectory?: boolean): string;
/**
* Edge case testing function - validates various path scenarios
* Used primarily for testing to ensure normalization handles edge cases
*
* @param testPath - Path to validate
* @returns Object with validation results
*/
export declare function validatePathEdgeCases(testPath: string, isDirectory?: boolean): {
isValid: boolean;
indicatesDirectory?: boolean;
normalized?: string;
error?: string;
};
//# sourceMappingURL=path.d.ts.map