const path = require('path')
console.log(__filename)
// 获取路径的基础名称=>路径的最后一部分
/**
* 第一个参数是字符串
* 第二个参数是文件扩展名,有扩展名就不现实扩展名了
*/
console.log(path.basename(__filename))
// test.js
console.log(path.basename(__filename,'.js'))
// test
console.log(path.basename('/a/b/c'))
// c
console.log(path.basename('/a/b/c/'))
// c
//获取目录路径
/**
* 返回路径中最后一部分的上一层所在目录
*/
console.log(path.dirname(__filename))
// /Users/yangkangwei
console.log(path.dirname('/a/b/c'))
// /a/b
console.log(path.dirname('/a/b/c/'))
// /a/b
// 获取文件路径的扩展名
console.log(path.extname(__filename))
// .js
console.log(path.extname('/a/b.html'))
// .html
// 4 解析路径
const obj1 = path.parse('/a/b/c/index.html')
const obj2 = path.parse('./a/b/test.js')
// 序列化路径
console.log(path.format(obj2))
// 判断路径是否为绝对路径
console.log(path.isAbsolute('../foo'))
console.log(path.isAbsolute('/foo'))
//拼接路径
console.log(path.join('/a','b','index.html'))
console.log(path.join('./a','b','index.html'))
console.log(path.join('./a/b','../','index.html'))
console.log(path.join('./a/b','./','index.html'))
console.log(path.join(''))
// 规范化路径
console.log(path.normalize('a/b/c/d'))
console.log(path.normalize('a///b/c/d'))
console.log(path.normalize('a/b\\/c\\/d'))
console.log(path.normalize('a/\b/c\\/d'))
console.log(path.normalize(''))
// 绝对路径
console.log(path.resolve('a','/b'))
console.log(path.resolve('a','b'))
console.log(path.resolve('/a','b'))
console.log(path.resolve('index.html')) // 推荐使用