node.js中的path.normalize方法使用說(shuō)明
方法說(shuō)明:
輸出規(guī)范格式的path字符串。
語(yǔ)法:
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;
};
- 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方法使用說(shuō)明
- node.js中的path.join方法使用說(shuō)明
- node.js中的path.dirname方法使用說(shuō)明
- node.js中的path.basename方法使用說(shuō)明
- node.js中的path.extname方法使用說(shuō)明
- node.js中path路徑模塊的使用方法實(shí)例分析
相關(guān)文章
Node.js中的Buffer對(duì)象及創(chuàng)建方式
node.js提供了一個(gè)Buffer對(duì)象來(lái)提供對(duì)二進(jìn)制數(shù)據(jù)的操作,Buffer?類的實(shí)例類似于整數(shù)數(shù)組,但?Buffer?的大小是固定的、且在?V8?堆外分配物理內(nèi)存。本文給大家介紹Node.js中的Buffer對(duì)象及創(chuàng)建方式,感興趣的朋友一起看看吧2022-01-01nodejs實(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ì),需要的朋友可以參考借鑒,下面來(lái)一起看看吧。2017-02-02NodeJS實(shí)現(xiàn)單點(diǎn)登錄原理解析
隨著公司業(yè)務(wù)的增多,必然會(huì)產(chǎn)生各個(gè)不同的系統(tǒng),如果每個(gè)系統(tǒng)都需要單獨(dú)登錄的話就會(huì)很不方便,所以這個(gè)時(shí)候單點(diǎn)登錄會(huì)很方便,今天通過(guò)本文給大家講解NodeJS實(shí)現(xiàn)單點(diǎn)登錄原理解析,感興趣的朋友一起看看吧2022-05-05TypeScript開(kāi)發(fā)Node.js程序的方法
這篇文章主要介紹了TypeScript開(kāi)發(fā)Node.js程序的方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-04-04簡(jiǎn)單好用的nodejs 爬蟲(chóng)框架分享
使用nodejs開(kāi)發(fā)爬蟲(chóng)半年左右了,爬蟲(chóng)可以很簡(jiǎn)單,也可以很復(fù)雜。簡(jiǎn)單的爬蟲(chóng)定向爬取一個(gè)網(wǎng)站,可能有個(gè)幾萬(wàn)或者幾十萬(wàn)的頁(yè)面請(qǐng)求,今天給大家介紹這款非常好用的爬蟲(chóng)框架crawl-pet2017-03-03