node.js中的path.normalize方法使用說明
更新時間:2014年12月08日 11:56:58 投稿:junjie
這篇文章主要介紹了node.js中的path.normalize方法使用說明,本文介紹了path.normalize的方法說明、語法、使用實例和實現(xiàn)源碼,需要的朋友可以參考下
方法說明:
輸出規(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學習筆記之(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.js中的Buffer對象及創(chuàng)建方式
node.js提供了一個Buffer對象來提供對二進制數(shù)據(jù)的操作,Buffer?類的實例類似于整數(shù)數(shù)組,但?Buffer?的大小是固定的、且在?V8?堆外分配物理內(nèi)存。本文給大家介紹Node.js中的Buffer對象及創(chuàng)建方式,感興趣的朋友一起看看吧2022-01-01nodejs實現(xiàn)郵件發(fā)送服務(wù)實例分享
本文給大家講解的是簡單的使用nodejs搭建郵件發(fā)送服務(wù)的一個實例,非常的好用,有需要的小伙伴可以參考下2017-03-03關(guān)于Sequelize連接查詢時inlude中model和association的區(qū)別詳解
這篇文章主要介紹了關(guān)于Sequelize連接查詢時inlude中model與association的區(qū)別,文中介紹的很詳細,需要的朋友可以參考借鑒,下面來一起看看吧。2017-02-02