File: src/lib/joinPath.ts

Recommend this page to a friend!
  Classes of Dom Hastings   JS Webdav Client   src/lib/joinPath.ts   Download  
File: src/lib/joinPath.ts
Role: Auxiliary data
Content type: text/plain
Description: Auxiliary data
Class: JS Webdav Client
Access files of a Webdav server
Author: By
Last change:
Date: 8 months ago
Size: 765 bytes


Class file image Download
export const joinPath = (...pieces: string[]): string => leadingSlash( pieces .map(trimSlashes) .filter((piece) => piece) .join('/') ); export const leadingAndTrailingSlash = (text: string): string => leadingSlash(trailingSlash(text)); export const leadingSlash = (text: string): string => text.startsWith('/') ? text : `/${text}`; export const pathAndName = (path: string): [string, string] => { const pathParts = joinPath(path).split(/\//), file = pathParts.pop(); return [joinPath(...pathParts), file]; }; export const trailingSlash = (text: string): string => text.endsWith('/') ? text : `${text}/`; export const trimSlashes = (piece: string): string => piece.replace(/^\/+|\/+$/g, ''); export default joinPath;