Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v1
with:
node-version: 12.x
node-version: 16.x
- name: npm install
run: |
npm install
Expand All @@ -38,7 +38,7 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v1
with:
node-version: 12.x
node-version: 16.x
- name: npm install
run: |
npm install
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macOS-latest, windows-latest]
node-version: [10.x, 12.x, 14.x]
node-version: [12.x, 14.x, 16.x, 17.x]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
Expand Down
20 changes: 20 additions & 0 deletions __tests__/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,11 @@ test('.pathnameBuilder() - one argument is an Array of Strings - should start pa
expect(result).toBe('/a/b/c/d/e/f');
});

test('.pathnameBuilder() - one argument is an Array of String paths - should start pathname with "/", separate each entry with single "/" and end with no "/"', () => {
const result = utils.pathnameBuilder('/a/b/', ['/c/d'], 'e/f/');
expect(result).toBe('/a/b/c/d/e/f');
});

test('.pathnameBuilder() - one argument is "undefined" - should start pathname with "/", separate each entry with single "/" and end with no "/"', () => {
const result = utils.pathnameBuilder('/a/b/', undefined, '/c/d/');
expect(result).toBe('/a/b/c/d');
Expand All @@ -184,6 +189,21 @@ test('.pathnameBuilder() - emtpy arguments at the beginning, first String starts
expect(result).toBe('a/b');
});

test('.pathnameBuilder() - path is a http origin - should start pathname with "/", separate each entry with single "/" and end with no "/"', () => {
const result = utils.pathnameBuilder('http://foo.com/b/', '/c/d/', '/e/f/');
expect(result).toBe('/c/d/e/f');
});

test('.pathnameBuilder() - path is a https origin - should start pathname with "/", separate each entry with single "/" and end with no "/"', () => {
const result = utils.pathnameBuilder('http://foo.com/b/', '/c/d/', '/e/f/');
expect(result).toBe('/c/d/e/f');
});

test('.pathnameBuilder() - path is an array with a origin - should start pathname with "/", separate each entry with single "/" and end with no "/"', () => {
const result = utils.pathnameBuilder(['http://foo.com/b/'], '/c/d/', '/e/f/');
expect(result).toBe('/c/d/e/f');
});

/**
* .uriBuilder()
*/
Expand Down
24 changes: 10 additions & 14 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,29 +45,25 @@ const pathnameBuilder = (...args) => {
}

const parts = args
.filter(
arg =>
(Array.isArray(arg) && arg.length !== 0) ||
(isString(arg) && arg.length !== 0),
)
.map(arg => {
if (Array.isArray(arg)) {
return arg;
.flat()
.filter((arg) => {
if (isString(arg) && arg.length !== 0 && !arg.startsWith('http')) {
return true;
}

return false;
})
.map(arg => {
if (prefixCheck) {
prefixCheck = false;
if (arg.charAt(0) === separator) {
prefix = separator;
}
}

return arg.split(separator).filter(item => item);
});
})
.flat();

// NOTE: .apply() is on purpose. It converts all the
// Arrays in the parts Array to one Array
return `${prefix}${[].concat.apply([], parts).join(separator)}`; // eslint-disable-line prefer-spread
return `${prefix}${parts.join(separator)}`;
};

/**
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,19 @@
"@semantic-release/github": "7.2.3",
"@semantic-release/npm": "7.1.3",
"@semantic-release/release-notes-generator": "9.0.3",
"semantic-release": "17.4.7",
"benchmark": "2.1.4",
"eslint": "7.32.0",
"eslint-config-airbnb-base": "14.2.1",
"eslint-config-prettier": "8.3.0",
"eslint-plugin-import": "2.24.1",
"eslint-plugin-prettier": "3.4.1",
"jest": "26.6.3",
"prettier": "2.2.1"
"prettier": "2.2.1",
"semantic-release": "17.4.7"
},
"dependencies": {
"@podium/schemas": "4.1.25",
"original-url": "1.2.3",
"camelcase": "6.2.0"
"camelcase": "6.2.0",
"original-url": "1.2.3"
}
}