mirror of
https://github.com/KRTirtho/spotube.git
synced 2025-09-14 16:25:16 +00:00

Configuration File Removals: .vscode/c_cpp_properties.json: Removed the entire configuration for C/C++ properties. .vscode/launch.json: Removed the Dart launch configurations for different environments and modes. .vscode/settings.json: Removed settings related to CMake, spell checking, file nesting, and Dart Flutter SDK path. .vscode/snippets.code-snippets: Removed code snippets for Dart, including PaginatedState and PaginatedNotifier templates. .vscode/tasks.json: Removed the tasks configuration file. Documentation Updates: CONTRIBUTION.md: Removed heart emoji from the introductory text. README.md: Updated the logo image and made minor text adjustments, including removing emojis and updating section titles. [1] [2] [3] [4] [5] Asset Removals: lib/collections/assets.gen.dart: Removed multiple unused asset references, including images related to Spotube logos and banners. [1] [2] [3] Minor Code Cleanups: cli/commands/build/linux.dart, cli/commands/build/windows.dart, cli/commands/translated.dart, cli/commands/untranslated.dart: Adjusted import statements for consistency. [1] [2] [3] [4] integration_test/app_test.dart: Removed an unnecessary blank line. lib/collections/routes.dart: Commented out the TrackRoute configuration.
55 lines
1.5 KiB
Dart
55 lines
1.5 KiB
Dart
import 'dart:math';
|
|
|
|
import 'package:uuid/uuid.dart';
|
|
|
|
abstract class PrimitiveUtils {
|
|
static bool containsTextInBracket(String matcher, String text) {
|
|
final allMatches = RegExp(r"(?<=\().+?(?=\))").allMatches(matcher);
|
|
if (allMatches.isEmpty) return false;
|
|
return allMatches
|
|
.map((e) => e.group(0))
|
|
.every((match) => match?.contains(text) ?? false);
|
|
}
|
|
|
|
static final Random _random = Random();
|
|
static T getRandomElement<T>(List<T> list) {
|
|
return list[_random.nextInt(list.length)];
|
|
}
|
|
|
|
static const uuid = Uuid();
|
|
|
|
static String toReadableNumber(double num) {
|
|
if (num > 999 && num < 99999) {
|
|
return "${(num / 1000).toStringAsFixed(0)}K";
|
|
} else if (num > 99999 && num < 999999) {
|
|
return "${(num / 1000).toStringAsFixed(0)}K";
|
|
} else if (num > 999999 && num < 999999999) {
|
|
return "${(num / 1000000).toStringAsFixed(0)}M";
|
|
} else if (num > 999999999) {
|
|
return "${(num / 1000000000).toStringAsFixed(0)}B";
|
|
} else {
|
|
return num.toStringAsFixed(0);
|
|
}
|
|
}
|
|
|
|
static Future<T> raceMultiple<T>(
|
|
Future<T> Function() inner, {
|
|
Duration timeout = const Duration(milliseconds: 2500),
|
|
int retryCount = 4,
|
|
}) async {
|
|
return Future.any(
|
|
List.generate(retryCount, (i) {
|
|
if (i == 0) return inner();
|
|
return Future.delayed(
|
|
Duration(milliseconds: timeout.inMilliseconds * i),
|
|
inner,
|
|
);
|
|
}),
|
|
);
|
|
}
|
|
|
|
static String toSafeFileName(String str) {
|
|
return str.replaceAll(RegExp(r'[/\?%*:|"<>]'), ' ');
|
|
}
|
|
}
|