readInt function

int readInt(
  1. Map<String, PropertyValue> props,
  2. String key,
  3. int fallback
)

Reads an int property, accepting a double too (JSON writers may encode whole numbers either way), or returns fallback.

Implementation

int readInt(Map<String, PropertyValue> props, String key, int fallback) {
  final v = props[key];
  return switch (v) {
    IntValue(:final value) => value,
    DoubleValue(:final value) => value.round(),
    _ => fallback,
  };
}