Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Remove type checks from slash-checking functions
Browse files Browse the repository at this point in the history
  • Loading branch information
alexlafroscia committed Apr 23, 2016
1 parent 0b3a026 commit 8319202
Showing 1 changed file with 13 additions and 18 deletions.
31 changes: 13 additions & 18 deletions addon/ajax-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,30 +43,22 @@ function isJSONAPIContentType(header) {
}

function startsWithSlash(string) {
if (typeof string === 'string') {
return string.charAt(0) === '/';
}
return string;
return string.charAt(0) === '/';
}

function endsWithSlash(string) {
if (typeof string === 'string') {
return string.charAt(string.length - 1) === '/';
}
return string;
return string.charAt(string.length - 1) === '/';
}

function stripSlashes(path) {
if (typeof path === 'string') {
// make sure path starts with `/`
if (startsWithSlash(path)) {
path = path.substring(1);
}
// make sure path starts with `/`
if (startsWithSlash(path)) {
path = path.substring(1);
}

// remove end `/`
if (endsWithSlash(path)) {
path = path.slice(0, -1);
}
// remove end `/`
if (endsWithSlash(path)) {
path = path.slice(0, -1);
}
return path;
}
Expand Down Expand Up @@ -279,7 +271,10 @@ export default class AjaxRequest {
}

const host = options.host || get(this, 'host');
const namespace = stripSlashes(get(this, 'namespace'));
let namespace = get(this, 'namespace');
if (namespace) {
namespace = stripSlashes(namespace);
}

let fullUrl = '';
// Add the host, if it exists
Expand Down

0 comments on commit 8319202

Please sign in to comment.