Files
czzj-app/src/utils/device-id.ts
2026-10-13 16:23:43 +08:00

21 lines
621 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/** 从路由参数等解析 ID,避免 Number() 导致 int64 精度丢失 */
export function parseId(raw: unknown): string {
if (raw === undefined || raw === null || raw === '') return ''
const id = String(raw).trim()
return id === '0' ? '' : id
}
/** 从路由参数等解析设备 ID */
export function parseDeviceId(raw: unknown): string {
return parseId(raw)
}
export function isValidDeviceId(id: string): boolean {
return /^\d+$/.test(id)
}
export function sameId(a: unknown, b: unknown): boolean {
if (a == null || b == null || a === '' || b === '') return false
return String(a) === String(b)
}