Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

better-path-join

ksxnodeapps14MIT0.0.3TypeScript support: included

Like path.join but takes absolute path into account

path, join, absolute

readme

Better path.join

Like path.join but takes absolute path into account.

What is wrong with built-in path.join?

It does not produce accurate path when non-first argument is an absolute path.

Usage

APIs

declare function createJoinFunction (pathModule: {
  isAbsolute (): boolean
  join (left: string, right: string): string
}): (left: string, right: string) => string

Example

import path from 'path'
import createJoinFunction from 'better-path-join'
const join = createJoinFunction(path)
console.log('relative', join('abc/def', 'foo/bar'))
console.log('absolute', join('abc/def', '/foo/bar'))

Output:

relative abc/def/foo/bar
absolute /foo/bar

License

MIT © Hoàng Văn Khải