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

首頁 > 語言 > JavaScript > 正文

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

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

方法說明:

輸出規范格式的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; 
  };

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

圖片精選

主站蜘蛛池模板: 柳州市| 巴塘县| 舞钢市| 虞城县| 赤城县| 莱州市| 清水河县| 宝清县| 邯郸县| 凤庆县| 庄河市| 永顺县| 建昌县| 宁武县| 萨迦县| 夏河县| 白沙| 清丰县| 漳州市| 潼关县| 文昌市| 烟台市| 伽师县| 鄂托克前旗| 大关县| 长葛市| 德阳市| 抚远县| 洪江市| 兰州市| 舟山市| 勐海县| 开远市| 青神县| 西丰县| 和静县| 安溪县| 万荣县| 民权县| 泰兴市| 阜平县|