Files
sdk/pkg/dartdev/lib/src/utils.dart
T
Devon Carew 353b04f96e [dartdev] add tests and remove dead code
Change-Id: I0e3ff1b9e507c48251d1b3588c86365052996d72
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/138020
Reviewed-by: Jaime Wren <jwren@google.com>
Commit-Queue: Devon Carew <devoncarew@google.com>
2020-03-02 20:22:52 +00:00

22 lines
938 B
Dart

// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
/// Emit the given word with the correct pluralization.
String pluralize(String word, int count) => count == 1 ? word : '${word}s';
/// String utility to trim some suffix from the end of a [String].
String trimEnd(String s, String suffix) {
if (s != null && suffix != null && suffix.isNotEmpty && s.endsWith(suffix)) {
return s.substring(0, s.length - suffix.length);
}
return s;
}
/// Given a data structure which is a Map of String to dynamic values, return
/// the same structure (`Map<String, dynamic>`) with the correct runtime types.
Map<String, dynamic> castStringKeyedMap(dynamic untyped) {
final Map<dynamic, dynamic> map = untyped as Map<dynamic, dynamic>;
return map?.cast<String, dynamic>();
}