Skip to content

Commit

Permalink
Remove code repetition
Browse files Browse the repository at this point in the history
  • Loading branch information
elvisvoer committed Feb 12, 2024
1 parent 783f984 commit 6148439
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions lib/b-path.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,16 @@ const posix = {
let word = "";
let dots = 0;

const handleFragment = () => {
if (dots === 2) {
fragments.pop();
}

if (word.length) {
fragments.push(word);
}
};

for (let i = 0; i < path.length; i += 1) {
// duplicated sep, skip
if (
Expand All @@ -122,13 +132,7 @@ const posix = {
}

if (path.charAt(i) === posix.sep) {
if (dots === 2) {
fragments.pop();
}

if (word.length) {
fragments.push(word);
}
handleFragment();

word = "";
dots = 0;
Expand All @@ -138,13 +142,7 @@ const posix = {
word += path.charAt(i);
}

if (dots === 2) {
fragments.pop();
}

if (word.length) {
fragments.push(word);
}
handleFragment();

let result = fragments.join(posix.sep);
if (hasTrailingSep) {
Expand Down

0 comments on commit 6148439

Please sign in to comment.