@hyperfrontend/project-scope/core/pathpath
Cross-platform path manipulation utilities that normalize between POSIX and native (Windows) separators.
Grouped into four concerns: joining (join, joinPosix, joinPath), normalization (normalizePath, normalizeToForwardSlashes, normalizeToNative, trailing-slash helpers), resolution (resolvePath, resolveRealPath, resolveFromWorkspace, relativePath, offsetFromRoot, isAbsolute), and segment extraction (getDirname, getBasename, getExtension, getFileNameWithoutExtension, parsePath, pathSegments).
All functions emit forward-slash paths by default to keep downstream string comparisons portable across operating systems.
API Reference
ƒ Functions
Parameters
| Name | Type | Description |
|---|---|---|
§filePath | string | Path to process |
Returns
stringExample
Ensuring trailing slash
ensureTrailingSlash('src/components')
// => 'src/components/'
ensureTrailingSlash('already/has/')
// => 'already/has/'Parameters
Returns
stringExample
Getting basename
getBasename('src/components/Button.tsx')
// => 'Button.tsx'
getBasename('src/components/Button.tsx', '.tsx')
// => 'Button'Parameters
| Name | Type | Description |
|---|---|---|
§filePath | string | Path to extract directory from |
Returns
stringExample
Getting directory name
getDirname('src/components/Button.tsx')
// => 'src/components'Parameters
| Name | Type | Description |
|---|---|---|
§filePath | string | Path to extract extension from |
Returns
stringExample
Getting file extension
getExtension('src/utils/helpers.ts')
// => '.ts'
getExtension('package.json')
// => '.json'Parameters
| Name | Type | Description |
|---|---|---|
§filePath | string | Path to extract name from |
Returns
stringExample
Getting filename without extension
getFileNameWithoutExtension('src/utils/helpers.ts')
// => 'helpers'Parameters
| Name | Type | Description |
|---|---|---|
§filePath | string | Path to check |
Returns
booleanExample
Checking absolute path
isAbsolute('/workspace/src/index.ts')
// => true
isAbsolute('./src/index.ts')
// => falseParameters
| Name | Type | Description |
|---|---|---|
§...paths | string[] | Path segments to join |
Returns
stringExample
Joining path segments
const fullPath = join('src', 'components', 'Button.tsx')
// => 'src/components/Button.tsx' (or 'src\\components\\Button.tsx' on Windows)Parameters
| Name | Type | Description |
|---|---|---|
§...segments | string[] | Path segments to join |
Returns
stringExample
Joining path segments
joinPath('src', 'components', 'Button.tsx')
// => 'src/components/Button.tsx'Parameters
| Name | Type | Description |
|---|---|---|
§...paths | string[] | Path segments to join |
Returns
stringExample
Joining paths with forward slashes
const configPath = joinPosix('config', 'settings', 'app.json')
// => 'config/settings/app.json'Parameters
| Name | Type | Description |
|---|---|---|
§filePath | string | Path to normalize |
Returns
stringExample
Normalizing path separators
const path = normalizePath('src\\components\\Button.tsx')
// => 'src/components/Button.tsx'. and .. segments for cross-platform configuration.Parameters
| Name | Type | Description |
|---|---|---|
§filePath | string | The input path to convert |
Returns
stringExample
Converting to forward slashes
const path = normalizeToForwardSlashes('./src/../lib/utils')
// => 'lib/utils'Parameters
| Name | Type | Description |
|---|---|---|
§filePath | string | The input path to convert |
Returns
stringExample
Converting to native separators
const path = normalizeToNative('src/components/Button.tsx')
// => 'src\\components\\Button.tsx' on Windows
// => 'src/components/Button.tsx' on UnixParameters
| Name | Type | Description |
|---|---|---|
§filePath | string | Path to calculate offset for |
Returns
stringExample
Calculating offset from root
offsetFromRoot('libs/utils/src')
// => '../../../'
offsetFromRoot('apps')
// => '../'Parameters
| Name | Type | Description |
|---|---|---|
§filePath | string | Path to parse |
Returns
ParsedPathExample
Parsing path components
const parsed = parsePath('/workspace/src/index.ts')
// => { root: '/', dir: '/workspace/src', base: 'index.ts', ext: '.ts', name: 'index' }Parameters
| Name | Type | Description |
|---|---|---|
§filePath | string | Path to split |
Returns
string[]Example
Splitting path into segments
pathSegments('src/components/Button.tsx')
// => ['src', 'components', 'Button.tsx']Returns
stringExample
Computing relative path
relativePath('/workspace/src/utils', '/workspace/lib/helpers')
// => '../../lib/helpers'Parameters
| Name | Type | Description |
|---|---|---|
§filePath | string | Path that may have trailing slashes |
Returns
stringExample
Removing trailing slashes
removeTrailingSlash('src/components/')
// => 'src/components'
removeTrailingSlash('path\\to\\dir\\')
// => 'path\\to\\dir'Parameters
Returns
stringExample
Resolving from workspace root
const configPath = resolveFromWorkspace('/workspace', 'config', 'app.json')
// => '/workspace/config/app.json'Parameters
| Name | Type | Description |
|---|---|---|
§...segments | string[] | Path segments to resolve |
Returns
stringExample
Resolving to absolute path
const absPath = resolvePath('src', 'components', 'Button.tsx')
// => '/workspace/project/src/components/Button.tsx'Parameters
| Name | Type | Description |
|---|---|---|
§filePath | string | Path to resolve |
Returns
stringExample
Resolving symlinks
const realPath = resolveRealPath('./node_modules/.bin/tsc')
// => '/workspace/node_modules/typescript/bin/tsc'