attributes library

Decode and encode structured data type-safely from JSON with data utilities.

Generic data structures for values, identifiers, entities and data objects.

Supports type-safe and null-safe accessors for value properties.

DataObject can represent data like JSON Objects or properties as a map. DataArray can represent data like JSON Arrays or properties as a list.

Usage: import package:attributes/attributes.dart

Classes

Counted
An interface for a collection with countable items.
DataArray
An interface for a data array with property values accessed by int keys (or indexes).
DataElement<K>
An interface for a data element that is a collection with accessors for typed values.
DataObject
An interface for a data object with property values accessed by String keys.
Entity
An interface for an entity with an optional id and required properties (as a data object).
EntityBase
An immutable base implementation of Entity.
Identifier
An interface for an identifier of something, represented as String, int or BigInt.
Primitive
A interface for a primitive value with type and null safe accessors for data.
PrimitiveAccessor<K>
An interface to access typed primitive values by keys of type K.
StringOrInteger
An interface for a value representing String, int or BigInt data.
Value
An interface for a value with type and null safe accessors for data implementing Primitive.
ValueAccessor<K>
An interface to access typed values by keys of type K.

Mixins

ValueAccessorMixin<K>
A base mixin with a partial implementation of ValueAccessor.

Functions

toBigIntValue(Object? data, {BigInt? min, BigInt? max}) BigInt
Converts data to BigInt or throws FormatException if cannot convert.
toBoolValue(Object? data) bool
Converts data to bool or throws FormatException if cannot convert.
toDoubleValue(Object? data, {double? min, double? max}) double
Converts data to double or throws FormatException if cannot convert.
toIdValue(Object? data) Identifier
Converts data to Identifier or throws FormatException if cannot convert.
toIntValue(Object? data, {int? min, int? max}) int
Converts data to int or throws FormatException if cannot convert.
toNullableValueMapOf<K extends Object, V extends Object>(Map<K, Object?> map, {bool isExposed = false}) Map<K, V?>
Converts map to a value map of K to V?, or throws if cannot convert.
toNullableValueOf<T extends Object>(Object? data) → T?
Converts data to a value of T? or throws if cannot convert.
toNullableValuesOf<T extends Object>(Iterable<Object?> list, {bool isExposed = false}) Iterable<T?>
Converts list to a value iterable of T? or throws if cannot convert.
toNumValue(Object? data, {num? min, num? max}) num
Converts data to num or throws FormatException if cannot convert.
toStringValue(Object? data) String
Converts data to String or throws FormatException if cannot convert.
toTimeMillisUTCValue(Object? data, {bool isUTCSource = false}) DateTime
Converts the data to a DateTime value.
toTimeUTCValue(Object? data, {DateFormat? sourceFormat, bool isUTCSource = false}) DateTime
Converts the data to a DateTime value.
toValueMapOf<K extends Object, V extends Object>(Map<K, Object?> map, {bool isExposed = false}) Map<K, V>
Converts map to a value map of K to V, or throws if cannot convert.
toValueOf<T extends Object>(Object? data) → T
Converts data to a value of T or throws FormatException if cannot.
toValuesOf<T extends Object>(Iterable<Object?> list, {bool isExposed = false}) Iterable<T>
Converts list to a value iterable of T or throws if cannot convert.

Exceptions / Errors

ConversionException
A FormatException notifying about an unsupported conversion.
InvalidValueException
A FormatException notifying about an invalid value
NullValueException
A FormatException notifying about a null value.
UndefinedValueException
A FormatException notifying about an undefined or missing value.