Skip to content

delimitedPath

Custom delimiter path helpers (e.g. -- visual groups). Does not handle filesystem / \.

split: {"path":["chat","call"],"leaf":"voice-line"}
parent: chat--call
label: voice-line
belongsToPrefix: true

Signatures

typescript
function splitDelimitedPath(value: string, sep: string): DelimitedPathParts
function joinDelimitedPath(segments: readonly string[], sep: string): string
function delimitedPathParent(path: string, sep: string): string | null
function delimitedPathDisplayLabel(path: string, sep: string): string
function belongsToDelimitedPrefix(value: string, prefix: string, sep: string): boolean

Usage

typescript
import {
  splitDelimitedPath,
  joinDelimitedPath,
  delimitedPathParent,
  belongsToDelimitedPrefix,
} from '@zengchaowu/shared/functions/path/delimitedPath'

const sep = '--'
splitDelimitedPath('chat--call--voice-line', sep)
// { path: ['chat', 'call'], leaf: 'voice-line' }

joinDelimitedPath(['chat', 'call'], sep)
// 'chat--call'

delimitedPathParent('chat--call', sep)
// 'chat'

belongsToDelimitedPrefix('chat--call--voice-line', 'chat--call', sep)
// true

vs pathLastSegment

  • delimitedPath: explicit sep for business group paths
  • pathLastSegment / pathBasename: filesystem style with / and \