Files
sdk/pkg/dartdev/lib/src/utils.dart
T
Jaime Wren 4da1bb0da7 Initial and intentionally minimal pkg/dartdev/ package.  This includes some initial CLI utilities and test file.
Change-Id: I2b8485a1918fb0f1b6c5f0cbe626418aeef9c06e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/132025
Commit-Queue: Jaime Wren <jwren@google.com>
Reviewed-by: Devon Carew <devoncarew@google.com>
2020-01-21 18:21:47 +00:00

33 lines
1.1 KiB
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.
import 'dart:io';
import 'package:intl/intl.dart';
import 'package:path/path.dart' as path;
/// The directory used to store per-user settings for Dart tooling.
Directory getDartPrefsDirectory() {
return Directory(path.join(getUserHomeDir(), '.dart'));
}
/// Return the user's home directory.
String getUserHomeDir() {
String envKey = Platform.operatingSystem == 'windows' ? 'APPDATA' : 'HOME';
String value = Platform.environment[envKey];
return value == null ? '.' : value;
}
/// A typedef to represent a function taking no arguments and with no return
/// value.
typedef void VoidFunction();
final NumberFormat _numberFormat = NumberFormat.decimalPattern();
/// Convert the given number to a string using the current locale.
String formatNumber(int i) => _numberFormat.format(i);
/// Emit the given word with the correct pluralization.
String pluralize(String word, int count) => count == 1 ? word : '${word}s';