node.js中的path.normalize方法使用说明
作者:bea
方法说明: 输出规范格式的path字符串。 语法: 代码如下: path.normalize(p) 由于该方法属于path模块,使用前需要引入path模块(var path= require(“path”) ) 例子: 代码如下: path.normalize('/foo/bar//baz/asdf/quux/..') // returns '/foo/bar/baz/asdf' 源码: 代码如下: // windows version e
方法说明:
输出规范格式的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;
};
有用 | 无用
输出规范格式的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;
};
有用 | 无用
猜你喜欢
您可能感兴趣的文章:
- jquery实现侧边弹出的垂直导航
- 基于javascript实现判断移动终端浏览器版本信息
- 使用jQuery实现星级评分代码分享
- Jquery弹出层插件ThickBox的使用方法
- 浅谈JavaScript函数节流
- node.js中的console.log方法使用说明
- node.js中的console.warn方法使用说明
- node.js中的console.info方法使用说明
- 浅谈JavaScript实现面向对象中的类
- node.js中的console.trace方法使用说明
- node.js中的console.time方法使用说明
- node.js中的console.timeEnd方法使用说明
- node.js中的path.basename方法使用说明
- JavaScript 开发工具webstrom使用指南
- node.js中的path.dirname方法使用说明
- node.js中的path.extname方法使用说明
- jQuery不使用插件及swf实现无刷新文件上传
- javascript中的this详解
- node.js中的path.isAbsolute方法使用说明