From a0e1208a7201efe74e51f7270194bc69340cc7a1 Mon Sep 17 00:00:00 2001 From: Jeff Peiffer Date: Sun, 16 Jul 2023 13:42:25 -0400 Subject: [PATCH] Updated json_class --- CHANGELOG.md | 5 ++ .../functions/date_time_functions.dart | 44 ++++----- .../functions/duration_functions.dart | 89 ++++++++++--------- lib/src/expressions/standard_members.dart | 12 +-- pubspec.yaml | 12 +-- 5 files changed, 84 insertions(+), 78 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2556768..ab62f3b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## [3.1.0] - July 16th, 2023 + +* Updated to json_class 3.0.0 + + ## [3.0.6+2] - July 4, 2023 * Automated dependency updates diff --git a/lib/src/expressions/functions/date_time_functions.dart b/lib/src/expressions/functions/date_time_functions.dart index e1e347d..25f2786 100644 --- a/lib/src/expressions/functions/date_time_functions.dart +++ b/lib/src/expressions/functions/date_time_functions.dart @@ -14,51 +14,51 @@ class DateTimeFunctions { second != null || millisecond != null) ? DateTime( - JsonClass.parseInt(value) ?? 0, - JsonClass.parseInt(month) ?? 1, - JsonClass.parseInt(date) ?? 1, - JsonClass.parseInt(hour) ?? 0, - JsonClass.parseInt(minute) ?? 0, - JsonClass.parseInt(second) ?? 0, - JsonClass.parseInt(millisecond) ?? 0, + JsonClass.maybeParseInt(value) ?? 0, + JsonClass.maybeParseInt(month) ?? 1, + JsonClass.maybeParseInt(date) ?? 1, + JsonClass.maybeParseInt(hour) ?? 0, + JsonClass.maybeParseInt(minute) ?? 0, + JsonClass.maybeParseInt(second) ?? 0, + JsonClass.maybeParseInt(millisecond) ?? 0, ) : value is Map ? DateTime( - JsonClass.parseInt(value['year']) ?? 0, - JsonClass.parseInt(value['month']) ?? 1, - JsonClass.parseInt(value['date'] ?? value['day']) ?? 1, - JsonClass.parseInt(value['hour']) ?? 0, - JsonClass.parseInt(value['minute']) ?? 0, - JsonClass.parseInt(value['second']) ?? 0, - JsonClass.parseInt(value['milliseconds']) ?? 0, + JsonClass.maybeParseInt(value['year']) ?? 0, + JsonClass.maybeParseInt(value['month']) ?? 1, + JsonClass.maybeParseInt(value['date'] ?? value['day']) ?? 1, + JsonClass.maybeParseInt(value['hour']) ?? 0, + JsonClass.maybeParseInt(value['minute']) ?? 0, + JsonClass.maybeParseInt(value['second']) ?? 0, + JsonClass.maybeParseInt(value['milliseconds']) ?? 0, ) : value is List ? DateTime( - JsonClass.parseInt( + JsonClass.maybeParseInt( value.isNotEmpty ? value[0] : null) ?? 0, - JsonClass.parseInt( + JsonClass.maybeParseInt( value.length > 1 ? value[1] : null) ?? 1, - JsonClass.parseInt( + JsonClass.maybeParseInt( value.length > 2 ? value[2] : null) ?? 1, - JsonClass.parseInt( + JsonClass.maybeParseInt( value.length > 3 ? value[3] : null) ?? 0, - JsonClass.parseInt( + JsonClass.maybeParseInt( value.length > 4 ? value[4] : null) ?? 0, - JsonClass.parseInt( + JsonClass.maybeParseInt( value.length > 5 ? value[5] : null) ?? 0, - JsonClass.parseInt( + JsonClass.maybeParseInt( value.length > 6 ? value[6] : null) ?? 0, ) : (value is num || value is String) ? DateTime.fromMillisecondsSinceEpoch( - JsonClass.parseInt(value) ?? 0) + JsonClass.maybeParseInt(value) ?? 0) : value == null ? DateTime.now() : throw Exception( diff --git a/lib/src/expressions/functions/duration_functions.dart b/lib/src/expressions/functions/duration_functions.dart index 2b2d6ba..ce006ff 100644 --- a/lib/src/expressions/functions/duration_functions.dart +++ b/lib/src/expressions/functions/duration_functions.dart @@ -4,54 +4,55 @@ import 'package:json_class/json_class.dart'; class DurationFunctions { /// The functions related to the Duration creation static final functions = { - 'Duration': (value, [hours, minutes, seconds, milliseconds]) => (hours != - null || - minutes != null || - seconds != null || - milliseconds != null) - ? Duration( - days: JsonClass.parseInt(value) ?? 0, - hours: JsonClass.parseInt(hours) ?? 0, - minutes: JsonClass.parseInt(minutes) ?? 0, - seconds: JsonClass.parseInt(seconds) ?? 0, - milliseconds: JsonClass.parseInt(milliseconds) ?? 0, - ) - : value is Map + 'Duration': (value, [hours, minutes, seconds, milliseconds]) => + (hours != null || + minutes != null || + seconds != null || + milliseconds != null) ? Duration( - days: JsonClass.parseInt(value['days']) ?? 0, - hours: JsonClass.parseInt(value['hours']) ?? 0, - minutes: JsonClass.parseInt(value['minutes']) ?? 0, - seconds: JsonClass.parseInt(value['seconds']) ?? 0, - milliseconds: JsonClass.parseInt(value['milliseconds']) ?? 0, + days: JsonClass.maybeParseInt(value) ?? 0, + hours: JsonClass.maybeParseInt(hours) ?? 0, + minutes: JsonClass.maybeParseInt(minutes) ?? 0, + seconds: JsonClass.maybeParseInt(seconds) ?? 0, + milliseconds: JsonClass.maybeParseInt(milliseconds) ?? 0, ) - : value is List + : value is Map ? Duration( - days: JsonClass.parseInt( - value.isNotEmpty ? value[0] : null) ?? - 0, - hours: JsonClass.parseInt( - value.length > 1 ? value[1] : null) ?? - 0, - minutes: JsonClass.parseInt( - value.length > 2 ? value[2] : null) ?? - 0, - seconds: JsonClass.parseInt( - value.length > 3 ? value[3] : null) ?? - 0, - milliseconds: JsonClass.parseInt( - value.length > 4 ? value[4] : null) ?? - 0, + days: JsonClass.maybeParseInt(value['days']) ?? 0, + hours: JsonClass.maybeParseInt(value['hours']) ?? 0, + minutes: JsonClass.maybeParseInt(value['minutes']) ?? 0, + seconds: JsonClass.maybeParseInt(value['seconds']) ?? 0, + milliseconds: + JsonClass.maybeParseInt(value['milliseconds']) ?? 0, ) - : value is String || value is num - ? JsonClass.parseDurationFromMillis(value)! - : throw Exception( - '[Duration]: expected [value] to be a Map, a List, a String, or a num but encountered: ${value?.runtimeType}', - ), - 'days': (value) => Duration(hours: JsonClass.parseInt(value)! * 24), - 'hours': (value) => Duration(minutes: JsonClass.parseInt(value)!), + : value is List + ? Duration( + days: JsonClass.maybeParseInt( + value.isNotEmpty ? value[0] : null) ?? + 0, + hours: JsonClass.maybeParseInt( + value.length > 1 ? value[1] : null) ?? + 0, + minutes: JsonClass.maybeParseInt( + value.length > 2 ? value[2] : null) ?? + 0, + seconds: JsonClass.maybeParseInt( + value.length > 3 ? value[3] : null) ?? + 0, + milliseconds: JsonClass.maybeParseInt( + value.length > 4 ? value[4] : null) ?? + 0, + ) + : value is String || value is num + ? JsonClass.maybeParseDurationFromMillis(value)! + : throw Exception( + '[Duration]: expected [value] to be a Map, a List, a String, or a num but encountered: ${value?.runtimeType}', + ), + 'days': (value) => Duration(hours: JsonClass.maybeParseInt(value)! * 24), + 'hours': (value) => Duration(minutes: JsonClass.maybeParseInt(value)!), 'milliseconds': (value) => - Duration(milliseconds: JsonClass.parseInt(value)!), - 'minutes': (value) => Duration(minutes: JsonClass.parseInt(value)!), - 'seconds': (value) => Duration(seconds: JsonClass.parseInt(value)!), + Duration(milliseconds: JsonClass.maybeParseInt(value)!), + 'minutes': (value) => Duration(minutes: JsonClass.maybeParseInt(value)!), + 'seconds': (value) => Duration(seconds: JsonClass.maybeParseInt(value)!), }; } diff --git a/lib/src/expressions/standard_members.dart b/lib/src/expressions/standard_members.dart index 38eab81..4575166 100644 --- a/lib/src/expressions/standard_members.dart +++ b/lib/src/expressions/standard_members.dart @@ -141,7 +141,7 @@ dynamic _processDateTime(DateTime target, String name) { target.millisecondsSinceEpoch + ((duration is Duration) ? duration.inMilliseconds - : JsonClass.parseInt(duration)!), + : JsonClass.maybeParseInt(duration)!), isUtc: target.isUtc, ); break; @@ -170,7 +170,7 @@ dynamic _processDateTime(DateTime target, String name) { result = (duration) => target.subtract( duration is Duration ? duration - : Duration(milliseconds: JsonClass.parseInt(duration)!), + : Duration(milliseconds: JsonClass.maybeParseInt(duration)!), ); break; @@ -198,7 +198,7 @@ dynamic _processDuration(Duration target, String name) { target.inMilliseconds + (duration is Duration ? duration.inMilliseconds - : JsonClass.parseInt(duration)!); + : JsonClass.maybeParseInt(duration)!); break; case 'compareTo': @@ -230,7 +230,7 @@ dynamic _processDuration(Duration target, String name) { milliseconds: target.inMilliseconds - (duration is Duration ? duration.inMilliseconds - : JsonClass.parseInt(duration)!), + : JsonClass.maybeParseInt(duration)!), ); break; } @@ -390,7 +390,7 @@ dynamic _processList(List target, String name) { case 'toJson': result = ([padding]) { - final indent = JsonClass.parseInt(padding) ?? 0; + final indent = JsonClass.maybeParseInt(padding) ?? 0; return indent == 0 ? json.encode(target) @@ -488,7 +488,7 @@ dynamic _processMap(Map target, String name) { case 'toJson': result = ([padding]) { - final indent = JsonClass.parseInt(padding) ?? 0; + final indent = JsonClass.maybeParseInt(padding) ?? 0; return indent == 0 ? json.encode(target) diff --git a/pubspec.yaml b/pubspec.yaml index 08806a9..9145dd5 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,18 +1,18 @@ name: 'template_expressions' description: 'A Dart library to process string based templates using expressions.' homepage: 'https://github.com/peiffer-innovations/template_expressions' -version: '3.0.6+2' +version: '3.1.0' -environment: +environment: sdk: '>=3.0.0 <4.0.0' -dependencies: +dependencies: convert: '^3.1.1' crypto: '^3.0.1' encrypt: '^5.0.1' fake_async: '^1.3.0' intl: '^0.18.1' - json_class: '^2.2.2+1' + json_class: '^3.0.0' json_path: '^0.6.0' logging: '^1.2.0' meta: '^1.9.1' @@ -22,11 +22,11 @@ dependencies: rxdart: '^0.27.7' yaon: '^1.1.2+1' -dev_dependencies: +dev_dependencies: flutter_lints: '^2.0.2' test: '^1.24.4' -ignore_updates: +ignore_updates: - 'archive' - 'async' - 'boolean_selector'