refactor: tryGetDeviceTypeVal
This commit is contained in:
@@ -34,11 +34,14 @@ export const DeviceTypeName: Record<DeviceTypeVal, string> = {
|
||||
[DeviceType.Keyboard]: '网络键盘',
|
||||
};
|
||||
|
||||
export const getDeviceTypeVal = (devcieTypeCode?: string): DeviceTypeVal => {
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
export const getDeviceTypeVal = (deviceTypeCode?: string): DeviceTypeVal => {
|
||||
let result: DeviceTypeVal = DeviceType.Camera;
|
||||
if (devcieTypeCode) {
|
||||
if (deviceTypeCode) {
|
||||
for (const key in DeviceTypeCode) {
|
||||
if (DeviceTypeCode[key as DeviceTypeVal].includes(devcieTypeCode)) {
|
||||
if (DeviceTypeCode[key as DeviceTypeVal].includes(deviceTypeCode)) {
|
||||
result = key as DeviceTypeVal;
|
||||
break;
|
||||
}
|
||||
@@ -46,3 +49,9 @@ export const getDeviceTypeVal = (devcieTypeCode?: string): DeviceTypeVal => {
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
export const tryGetDeviceTypeVal = (deviceTypeCode?: string) => {
|
||||
if (!deviceTypeCode) return undefined;
|
||||
const entry = Object.entries(DeviceTypeCode).find(([, codes]) => codes.includes(deviceTypeCode));
|
||||
return entry?.[0] as DeviceTypeVal | undefined;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user