mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2024-11-10 09:07:47 +01:00
utils/getService: Improve Functionality to run on O(n)
This commit is contained in:
parent
b785658db1
commit
db8543a0b4
1 changed files with 8 additions and 7 deletions
|
@ -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()];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue