node.js中的path.normalize方法使用說明
方法說明:
輸出規(guī)范格式的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;
};
- 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路徑模塊的使用方法實例分析
相關(guān)文章
node使用querystring內(nèi)置模塊解決分頁返回數(shù)據(jù)太多導(dǎo)致json.parse()解析報錯問題
這篇文章主要介紹了node使用querystring內(nèi)置模塊解決分頁返回數(shù)據(jù)太多導(dǎo)致json.parse()解析報錯問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-09-09
從零開始學(xué)習(xí)Node.js系列教程五:服務(wù)器監(jiān)聽方法示例
這篇文章主要介紹了Node.js服務(wù)器監(jiān)聽方法,結(jié)合實例形式分析了nodejs事件監(jiān)聽相關(guān)操作技巧,需要的朋友可以參考下2017-04-04
NodeJS http模塊用法示例【創(chuàng)建web服務(wù)器/客戶端】
這篇文章主要介紹了NodeJS http模塊用法,結(jié)合實例形式分析了node.js創(chuàng)建web服務(wù)器與客戶端,進(jìn)行HTTP通信的相關(guān)操作技巧,需要的朋友可以參考下2019-11-11
node版本太高導(dǎo)致項目跑不起來的解決辦法(windows)
換了臺電腦后,安裝node,一切完美,發(fā)現(xiàn)其中有一個uniapp的小程序項目跑不起來,感覺是node版本太高導(dǎo)致的,所以只能重新安裝低版本的node,本文給大家介紹了node版本太高的解決辦法,需要的朋友可以參考下2023-10-10
使用Node.js配合Nginx實現(xiàn)高負(fù)載網(wǎng)絡(luò)
這篇文章主要介紹了使用Node.js配合Nginx實現(xiàn)高負(fù)載網(wǎng)絡(luò),Node的異步加上Nginx的反向代理在性能上實在是給力!需要的朋友可以參考下2015-06-06
Node.js+ES6+dropload.js實現(xiàn)移動端下拉加載實例
這個demo服務(wù)由Node搭建服務(wù)、下拉加載使用插件dropload,數(shù)據(jù)渲染應(yīng)用了ES6中的模板字符串。有興趣的小伙伴可以自己嘗試下2017-06-06

