Show:

Path Class

Module: path

地址操作工具类

  • Index
  • Methods

Item Index

Methods

Methods

basename

(
  • path
  • ext
)
String static

获取域名中的文件名

Parameters:

  • path String

    路径字符串

  • ext String

    需要过滤的扩展名,比如.html

Returns:

String:

返回结果字符串

Example:

Path.basename('http://www.taobao.com/index.html','.html');//=> index

dirname

(
  • path
)
String static

返回path所指的文件所在的目录路径

Parameters:

Returns:

Example:

Path.dirname('/home/bachi/daily/index.html');//=>/home/bachi/daily

extname

(
  • path
)
String static

获取路径所指文件的扩展名,比如.html

Parameters:

Returns:

Example:

Path.extname('/home/bachi/daily/index.html');//=> .html

normalize

(
  • path
)
String static

将path中的无关内容清理掉,返回直接的路径信息

Parameters:

Returns:

Example:

Path.normalize('x/y/../z'); // => x/z/
Path.normalize('x/y/z/../'); // => x/y/

relative

(
  • from
  • to
)
String static

计算相对路径

Parameters:

  • from String

    要比较的源地址

  • to String

    要比较的目标地址

Returns:

Example:

Path.relative('x/','x/y/z'); // => 'y/z'
Path.relative('x/t/z','x/'); // => '../../'

resolve

() static

得到绝对地址,算法逻辑参照 NodeJS

Example:

Path.resolve('wwwroot', 'static_files/png/', '../gif/image.gif')
// => 'wwwroot/static_files/gif/image.gif'

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