mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-16 16:37:12 +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";
|
import { Service } from "../types/segments.model";
|
||||||
|
|
||||||
export function getService<T extends string>(...value: T[]): Service {
|
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) {
|
for (const name of value) {
|
||||||
if (name) {
|
if (name?.trim().toLowerCase() in serviceByName) {
|
||||||
const service = Object.values(Service).find(
|
return serviceByName[name.trim().toLowerCase()];
|
||||||
(val) => val.toLowerCase() === name.trim().toLowerCase()
|
|
||||||
);
|
|
||||||
if (service) {
|
|
||||||
return service;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user