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

首頁 > 編程 > JavaScript > 正文

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

2019-11-20 13:47:13
字體:
來源:轉載
供稿:網友

方法說明:

輸出規范格式的path字符串。

語法:

復制代碼 代碼如下:

path.normalize(p)

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

例子:

復制代碼 代碼如下:

path.normalize('/foo/bar//baz/asdf/quux/..')
// returns
'/foo/bar/baz/asdf'

源碼:

復制代碼 代碼如下:

// windows version
  exports.normalize = function(path) {
    var result = splitDeviceRe.exec(path),
        device = result[1] || '',
        isUnc = device && device.charAt(1) !== ':',
        isAbsolute = exports.isAbsolute(path),
        tail = result[3],
        trailingSlash = /[////]$/.test(tail);
 
    // If device is a drive letter, we'll normalize to lower case.
    if (device && device.charAt(1) === ':') {
      device = device[0].toLowerCase() + device.substr(1);
    }
 
    // Normalize the tail path
    tail = normalizeArray(tail.split(/[////]+/).filter(function(p) {
      return !!p;
    }), !isAbsolute).join('//');
 
    if (!tail && !isAbsolute) {
      tail = '.';
    }
    if (tail && trailingSlash) {
      tail += '//';
    }
 
    // Convert slashes to backslashes when `device` points to an UNC root.
    // Also squash multiple slashes into a single one where appropriate.
    if (isUnc) {
      device = normalizeUNCRoot(device);
    }
 
    return device + (isAbsolute ? '//' : '') + tail;
  };

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 武鸣县| 丹棱县| 从化市| 玉环县| 大庆市| 武义县| 龙江县| 梅州市| 秦安县| 安化县| 合江县| 泾源县| 文山县| 尤溪县| 林口县| 姚安县| 原阳县| 满洲里市| 莱阳市| 镶黄旗| 弥勒县| 溧水县| 安徽省| 雷山县| 河东区| 永安市| 濮阳市| 兴安县| 兴文县| 义马市| 运城市| 马尔康县| 卢龙县| 徐闻县| 赣州市| 库伦旗| 罗山县| 东兴市| 治县。| 山东省| 丰宁|