Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 40 additions & 22 deletions lib/path.js
Original file line number Diff line number Diff line change
Expand Up @@ -1114,19 +1114,12 @@ const win32 = {
startDot === end - 1 &&
startDot === startPart + 1)) {
if (end !== -1) {
if (startPart === 0 && isAbsolute)
ret.base = ret.name = path.slice(rootEnd, end);
else
ret.base = ret.name = path.slice(startPart, end);
const start = (startPart === 0 && isAbsolute) ? rootEnd : startPart;
ret.name = path.slice(start, end);
}
} else {
if (startPart === 0 && isAbsolute) {
ret.name = path.slice(rootEnd, startDot);
ret.base = path.slice(rootEnd, end);
} else {
ret.name = path.slice(startPart, startDot);
ret.base = path.slice(startPart, end);
}
const start = (startPart === 0 && isAbsolute) ? rootEnd : startPart;
ret.name = path.slice(start, startDot);
ret.ext = path.slice(startDot, end);
}

Expand All @@ -1135,6 +1128,22 @@ const win32 = {
else if (isAbsolute)
ret.dir = path.slice(0, rootEnd);

Object.defineProperty(ret, 'base', {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same code repeated. Can this be refactored to be a function?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prbly, I look into it, but this file is full of dup code 😵

enumerable: true,
configurable: false,
get() { return this.name + this.ext; },
set(value) {
const li = value.lastIndexOf('.');
if (li > 0) {
this.ext = value.slice(li);
this.name = value.slice(0, li);
} else {
this.name = value;
this.ext = '';
}
}
});

return ret;
},

Expand Down Expand Up @@ -1574,19 +1583,12 @@ const posix = {
startDot === end - 1 &&
startDot === startPart + 1)) {
if (end !== -1) {
if (startPart === 0 && isAbsolute)
ret.base = ret.name = path.slice(1, end);
else
ret.base = ret.name = path.slice(startPart, end);
const start = (startPart === 0 && isAbsolute) ? 1 : startPart;
ret.name = path.slice(start, end);
}
} else {
if (startPart === 0 && isAbsolute) {
ret.name = path.slice(1, startDot);
ret.base = path.slice(1, end);
} else {
ret.name = path.slice(startPart, startDot);
ret.base = path.slice(startPart, end);
}
const start = (startPart === 0 && isAbsolute) ? 1 : startPart;
ret.name = path.slice(start, startDot);
ret.ext = path.slice(startDot, end);
}

Expand All @@ -1595,6 +1597,22 @@ const posix = {
else if (isAbsolute)
ret.dir = '/';

Object.defineProperty(ret, 'base', {
enumerable: true,
configurable: false,
get() { return this.name + this.ext; },
set(value) {
const li = value.lastIndexOf('.');
if (li > 0) {
this.ext = value.slice(li);
this.name = value.slice(0, li);
} else {
this.name = value;
this.ext = '';
}
}
});

return ret;
},

Expand Down