Method description:
Output path string in canonical format.
Grammar:
path.normalize(p)
Since this method belongs to the path module, the path module needs to be introduced before use (var path= require(“path”) )
Example:
path.normalize('/foo/bar//baz/asdf/quux/..')
// returns
'/foo/bar/baz/asdf'
Source code:
// 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;
};