Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions lib/src/plugins/lib/random_user_agents.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/// A dart library for generating random user agents.
library random_user_agents;

import 'dart:math';

part 'user_agents.dart';

/// Random UserAgents
class RandomUserAgents {
/// a filtered list of user agents
final List<String> _list;

/// Creates a random number generator
final Random _random = Random();

/// Return an instance of RandomUserAgents using a private named constructor.
/// The instance is created with a filter function and a filtered list of user agents.
factory RandomUserAgents([bool Function(String value)? filter]) {
if (filter == null) {
return RandomUserAgents._internal(
_userAgents,
);
}

return RandomUserAgents._internal(
_userAgents.where(filter).toList(),
);
}

/// a private named constructor
RandomUserAgents._internal(this._list);

/// Return a random user agent string
static String random() {
Random random = Random();
return _userAgents[random.nextInt(_userAgents.length)];
}

/// Return a random user agent string
String getUserAgent() {
return _list[_random.nextInt(_list.length)];
}
}
Loading
Loading