Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into issue-#1448
Browse files Browse the repository at this point in the history
  • Loading branch information
GrandSchtroumpf committed Sep 11, 2024
2 parents 5dba97d + 726f23b commit 4e7818e
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 31 additions & 0 deletions src/libs/routing/utils.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { parseSearchWith } from './utils';
import { describe, it, expect } from 'vitest';

describe('parseSearchWith', () => {
const parser = parseSearchWith(JSON.parse);
it('should parse number to string and string numbers to double string', () => {
const url =
"?number1=1&number2=0.2&number3=0.1&number4='1'&number5='0.2'&number6='0.1'&number7='.'&number8=.";
const queryKeys = parser(url);

expect(queryKeys).toStrictEqual({
number1: '1',
number2: '0.2',
number3: '0.1',
number4: "'1'",
number5: "'0.2'",
number6: "'0.1'",
number7: "'.'",
number8: '.',
});
});
it('should parse non-number strings to string', () => {
const url = "?string1=hello&string2='hello'";
const queryKeys = parser(url);

expect(queryKeys).toStrictEqual({
string1: 'hello',
string2: "'hello'",
});
});
});
2 changes: 1 addition & 1 deletion src/libs/routing/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export const parseSearchWith = (parser: (str: string) => any) => {

const formatNumberParam = (value: string): string => {
const number = /^\d*\.*\d*$/;
if (value.match(number)) return `"${formatNumber(value)}"`;
if (value.match(number)) return `"${value}"`;
return value;
};

Expand Down

0 comments on commit 4e7818e

Please sign in to comment.