@hello.nrfcloud.com/proto-map
Version:
Documents the communication protocol between devices, the hello.nrfcloud.com/map backend and web application
30 lines (28 loc) • 698 B
text/typescript
import { RangeEnumerationRegExp } from './LWM2MObjectDefinition.js'
import type { Range } from './LWM2MObjectInfo.js'
export const parseRangeEnumeration = (
re: string,
): { range: Range } | { error: Error } => {
const match = RangeEnumerationRegExp.exec(re)
if (match === null)
return {
error: new Error(
`Could not match '${re}' against ${RangeEnumerationRegExp}!`,
),
}
const { min: minS, max: maxS } = match.groups ?? {}
const min = parseFloat(minS as string)
const max = parseFloat(maxS as string)
if (min > max)
return {
error: new Error(
`'min' must be smaller than 'max' in RangeEnumeration '${re}'!`,
),
}
return {
range: {
min,
max,
},
}
}