caster 1.0.0
caster: ^1.0.0 copied to clipboard
A safe, zero-dependency Dart casting utility with built-in fallbacks, custom defaults, and map extraction extensions.
1.0.0 #
- Initial release of
caster. - Added
safeCast<T>with multi-tiered resolution:- Exact match fast path.
- Explicit fallback support.
- Custom registered type defaults.
- Built-in type defaults (
int,double,num,bool,String,List,Set,Map). - Nullable target fallback.
- Concrete type enforcement (
CasterArgumentExceptionifTisObject).
- Added
safeCastOrNull<T>for quick nullable casting without default fallback resolution. - Added central
Casternamespace for configuration and type default management:Caster.registerDefaultValue<T>andCaster.registerDefaultValuesCaster.unregisterDefaultValue<T>andCaster.unregisterDefaultValuesCaster.resetDefaultValuesCaster.builtInDefault<T>()Caster.loggerName(configurable tag for diagnostic logs)Caster.debug(global flag to enable diagnostic developer logging)
- Added
useDefaultsparameter (defaults totrue) tosafeCastandsafeCastFirstto selectively disable automatic fallback defaults. - Added
MapCaster<K, V>extension methods (insrc/map_caster.dart):safeCast<T>: Safely extracts and casts a single value.safeCastOrNull<T>: Safely extracts and casts a single value, returningnullon failure.safeCastFirst<T>: Evaluates keys in order and returns the first castable value.safeCastList<T>: Safely extracts and filters elements into a typedList<T>.safeCastListOrNull<T>: Safely extracts elements or returnsnullif the key is absent/non-iterable.convert<T>: Transforms a value via custom converter function with required fallback.tryConvert<T>: Transforms a value via custom converter function returningT?with optional fallback.convertList<T>: Maps and filters collection elements into a typedList<T>with optional element fallback.convertListOrNull<T>: Maps elements or returnsnullif the key is absent/non-iterable.
- Added typed exception hierarchy with
CasterException(implementingException),CasterArgumentException, andCasterTypeException. - Concrete type enforcement rejecting
Object,Object?, anddynamicwithCasterArgumentException. - Added zero-dependency debug diagnostic logging directly via
dart:developer.log.