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

首頁(yè) > 編程 > JavaScript > 正文

node.js中的path.join方法使用說(shuō)明

2019-11-20 13:47:13
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

方法說(shuō)明:

將多個(gè)參數(shù)組合成一個(gè) path (詳細(xì)請(qǐng)看例子)

語(yǔ)法:

復(fù)制代碼 代碼如下:

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

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

例子:

復(fù)制代碼 代碼如下:

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

源碼:

復(fù)制代碼 代碼如下:

// 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ā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 大埔区| 修水县| 临朐县| 莎车县| 鄂伦春自治旗| 佛学| 肇州县| 琼海市| 扬州市| 洱源县| 辛集市| 新津县| 什邡市| 漳州市| 翁牛特旗| 桦川县| 海安县| 德兴市| 垦利县| 和田县| 崇阳县| 介休市| 体育| 镇赉县| 南江县| 沧源| 巴林左旗| 建宁县| 蓝田县| 富阳市| 纳雍县| 化州市| 阳春市| 赤壁市| 友谊县| 芦山县| 廊坊市| 连南| 石家庄市| 阿拉善盟| 时尚|