safe_converter 1.2.0
safe_converter: ^1.2.0 copied to clipboard
A high-performance utility for safely converting dynamic values to specific types (int, double, bool, DateTime, etc.) without runtime exceptions.
CHANGELOG #
1.2.0 Fluent Try Aliases 🍭 #
This update introduces concise tryxx aliases for all OrNull methods to improve developer experience and code readability.
New Features #
- Try Aliases: Added shorter
tryxxaliases for all conversion methods.- Map Extension:
tryGetInt,tryGetBool,tryGetString,tryGetList,tryGetMap,tryGetT, etc. - Object Extension:
try2Int,try2Bool,try2String,try2T, etc. - Top-level Functions:
tryInt,tryBool,tryString,tryList,tryMap,tryT, etc.
- Map Extension:
- Improved Fluent API: Enhanced
Objectextensions withtryprefixes for more natural chain calls.
1.1.0 Deep Path Access 🔥 #
This update introduces powerful deep path access and automatic JSON decoding during traversal.
New Features #
- Deep Path Access: Support for dot notation (e.g.,
data.user.name) to access nested fields inMap. - List Index Support: Access list elements by index within paths (e.g.,
items.0.id). - Automatic JSON Decoding: The library now automatically detects and decodes JSON strings in the middle of a path, allowing seamless traversal through serialized data.
- Generic Path Access: Added
getTOrNull<T>(key)andgetT<T>(key)toMapextensions for flexible, type-safe path access.
Improvements #
- Refactored core traversal logic into a private
_gethelper for better consistency and performance. - Enhanced internal robust type checking during path resolution.
1.0.0 Initial Release 🚀 #
The first stable release of safe_convert, providing a robust and developer-friendly way to handle dynamic type conversion in Dart and Flutter.
Core Features #
- Comprehensive Type Support: Safe conversion for
int,double,num,bool,String,DateTime,List, andMap. - Smart Parsing:
- Numeric strings (e.g.,
"123.4") are automatically parsed tointordouble. - Boolean strings support multiple formats like
"yes/no","on/off","true/false", and"1/0". DateTimesupport for both ISO8601 strings and millisecond timestamps.
- Numeric strings (e.g.,
- Fluent Extensions:
SafeConvertOnObject2XXX: Perform conversions directly on anyObject.SafeConvertOnMap2XXX: Safely extract and convert values fromMapby key.
- Production Monitoring: Global logging via
SafeConvertConfigto track and report conversion failures in real-world data. - Custom Object Codecs: Support for registering custom
ObjCodecto handle complex Model parsing viaregisterCodec. - JSON Integration: Automatic
json.encodesupport forMapandListwhen converting toString. - Zero Dependencies: Pure Dart implementation, suitable for Flutter, Web, and Server-side Dart.
- Fully Documented: All public APIs come with English documentation and usage examples.
- High Test Coverage: Extensive unit tests covering edge cases like
null,NaN,Infinity, and invalid formats.