resolvePath
浏览器端路径解析,模拟 nodejs path.resolve 行为
引入版本
0.95.0
Demo
ts
import { resolvePath } from '@wyfex/iutils'
console.log(resolvePath('/a', 'b', '../c')) // "/a/c"
console.log(resolvePath('a/b', '../d')) // "a/d"
console.log(resolvePath('/foo', 'bar', '/baz', 'qux')) // "/baz/qux"
console.log(resolvePath('a//b///c')) // "a/b/c"
console.log(resolvePath('a', './b', '../../c')) // "c"
console.log(resolvePath('/a//b//')) // "/a/b"
console.log(resolvePath(null, undefined, '', 'x')) // "x"
console.log(resolvePath('../../a', 'b')) // "../../a/b"
console.log(resolvePath('/')) // "/"
console.log(resolvePath()) // "."
console.log(resolvePath('foo\\bar\\baz')) // "foo/bar/baz" 兼容windows反斜杠