国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > JavaScript > 正文

node.js中的path.join方法使用說明

2024-05-06 16:11:42
字體:
來源:轉載
供稿:網(wǎng)友
這篇文章主要介紹了node.js中的path.join方法使用說明,本文介紹了path.join的方法說明、語法、使用實例和實現(xiàn)源碼,需要的朋友可以參考下
 
 

方法說明:

將多個參數(shù)組合成一個 path (詳細請看例子)

語法:

 

復制代碼代碼如下:

path.join([path1], [path2], [...])

 

由于該方法屬于path模塊,使用前需要引入path模塊(var path= require(“path”) )

例子:

 

復制代碼代碼如下:

path.join('/foo', 'bar', 'baz/asdf', 'quux', '..')
// returns
'/foo/bar/baz/asdf'
path.join('foo', {}, 'bar')
// throws exception
TypeError: Arguments to path.join must be strings

 

源碼:

 

復制代碼代碼如下:

// windows version 
  exports.join = function() { 
    function f(p) { 
      if (!util.isString(p)) { 
        throw new TypeError('Arguments to path.join must be strings'); 
      } 
      return p; 
    } 
 
    var paths = Array.prototype.filter.call(arguments, f); 
    var joined = paths.join('//'); 
 
    // Make sure that the joined path doesn't start with two slashes, because 
    // normalize() will mistake it for an UNC path then. 
    // 
    // This step is skipped when it is very clear that the user actually 
    // intended to point at an UNC path. This is assumed when the first 
    // non-empty string arguments starts with exactly two slashes followed by 
    // at least one more non-slash character. 
    // 
    // Note that for normalize() to treat a path as an UNC path it needs to 
    // have at least 2 components, so we don't filter for that here. 
    // This means that the user can use join to construct UNC paths from 
    // a server name and a share name; for example: 
    // path.join('//server', 'share') -> '////server//share/') 
    if (!/^[////]{2}[^////]/.test(paths[0])) { 
      joined = joined.replace(/^[////]{2,}/, '//'); 
    } 
 
    return exports.normalize(joined); 
  };
 

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表

圖片精選

主站蜘蛛池模板: 云霄县| 凤翔县| 林芝县| 嘉义县| 大英县| 丹巴县| 广东省| 彰武县| 防城港市| 庄河市| 贺兰县| 抚顺县| 五家渠市| 南阳市| 康平县| 察哈| 延安市| 南华县| 汝阳县| 安图县| 连城县| 台江县| 嫩江县| 小金县| 新巴尔虎右旗| 临澧县| 清镇市| 西宁市| 翁牛特旗| 阿拉善盟| 陆川县| 道孚县| 巴彦淖尔市| 朔州市| 隆尧县| 花垣县| 澎湖县| 牡丹江市| 香格里拉县| 南汇区| 汕头市|