Skip to content

Commit

Permalink
Merge pull request #221 from vitalygashkov/next
Browse files Browse the repository at this point in the history
Fixed episode numbers parsing, fixed evaluation of JS objects from string
  • Loading branch information
vitalygashkov authored Sep 17, 2024
2 parents c7a1d63 + b42274d commit 60e099c
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 15 deletions.
2 changes: 1 addition & 1 deletion apps/cli
Submodule cli updated from c6d4ef to 085e0a
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 5 additions & 9 deletions packages/core/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,13 @@ export const execUrlPatterns = (url: string, patterns: string[], baseUrls: strin
return { pathname, search };
};

// Like global eval but just for JS objects
// Like eval but just for JS objects
export const safeEval = <T = any>(jsObjectString: string): T | null => {
const jsonString = jsObjectString
.trim()
.replace(/(\w+):/g, '"$1":')
.replace(/'/g, '"');
try {
return JSON.parse(jsonString);
return new Function('return ' + jsObjectString)();
} catch (e) {
logger.error('JSON parsing failed');
logger.debug(jsonString);
logger.error('Evaluation JS object failed. Input:');
logger.debug(jsObjectString);
logger.debug(e);
return null as T;
}
Expand All @@ -62,7 +58,7 @@ export const extendEpisodes = (episodesBySeasons: Map<number, Set<number>>) => {
else episodesBySeasons.set(s, new Set([e]));
};
const getAllEpisodeNumbers = () =>
Array.from(episodesBySeasons.values()).flatMap(Array.from) as number[];
Array.from(episodesBySeasons.values()).flatMap((value) => Array.from(value)) as number[];
const seasonsCount = episodesBySeasons.size;
const episodes = getAllEpisodeNumbers();
const episodesCount = episodes.length;
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@streamyx/core",
"version": "2.1.0",
"version": "2.1.1",
"author": "Vitaly Gashkov <[email protected]>",
"description": "Core modules for Streamyx",
"license": "AGPL-3.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/crunchyroll

0 comments on commit 60e099c

Please sign in to comment.