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
-
A data array with property values accessed by
int
keys (or indexes). -
DataElement<
K> - A data element as a collection with accessors for typed values.
- DataObject
-
A data object with property values accessed by
String
keys. - Entity
- An entity with an optional id and required properties as a data object.
- EntityBase
- An immutable base implementation of Entity.
- Identifier
-
An identifier of something, represented as
String
,int
orBigInt
. - Primitive
- 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
orBigInt
data. - Value
- A value with type and null safe accessors for data extending Primitive.
-
ValueAccessor<
K> -
An interface to access typed values by keys of type
K
.
Mixins
-
ValueAccessorMixin<
K> - A partial implementation of ValueAccessor.
Functions
-
toBigIntValue(
Object? data, {BigInt? min, BigInt? max}) → BigInt -
Converts
data
toBigInt
or throws FormatException if cannot convert. -
toBoolValue(
Object? data) → bool -
Converts
data
tobool
or throws FormatException if cannot convert. -
toDoubleValue(
Object? data, {double? min, double? max}) → double -
Converts
data
todouble
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
toint
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 ofK
toV?
, or throws if cannot convert. -
toNullableValueOf<
T extends Object> (Object? data) → T? -
Converts
data
to a value ofT?
or throws if cannot convert. -
toNullableValuesOf<
T extends Object> (Iterable< Object?> list, {bool isExposed = false}) → Iterable<T?> -
Converts
list
to a value iterable ofT?
or throws if cannot convert. -
toNumValue(
Object? data, {num? min, num? max}) → num -
Converts
data
tonum
or throws FormatException if cannot convert. -
toStringValue(
Object? data) → String -
Converts
data
toString
or throws FormatException if cannot convert. -
toTimeMillisUTCValue(
Object? data, {bool isUTCSource = false}) → DateTime -
Converts the
data
to aDateTime
value. -
toTimeUTCValue(
Object? data, {DateFormat? sourceFormat, bool isUTCSource = false}) → DateTime -
Converts the
data
to aDateTime
value. -
toValueMapOf<
K extends Object, V extends Object> (Map< K, Object?> map, {bool isExposed = false}) → Map<K, V> -
Converts
map
to a value map ofK
toV
, or throws if cannot convert. -
toValueOf<
T extends Object> (Object? data) → T -
Converts
data
to a value ofT
or throws FormatException if cannot. -
toValuesOf<
T extends Object> (Iterable< Object?> list, {bool isExposed = false}) → Iterable<T> -
Converts
list
to a value iterable ofT
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.