path

地址操作工具类

KISSY.use('path',function(S,Path){
        Path.do_sth();// 执行操作
});

Methods

basename() `<static>`
basename(path,ext) => String
获取域名中的文件名
Parameters:
  • path (string) – 路径字符串
  • ext (string) – 需要过滤的扩展名,比如`.html`
Returns:

返回结果字符串

Return type:

String

Path.basename('http://www.taobao.com/index.html','.html');//=> index
dirname() `<static>`
dirname(path) => String
返回path所指的文件所在的目录路径
Parameters:path (string) – Path 全称
Return type:String
Path.dirname('/home/bachi/daily/index.html');//=>/home/bachi/daily
extname() `<static>`
extname(path) => String
获取路径所指文件的扩展名,比如`.html`
Parameters:path (string) – Path 全称
Return type:String
Path.extname('/home/bachi/daily/index.html');//=> .html
normalize() `<static>`
normalize(path) => String
将path中的无关内容清理掉,返回直接的路径信息
Parameters:path (string) – Path 全称
Return type:String
Path.normalize('x/y/../z'); // => x/z/
Path.normalize('x/y/z/../'); // => x/y/
relative() `<static>`
relative(from,to) => String
计算相对路径
Parameters:
  • from (string) – 要比较的源地址
  • to (string) – 要比较的目标地址
Return type:

String

Path.relative('x/','x/y/z'); // => 'y/z'
Path.relative('x/t/z','x/'); // => '../../'
resolve() `<static>`
resolve([from ...], to) => String
得到绝对地址,算法逻辑参照NodeJS
KISSY.Path.resolve('wwwroot', 'static_files/png/', '../gif/image.gif')
// => 'wwwroot/static_files/gif/image.gif'

KISSY.Path.resolve('/foo/bar', '/tmp/file/')
// =>   '/tmp/file'