国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表

圖片精選

主站蜘蛛池模板: 宜丰县| 休宁县| 平阳县| 循化| 永泰县| 达拉特旗| 郧西县| 南城县| 全南县| 岳普湖县| 青岛市| 蒙山县| 华亭县| 永清县| 澳门| 托克托县| 博野县| 四平市| 盐源县| 连平县| 南充市| 元阳县| 龙门县| 嘉定区| 靖州| 闽侯县| 邮箱| 义马市| 容城县| 耒阳市| 迭部县| 大洼县| 琼海市| 喀什市| 杭锦旗| 石景山区| 花垣县| 高唐县| 建湖县| 崇文区| 衡阳县|