expand boolean helpers to support more than just true and false
This commit is contained in:
@@ -1,8 +1,40 @@
|
||||
export const BooleanHelpers = {
|
||||
parseBool: function(value: string | undefined, defaultValue: boolean) {
|
||||
if (value === undefined) {
|
||||
return defaultValue;
|
||||
parseBool: function(value: string | number | undefined, defaultValue: boolean): boolean {
|
||||
switch (typeof value) {
|
||||
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 { 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);
|
||||
|
||||
if (!torrent.imdbId && torrent.type !== TorrentType.Anime) {
|
||||
|
||||
Reference in New Issue
Block a user