exports.split = function(path, keepBlanks) {
- // split based on /, but only if that / is not at the start or end.
- return exports.normalizeArray(path.split(/^|\/(?!$)/), keepBlanks);
+ // split based on / and \, but only if that / is not at the start or end.
+ return exports.normalizeArray(path.split(/^|[\\\/](?!$)/), keepBlanks);
};
return parts.filter(function(p) { return validPathPart(p, keepBlanks) })
.join('/')
- .split(/^|\/(?!$)/);
+ .split(/^|[\\\/](?!$)/);
}
exports.dirname = function(path) {
- if (path.length > 1 && '/' === path[path.length - 1]) {
+ if (path.length > 1 && '\\/'.indexOf(path[path.length-1]) != -1) {
path = path.replace(/\/+$/, '');
}
- var lastSlash = path.lastIndexOf('/');
+ var lastSlash = Math.max(path.lastIndexOf('/'), path.lastIndexOf('\\'));
switch (lastSlash) {
case -1:
return '.';
exports.extname = function(path) {
var dot = path.lastIndexOf('.'),
- slash = path.lastIndexOf('/');
+ slash = Math.max(path.lastIndexOf('/'), path.lastIndexOf('\\'));
// The last dot must be in the last path component, and it (the last dot) must
// not start the last path component (i.e. be a dot that signifies a hidden
// file in UNIX).