-
-
Notifications
You must be signed in to change notification settings - Fork 9
ESM + CommonJS build 🎉 #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
eac3474
78bc62b
213c0ab
8267f7a
f26c63c
ec35f57
58f5047
e7a7ba2
5884992
5cd17d2
0cb8e04
aeccead
1f05186
208504b
c510a40
2406c61
3d710ee
cd5c6ab
621c197
27c1bec
e33a989
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"directory": "./dist/", | ||
"name": "index.dto.d", | ||
"noHeader": true | ||
} | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,30 @@ | ||
import { HTMLElement } from 'node-html-parser'; | ||
import { CSFDColorRating } from '../interfaces/global'; | ||
import { Colors } from '../interfaces/user-ratings.interface'; | ||
import { | ||
CSFDCinemaGroupedFilmsByDate, | ||
CSFDCinemaMeta, | ||
CSFDCinemaMovie | ||
} from './../interfaces/cinema.interface'; | ||
} from '../dto/cinema'; | ||
import { CSFDColorRating } from '../dto/global'; | ||
import { Colors } from '../dto/user-ratings'; | ||
import { parseColor, parseIdFromUrl } from './global.helper'; | ||
|
||
export const getColorRating = (el: HTMLElement): CSFDColorRating => { | ||
return parseColor(el?.classNames.split(' ').pop() as Colors); | ||
export const getCinemaColorRating = (el: HTMLElement | null): CSFDColorRating => { | ||
const classes: string[] = el?.classNames.split(' ') ?? []; | ||
const last = classes.length ? classes[classes.length - 1] : undefined; | ||
return last ? parseColor(last as Colors) : 'unknown'; | ||
}; | ||
|
||
export const getCinemaId = (el: HTMLElement | null): number => { | ||
const id = el?.id?.split('-')[1]; | ||
return +id; | ||
}; | ||
|
||
export const getId = (url: string): number | null => { | ||
if (url) { | ||
return parseIdFromUrl(url); | ||
} | ||
return null; | ||
export const getCinemaUrlId = (url: string | null | undefined): number | null => { | ||
if (!url) return null; | ||
return parseIdFromUrl(url); | ||
}; | ||
Comment on lines
+22
to
25
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chainAlign parseIdFromUrl’s type: it returns null in some paths This wrapper returns Update src/helpers/global.helper.ts: -export const parseIdFromUrl = (url: string): number => {
+export const parseIdFromUrl = (url: string): number | null => {
if (url) {
const idSlug = url?.split('/')[2];
const id = idSlug?.split('-')[0];
return +id || null;
} else {
return null;
}
}; Run to confirm all signatures/usages are consistent: 🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "== Declarations =="
rg -nP -C2 'export\s+const\s+parseIdFromUrl\s*=\s*\(url:\s*string\)\s*:\s*number\b'
echo
echo "== Call sites (context) =="
rg -nP -C3 '\bparseIdFromUrl\s*\(' Length of output: 6013 🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "== parseIdFromUrl declaration =="
sed -n '1,120p' src/helpers/global.helper.ts
echo
echo "== Call sites with surrounding context (8 lines) =="
rg -nP -C8 '\bparseIdFromUrl\s*\(' || true Length of output: 14142 🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "== Locations that return parseIdFromUrl (with context) =="
rg -nP -C4 'return\s+parseIdFromUrl\(' || true
echo
echo "== Functions exporting and returning parseIdFromUrl result (signatures) =="
rg -nP --hidden --no-ignore-vcs 'export\s+const\s+[A-Za-z0-9_]+\s*=\s*\(.*\)\s*:\s*number\b' -n -C1 || true
echo
echo "== DTO/type definitions referencing 'id' fields (searching common DTO names) =="
rg -nP '\bCSFD(Search(Movie|User)|Movie(ListItem)?|SearchMovie|SearchUser|MovieListItem)\b' || true
echo
echo "== File contents for DTOs and found helpers =="
sed -n '1,240p' src/dto/global.ts || true
sed -n '1,240p' src/dto/movie.ts || true
sed -n '1,240p' src/dto/search.ts || true
sed -n '1,240p' src/dto/user-ratings.ts || true Length of output: 12183 Fix parseIdFromUrl signature and update callers parseIdFromUrl is declared to return number but its implementation (and tests) return null on some inputs. Change the helper signature to: export const parseIdFromUrl = (url: string | null | undefined): number | null => Then update/guard all call sites that assume a non-null number (either widen their return types to number | null or add runtime checks/assertions):
Callers already nullable-aware and OK: src/helpers/creator.helper.ts:getCreatorId, src/helpers/cinema.helper.ts:getCinemaUrlId 🤖 Prompt for AI Agents
|
||
|
||
export const getCoords = (el: HTMLElement | null): { lat: number; lng: number } | null => { | ||
export const getCinemaCoords = (el: HTMLElement | null): { lat: number; lng: number } | null => { | ||
|
||
if (!el) return null; | ||
const linkMapsEl = el.querySelector('a[href*="q="]'); | ||
|
@@ -63,20 +63,20 @@ export const getGroupedFilmsByDate = (el: HTMLElement | null): CSFDCinemaGrouped | |
.map((index) => { | ||
const [date, films] = divs.slice(index, index + 2); | ||
const dateText = date?.firstChild?.textContent?.trim() ?? null; | ||
return { date: dateText, films: getFilms('', films) }; | ||
return { date: dateText, films: getCinemaFilms('', films) }; | ||
}); | ||
|
||
return getDatesAndFilms; | ||
}; | ||
|
||
export const getFilms = (date: string, el: HTMLElement | null): CSFDCinemaMovie[] => { | ||
export const getCinemaFilms = (date: string, el: HTMLElement | null): CSFDCinemaMovie[] => { | ||
const filmNodes = el.querySelectorAll('.cinema-table tr'); | ||
bartholomej marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
const films = filmNodes.map((filmNode) => { | ||
const url = filmNode.querySelector('td.name h3 a')?.attributes.href; | ||
const id = getId(url); | ||
const id = url ? getCinemaUrlId(url) : null; | ||
const title = filmNode.querySelector('.name h3')?.text.trim(); | ||
const colorRating = getColorRating(filmNode.querySelector('.name .icon')); | ||
const colorRating = getCinemaColorRating(filmNode.querySelector('.name .icon')); | ||
const showTimes = filmNode.querySelectorAll('.td-time')?.map((x) => x.textContent.trim()); | ||
const meta = filmNode.querySelectorAll('.td-title span')?.map((x) => x.text.trim()); | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.