From 0b9fd2403072d974e91339867258be0f0e4c92c7 Mon Sep 17 00:00:00 2001 From: Patrick Stewart Date: Fri, 5 Jul 2024 07:32:23 -0700 Subject: [PATCH] update: updating comments --- packages/http/lib/foundation.dart | 23 +++++--- .../lib/src/foundation/parameter_bag.dart | 54 ++++++++++--------- 2 files changed, 46 insertions(+), 31 deletions(-) diff --git a/packages/http/lib/foundation.dart b/packages/http/lib/foundation.dart index 1c1ee06..7b52aed 100644 --- a/packages/http/lib/foundation.dart +++ b/packages/http/lib/foundation.dart @@ -9,19 +9,28 @@ /// This library exports various foundation classes and utilities for web-related operations. /// -/// It includes: -/// - [CountableInterface] for objects that can be counted -/// - [Cookie] for handling HTTP cookies -/// - [HeaderUtils] for working with HTTP headers -/// - [HeaderBag] for managing collections of HTTP headers -/// - [ParameterBag] for handling request parameters -/// - [ResponseHeaderBag] for managing response headers +/// Exports: +/// - [CountableInterface] from 'src/foundation/countable_interface.dart' +/// - [StringableInterface] from 'src/foundation/stringable_interface.dart' +/// - [Filter] from 'src/foundation/filter.dart' +/// - [Cookie] from 'src/foundation/cookie.dart' +/// - [HeaderUtils] from 'src/foundation/header_utils.dart' +/// - [HeaderBag] from 'src/foundation/header_bag.dart' +/// - [ParameterBag] from 'src/foundation/parameter_bag.dart' +/// - [InputBag] from 'src/foundation/input_bag.dart' +/// - [ResponseHeaderBag] from 'src/foundation/response_header_bag.dart' +/// +/// These exports provide a comprehensive set of tools for handling various aspects of web development, +/// including countable objects, string manipulation, filtering, cookies, HTTP headers, request parameters, +/// and response handling. library; export 'src/foundation/countable_interface.dart'; export 'src/foundation/stringable_interface.dart'; +export 'src/foundation/filter.dart'; export 'src/foundation/cookie.dart'; export 'src/foundation/header_utils.dart'; export 'src/foundation/header_bag.dart'; export 'src/foundation/parameter_bag.dart'; +export 'src/foundation/input_bag.dart'; export 'src/foundation/response_header_bag.dart'; \ No newline at end of file diff --git a/packages/http/lib/src/foundation/parameter_bag.dart b/packages/http/lib/src/foundation/parameter_bag.dart index 761b956..171983e 100644 --- a/packages/http/lib/src/foundation/parameter_bag.dart +++ b/packages/http/lib/src/foundation/parameter_bag.dart @@ -346,39 +346,45 @@ abstract class ParameterBag implements Iterable>, Coun } } - /// Filters and transforms a parameter value using a provided function. + /// Filters a parameter value based on the given key. /// /// This method retrieves the value associated with the given [key] and applies - /// a [filterFunction] to transform or validate it. If the key doesn't exist, - /// it returns the [defaultValue]. + /// basic filtering logic. If the key doesn't exist, it returns the [defaultValue]. + /// + /// The current implementation provides a simple string sanitization for string values, + /// trimming whitespace from the beginning and end. For all other types, the value + /// is returned as-is. + /// + /// This method is designed to be overridden or extended in subclasses to provide + /// more sophisticated filtering logic. /// /// Parameters: - /// [key] - The key of the parameter to retrieve and filter. - /// [defaultValue] - Optional. The value to return if the key is not found. - /// [filterFunction] - A function that takes the parameter value as input - /// and returns a transformed or validated value. + /// [key] - The key of the parameter to filter. + /// [defaultValue] - Optional. The value to return if the key doesn't exist. + /// [filter] - Optional. An integer representing the filter type (not used in the base implementation). + /// [options] - Optional. Additional options for filtering (not used in the base implementation). /// /// Returns: - /// The filtered and transformed parameter value, or the defaultValue if - /// the key is not found. - /// - /// Throws: - /// [UnexpectedValueException] if the filterFunction throws an exception, - /// indicating that the parameter value is invalid. + /// The filtered value if the key exists, otherwise the [defaultValue]. /// /// Example: - /// var age = parameterBag.filter('age', - /// defaultValue: 0, - /// filterFunction: (value) => int.parse(value.toString())); - dynamic filter(String key, {dynamic defaultValue, required String Function(dynamic) filterFunction}) { - final value = get(key, defaultValue); - if (value == null) return defaultValue; - - try { - return filterFunction(value); - } catch (e) { - throw UnexpectedValueException('Parameter value "$key" is invalid: ${e.toString()}'); + /// parameterBag.set('name', ' John Doe '); + /// print(parameterBag.filter('name')); // Outputs: 'John Doe' + dynamic filter(String key, {dynamic defaultValue, int? filter, dynamic options}) { + if (!has(key)) { + return defaultValue; } + + var value = get(key); + + // Basic filtering logic, can be overridden or extended in subclasses + if (value is String) { + // Simple string sanitization as an example + return value.trim(); + } + + // For other types, return as is + return value; } /// Returns an iterator for the entries in the parameters map.