Skip to content

Commit 621c197

Browse files
committed
fix(creator): types and nullability
1 parent cd5c6ab commit 621c197

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

src/helpers/creator.helper.ts

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ const getCreatorColorRating = (el: HTMLElement): CSFDColorRating => {
88
return parseColor(el?.classNames.split(' ').pop() as Colors);
99
};
1010

11-
export const getCreatorId = (url: string): number => {
11+
export const getCreatorId = (url: string): number | null => {
1212
if (url) {
1313
return parseIdFromUrl(url);
1414
}
1515
return null;
16-
};
16+
}
1717

1818
export const getCreatorName = (el: HTMLElement | null): string => {
1919
return el.querySelector('h1').innerText.trim();
@@ -46,22 +46,21 @@ export const getCreatorBio = (el: HTMLElement | null): string => {
4646
return el.querySelector('.article-content p')?.text.trim().split('\n')[0].trim() || null;
4747
};
4848

49-
export const getCreatorPhoto = (el: HTMLElement | null): string => {
50-
const image = el.querySelector('img').attributes.src;
51-
return addProtocol(image);
49+
export const getCreatorPhoto = (el: HTMLElement | null): string | null => {
50+
const src = el?.querySelector('img')?.getAttribute('src');
51+
return src ? addProtocol(src) : null;
5252
};
5353

54-
const parseBirthday = (text: string): any => {
55-
return text.replace(/nar./g, '').trim();
56-
};
54+
const parseBirthday = (text: string): string => text.replace(/nar\./g, '').trim();
5755

58-
const parseAge = (text: string): any => {
59-
return text.trim().replace(/\(/g, '').replace(/let\)/g, '').trim();
56+
const parseAge = (text: string): number | null => {
57+
const digits = text.replace(/[^\d]/g, '');
58+
return digits ? Number(digits) : null;
6059
};
6160

62-
const parseBirthPlace = (text: string): any => {
63-
return text.trim().replace(/<br>/g, '').trim();
64-
};
61+
const parseBirthPlace = (text: string): string =>
62+
text.trim().replace(/<br>/g, '').trim();
63+
6564

6665
export const getCreatorFilms = (el: HTMLElement | null): CSFDCreatorScreening[] => {
6766
const filmNodes = el.querySelectorAll('.box')[0]?.querySelectorAll('table tr');

tsconfig.esm.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"extends": "./tsconfig.json",
33
"compilerOptions": {
44
"module": "ESNext",
5-
"moduleResolution": "node",
5+
"moduleResolution": "Node",
66
"outDir": "./dist/esm"
77
}
88
}

0 commit comments

Comments
 (0)