mirror of
https://github.com/knightcrawler-stremio/knightcrawler.git
synced 2024-12-20 03:29:51 +00:00
expand boolean helpers to support more than just true and false
This commit is contained in:
@@ -1,8 +1,40 @@
|
|||||||
export const BooleanHelpers = {
|
export const BooleanHelpers = {
|
||||||
parseBool: function(value: string | undefined, defaultValue: boolean) {
|
parseBool: function(value: string | number | undefined, defaultValue: boolean): boolean {
|
||||||
if (value === undefined) {
|
switch (typeof value) {
|
||||||
return defaultValue;
|
case 'string':
|
||||||
|
return parseStringToBool(value, defaultValue);
|
||||||
|
case 'boolean':
|
||||||
|
return value;
|
||||||
|
case 'number':
|
||||||
|
return parseNumberToBool(value, defaultValue);
|
||||||
|
default:
|
||||||
|
return defaultValue;
|
||||||
}
|
}
|
||||||
return value.toLowerCase().trim() === 'true';
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const parseStringToBool = (input: string, defaultVal: boolean): boolean => {
|
||||||
|
switch (input.toLowerCase().trim()) {
|
||||||
|
case 'true':
|
||||||
|
case 'yes':
|
||||||
|
case '1':
|
||||||
|
return true;
|
||||||
|
case 'false':
|
||||||
|
case 'no':
|
||||||
|
case '0':
|
||||||
|
return false;
|
||||||
|
default:
|
||||||
|
return defaultVal
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const parseNumberToBool = (input: number, defaultVal: boolean): boolean => {
|
||||||
|
switch (input) {
|
||||||
|
case 1:
|
||||||
|
return true;
|
||||||
|
case 0:
|
||||||
|
return false;
|
||||||
|
default:
|
||||||
|
return defaultVal;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -8,7 +8,7 @@ import { parsingService } from './services/parsing_service';
|
|||||||
import { torrentFileService } from './services/torrent_file_service';
|
import { torrentFileService } from './services/torrent_file_service';
|
||||||
import { torrentSubtitleService } from './services/torrent_subtitle_service';
|
import { torrentSubtitleService } from './services/torrent_subtitle_service';
|
||||||
|
|
||||||
export async function createTorrentEntry(torrent, overwrite = false) : Promise<void> {
|
export async function createTorrentEntry(torrent, overwrite = false) {
|
||||||
const titleInfo = parse(torrent.title);
|
const titleInfo = parse(torrent.title);
|
||||||
|
|
||||||
if (!torrent.imdbId && torrent.type !== TorrentType.Anime) {
|
if (!torrent.imdbId && torrent.type !== TorrentType.Anime) {
|
||||||
|
|||||||
Reference in New Issue
Block a user