mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-15 07:57:05 +03:00
utils/getService: Improve Functionality to run on O(n)
This commit is contained in:
@@ -1,14 +1,15 @@
|
||||
import { Service } from "../types/segments.model";
|
||||
|
||||
export function getService<T extends string>(...value: T[]): Service {
|
||||
const serviceByName = Object.values(Service).reduce((acc, serviceName) => {
|
||||
acc[serviceName.toLowerCase()] = serviceName;
|
||||
|
||||
return acc;
|
||||
}, {} as Record<string, Service>);
|
||||
|
||||
for (const name of value) {
|
||||
if (name) {
|
||||
const service = Object.values(Service).find(
|
||||
(val) => val.toLowerCase() === name.trim().toLowerCase()
|
||||
);
|
||||
if (service) {
|
||||
return service;
|
||||
}
|
||||
if (name?.trim().toLowerCase() in serviceByName) {
|
||||
return serviceByName[name.trim().toLowerCase()];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user