dart_bones library
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
- LEVEL_DEBUG → const int
- LEVEL_DETAIL → const int
- LEVEL_FINE → const int
- LEVEL_LOOP → const int
- LEVEL_SUMMERY → const int
Properties
- globalLogger ↔ BaseLogger
-
getter/setter pair
Functions
-
asFloat(
String text, {double? defaultValue}) → double? -
Converts a
text
into an integer.defaultValue
is the return value iftext
is not an integer -
asInt(
String text, {int? defaultValue}) → int? -
Converts a
text
into an integer.defaultValue
is the return value iftext
is not an integer -
boolOption(
String longName, String shortName, String argument) → Bool -
Tests whether the
argument
has thelongName
or theshortName
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 thelongName
or theshortName
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 astring
. -
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 resultseparator
: the string between date and time, default: '-' -
dateOption(
String longName, String? shortName, String argument) → DateTime? -
Tests whether the
argument
has thelongName
or theshortName
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 indexstart
.text
: the string to inspectlength
: 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 "^
-
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 thelongName
or theshortName
and an integer. Returns the value of the int argument or thedefaultValue
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. 5ellipsis
: null or a suffix which signals the cut of thestring
returnstring
(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 thecharClass
. Returns null if all characters are in the charClass, otherwise the first index ofstring
with a character not incharClass
-
patternOption(
String longName, String? shortName, String argument) → RegExp? -
Tests whether the
argument
has thelongName
or theshortName
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 thelongName
or theshortName
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) pairsrexprVariable
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 thelongName
or theshortName
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 iftext
is not valid.