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

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

圖片精選

主站蜘蛛池模板: 松原市| 大连市| 隆德县| 图们市| 资阳市| 长寿区| 正定县| 茌平县| 同德县| 西华县| 大同市| 腾冲县| 阿合奇县| 南安市| 通化县| 白山市| 牡丹江市| 金昌市| 当雄县| 保德县| 揭西县| 图片| 龙岩市| 珠海市| 澎湖县| 乡城县| 台东县| 临汾市| 津市市| 会宁县| 桃园县| 金塔县| 商丘市| 清河县| 威远县| 教育| 盐池县| 尼勒克县| 宕昌县| 孝感市| 赤城县|