Skip to content

Commit 30a865b

Browse files
committed
Micro perf improvement
1 parent 2bbeb92 commit 30a865b

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

packages/openapi-fetch/src/index.js

+6-10
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ const DEFAULT_HEADERS = {
33
"Content-Type": "application/json",
44
};
55

6-
const LEADING_QUESTION_RE = /^\?+/;
76
const PATH_PARAM_RE = /\{[^{}]+\}/g;
87

98
/**
@@ -19,7 +18,7 @@ export default function createClient(clientOptions) {
1918
} = clientOptions ?? {};
2019
let baseUrl = baseOptions.baseUrl ?? "";
2120
if (baseUrl.endsWith("/")) {
22-
baseUrl = baseUrl.slice(0, -1); // remove trailing slash
21+
baseUrl = baseUrl.substring(0, baseUrl.length - 1);
2322
}
2423

2524
/**
@@ -331,12 +330,8 @@ export function createQuerySerializer(options) {
331330
* @see https://swagger.io/docs/specification/serialization/#path
332331
*/
333332
export function defaultPathSerializer(pathname, pathParams) {
334-
const matches = pathname.match(PATH_PARAM_RE);
335-
if (!matches || !matches.length) {
336-
return undefined;
337-
}
338333
let nextURL = pathname;
339-
for (const match of matches) {
334+
for (const match of pathname.match(PATH_PARAM_RE) ?? []) {
340335
let paramName = match.substring(1, match.length - 1);
341336
let explode = false;
342337
let style = "simple";
@@ -411,9 +406,10 @@ export function createFinalURL(pathname, options) {
411406
if (options.params?.path) {
412407
finalURL = defaultPathSerializer(finalURL, options.params.path);
413408
}
414-
const search = options
415-
.querySerializer(options.params.query ?? {})
416-
.replace(LEADING_QUESTION_RE, "");
409+
let search = options.querySerializer(options.params.query ?? {});
410+
if (search.startsWith("?")) {
411+
search = search.substring(1);
412+
}
417413
if (search) {
418414
finalURL += `?${search}`;
419415
}

0 commit comments

Comments
 (0)