pub fn safe_integer_field(map: &Map<String, Value>, key: &str) -> Option<i64>Expand description
What:
Read a field as a JavaScript safe integer,
or nothing.
i64 is a signed 64-bit integer.
Why:
typeof value === 'number' && Number.isSafeInteger(value) accepts 1,
1.0 and
1e0 alike,
because JavaScript has only doubles;
anything with a fraction or beyond
2^53 - 1 is refused.
In TS you’d write (pseudocode):
typeof value[key] === 'number' && Number.isSafeInteger(value[key]) ? value[key] : undefined