dart_bones library Null safety

Helper definitions for Dart programming.

Classes

BaseConfiguration
Implements read access to a YAML based configuration content. Only a two levels structure is allowed: simple types in the first level or simple types in a named map. The name of such a map is called "section".
BaseLogger
Implements the superclass of loggers.
BaseRandom
Configuration
Implements static functions for files and directories in the sync variant.
CryptoBaseEngine
FileSync
Implements static functions for files and directories in the sync variant.
KissRandom
A pseudo random generator from George Marsaglia. https://de.wikipedia.org/wiki/KISS_(Zufallszahlengenerator) The algorithm is modified to support JavaScript ("Web") with float arithmetic only: [...]
Logger
MemoryLogger
Implements a logger which logs to stdout and stores the messages.
MySqlDb
OsService
Holds the information about the current user.
ProcessSync
UserInfo
Validation
Offers functions testing some things like phone numbers. All methods are static and sync.

Constants

BONES_VERSION → const String
'0.4.9'
LEVEL_DEBUG → const int
9
LEVEL_DETAIL → const int
2
LEVEL_FINE → const int
4
LEVEL_LOOP → const int
3
LEVEL_SUMMERY → const int
1

Properties

globalLogger BaseLogger
read / write

Functions

asFloat(String text, {double? defaultValue}) double?
Converts a text into an integer. defaultValue is the return value if text is not an integer
asInt(String text, {int? defaultValue}) int?
Converts a text into an integer. defaultValue is the return value if text is not an integer
boolOption(String longName, String shortName, String argument) Bool
Tests whether the argument has the longName or the shortName and an boolean. Returns the value of the boolean argument. Throws OptionException on error. longName: the long name to inspect, e.g. 'max-length' shortName: the short name to inspect, e.g. 'm' argument: argument to inspect, e.g. '--max-length=3'
byteOption(String longName, String? shortName, String argument) int?
Tests whether the argument has the longName or the shortName and byte value given by an int an a unit. Returns the int value. Throws OptionException on error. longName: the long name to inspect, e.g. 'max-size' shortName: the short name to inspect, e.g. 'm' argument: argument to inspect, e.g. '--max-size=50G'
countChar(String string, String char) int
Counts the occurrences of a char in a string.
dateAsString(DateTime? date, {bool withoutSeconds = false, String separator = '-'}) String
Returns a standard representation of date: YYYY.mm.dd-HH:MM:SS date date to convert. If null the current date and time is taken [withoutSeconds: true: the seconds are not part of the result separator: the string between date and time, default: '-'
dateOption(String longName, String? shortName, String argument) DateTime?
Tests whether the argument has the longName or the shortName and a date (and time). Returns the DateTime or null. Throws OptionException on error. longName: the long name to inspect, e.g. 'log-file' shortName: the short name to inspect, e.g. 'l' argument: argument to inspect, e.g. '--exclude-file=.*.log'
dateToString(String format, [DateTime? date]) String
Converts a date into a string with a given format like the unix command date. format: a string with placeholders, e.g. '%Y.%m.%d-%H:%M:%S' Format placeholders: '%!': full (same as '%Y.%m.%d-%H:%M:%S') '%%': '%' '%d': day (01..31) '%F': date (same as '%Y-%m-%d') '%H': hours (00..23) '%i': iso (same as '%Y-%m-%d %H:%M:%S') '%j': day of the year: (001..366) '%M': minutes (00..59) '%m': month (01..12) '%n': '\n' '%R': time (same as '%H:%M') '%S': seconds (00.59) '%s': seconds since epoch '%W': day of the week (0..6) 0 is monday '%w': week no (01..53) '%Y': year (e.g. 2021) [...]
decimalToInt(String text, int start, [List<int>? length, int? last]) int
Returns the int value of a decimal number in a text starting at index start. text: the string to inspect length: OUT: if not null: the count of digits will be stored in length0 last: if not null: the number detection ends with this index (excluding)
decodeUtf8HmDu(String input) String?
Convert specially UTF-8 encoded non ASCII characters into real UTF-8. hmdu is a program which encodes "more byte" UTF-8 characters into the form "^#", e.g. "^C384#" for Ä input: the string to convert return: the with decoded UTF-8 ("real UTF-8")
enumToString(Object enumValue) String
Converts an enumValue to a string.
globPatternToRegExpression(String pattern) String
Converts a glob pattern to a regular expression string. pattern: a string with wildcards '*' and '?' and char classes, e.g. "[a-z0-9]"
intOption(String longName, String? shortName, String argument, int defaultValue) int
Tests whether the argument has the longName or the shortName and an integer. Returns the value of the int argument or the defaultValue Throws OptionException on error. longName: the long name to inspect, e.g. 'max-length' shortName: the short name to inspect, e.g. 'm' argument: argument to inspect, e.g. '--max-length=3' defaultValue: if the arguments does not match: this value is returned
limitString(String string, dynamic maxSize, {String ellipsis = '...'}) String
Returns the length limited string. string the string to convert, e.g. "abc123" maxSize: the maximum length, e.g. 5 ellipsis: null or a suffix which signals the cut of the string return string (if enough space or null) or the limited string, e.g. "ab..."
notInCharClass(CharClass charClass, String string) int?
Tests whether all characters of string are in the charClass. Returns null if all characters are in the charClass, otherwise the first index of string with a character not in charClass
patternOption(String longName, String? shortName, String argument) RegExp?
Tests whether the argument has the longName or the shortName and a pattern. A pattern is a glob expression (wildcards: '' and '?) or a regular expression (if starting with '|'). Returns the RegExp or null. Throws OptionException on error. longName: the long name to inspect, e.g. 'log-file' shortName: the short name to inspect, e.g. 'l' argument: argument to inspect, e.g. '--exclude-file=.log'
regExpOption(String longName, String? shortName, String argument) RegExp?
Tests whether the argument has the longName or the shortName and a regular expression. Returns the RegExp or null. Throws OptionException on error. longName: the long name to inspect, e.g. 'log-file' shortName: the short name to inspect, e.g. 'l' argument: argument to inspect, e.g. '--exclude-file=.*.log'
replacePlaceholders(String input, Map<String, String> variables, RegExp rexprVariable) String
Replaces placeholders in a string with values stored in a map. input: the input string [variables: a map containing (placeholder, value) pairs rexprVariable a regular expression for one variable. The variable name must be in group(1) returns: the input string with the replaced placeholders
setLogger(BaseLogger logger) → void
stringOption(String longName, String? shortName, String argument, {bool notEmpty = false}) String?
Tests whether the argument has the longName or the shortName and a string. Returns the value of the string argument or null. Throws OptionException on error. longName: the long name to inspect, e.g. 'log-file' shortName: the short name to inspect, e.g. 'l' argument: argument to inspect, e.g. '--log-file=app.log' notEmpty: true: the string may not be empty
stringToDateTime(String dateString) DateTime
Converts the string dateString into a DateTime instance. Throws ArgumentsError on syntax error(s).
stringToEnum<T>(String text, List<T> values) → T?
Converts a text into an enum value. Returns null if text is not valid.

Enums

Bool
bool does not have a undef value (null cannot distincted from false)
CharClass
MysqlType

Exceptions / Errors

DbException
OptionException