Options
All
  • Public
  • Public/Protected
  • All
Menu

better-path-join — Reference

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

Generated using TypeDoc