Skip to content

Commit

Permalink
feat: modify createUrl util
Browse files Browse the repository at this point in the history
param option key's convention is camelCase
and pathToken's convention is kebab-case
so sync the convention

#19
  • Loading branch information
timepresent95 committed Aug 20, 2024
1 parent a468ba5 commit a5cf6fd
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/utils/url.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import {convertKebabToCamel} from './string';

type OptionType = string | number | boolean;

interface Options {
Expand All @@ -7,8 +9,12 @@ interface Options {
export function createUrl(path: string, options?: Options) {
const pathTokens = path.split('/');
const replacedPathTokens = pathTokens.map(token => {
if (token[0] === ':' && options?.param && options.param[token.slice(1)]) {
return options.param[token.slice(1)];
const camelCaseToken = convertKebabToCamel(token.slice(1));
const optionsParam = options?.param ?? {};
const matchedParam = optionsParam[camelCaseToken];

if (token[0] === ':' && matchedParam) {
return matchedParam;
}
return token;
});
Expand Down

0 comments on commit a5cf6fd

Please sign in to comment.