node.js中的path.normalize方法使用說明
更新時(shí)間:2014年12月08日 11:56:58 投稿:junjie
這篇文章主要介紹了node.js中的path.normalize方法使用說明,本文介紹了path.normalize的方法說明、語(yǔ)法、使用實(shí)例和實(shí)現(xiàn)源碼,需要的朋友可以參考下
方法說明:
輸出規(guī)范格式的path字符串。
語(yǔ)法:
復(fù)制代碼 代碼如下:
path.normalize(p)
由于該方法屬于path模塊,使用前需要引入path模塊(var path= require(“path”) )
例子:
復(fù)制代碼 代碼如下:
path.normalize('/foo/bar//baz/asdf/quux/..')
// returns
'/foo/bar/baz/asdf'
源碼:
復(fù)制代碼 代碼如下:
// 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;
};
您可能感興趣的文章:
- node.JS路徑解析之PATH模塊使用方法詳解
- Node.js中路徑處理模塊path詳解
- 詳解nodeJS之路徑PATH模塊
- NodeJS學(xué)習(xí)筆記之(Url,QueryString,Path)模塊
- 詳解Node.js中path模塊的resolve()和join()方法的區(qū)別
- 深入理解node.js之path模塊
- node.js中的path.resolve方法使用說明
- node.js中的path.join方法使用說明
- node.js中的path.dirname方法使用說明
- node.js中的path.basename方法使用說明
- node.js中的path.extname方法使用說明
- node.js中path路徑模塊的使用方法實(shí)例分析
相關(guān)文章
Node.js中的Buffer對(duì)象及創(chuàng)建方式
node.js提供了一個(gè)Buffer對(duì)象來提供對(duì)二進(jìn)制數(shù)據(jù)的操作,Buffer?類的實(shí)例類似于整數(shù)數(shù)組,但?Buffer?的大小是固定的、且在?V8?堆外分配物理內(nèi)存。本文給大家介紹Node.js中的Buffer對(duì)象及創(chuàng)建方式,感興趣的朋友一起看看吧2022-01-01
nodejs實(shí)現(xiàn)郵件發(fā)送服務(wù)實(shí)例分享
本文給大家講解的是簡(jiǎn)單的使用nodejs搭建郵件發(fā)送服務(wù)的一個(gè)實(shí)例,非常的好用,有需要的小伙伴可以參考下2017-03-03
關(guān)于Sequelize連接查詢時(shí)inlude中model和association的區(qū)別詳解
這篇文章主要介紹了關(guān)于Sequelize連接查詢時(shí)inlude中model與association的區(qū)別,文中介紹的很詳細(xì),需要的朋友可以參考借鑒,下面來一起看看吧。2017-02-02
NodeJS實(shí)現(xiàn)單點(diǎn)登錄原理解析
隨著公司業(yè)務(wù)的增多,必然會(huì)產(chǎn)生各個(gè)不同的系統(tǒng),如果每個(gè)系統(tǒng)都需要單獨(dú)登錄的話就會(huì)很不方便,所以這個(gè)時(shí)候單點(diǎn)登錄會(huì)很方便,今天通過本文給大家講解NodeJS實(shí)現(xiàn)單點(diǎn)登錄原理解析,感興趣的朋友一起看看吧2022-05-05

