Skip to content

Commit

Permalink
fix: regex match condition for primary type (#353)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpuri authored Dec 19, 2024
1 parent 2f7d139 commit 73db8a7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/utils/common.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ describe('CommonUtils', () => {
it('return types which are not array without any change', () => {
expect(stripArrayTypeIfPresent('string')).toBe('string');
expect(stripArrayTypeIfPresent('string []')).toBe('string []');
expect(
// @ts-expect-error Intentionally testing invalid input
stripArrayTypeIfPresent(undefined),
).toBeUndefined();
});
});
});
2 changes: 1 addition & 1 deletion src/utils/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @returns Parameter string with array brackets [] removed.
*/
export const stripArrayTypeIfPresent = (typeString: string) => {
if (typeString?.match(/\S\[\d*\]$/u) !== null) {
if (typeString?.match(/\S\[\d*\]$/u)) {
return typeString.replace(/\[\d*\]$/gu, '').trim();
}
return typeString;
Expand Down

0 comments on commit 73db8a7

Please sign in to comment.