compactWhitespace method

String compactWhitespace()

Replaces all runs of whitespace with a single space and trims.

'  hello   world  '.compactWhitespace() // 'hello world'

Implementation

String compactWhitespace() => trim().replaceAll(RegExp(r'\s+'), ' ');