update: updating comments
This commit is contained in:
parent
fa59a8c7fc
commit
0b9fd24030
2 changed files with 46 additions and 31 deletions
|
@ -9,19 +9,28 @@
|
||||||
|
|
||||||
/// This library exports various foundation classes and utilities for web-related operations.
|
/// This library exports various foundation classes and utilities for web-related operations.
|
||||||
///
|
///
|
||||||
/// It includes:
|
/// Exports:
|
||||||
/// - [CountableInterface] for objects that can be counted
|
/// - [CountableInterface] from 'src/foundation/countable_interface.dart'
|
||||||
/// - [Cookie] for handling HTTP cookies
|
/// - [StringableInterface] from 'src/foundation/stringable_interface.dart'
|
||||||
/// - [HeaderUtils] for working with HTTP headers
|
/// - [Filter] from 'src/foundation/filter.dart'
|
||||||
/// - [HeaderBag] for managing collections of HTTP headers
|
/// - [Cookie] from 'src/foundation/cookie.dart'
|
||||||
/// - [ParameterBag] for handling request parameters
|
/// - [HeaderUtils] from 'src/foundation/header_utils.dart'
|
||||||
/// - [ResponseHeaderBag] for managing response headers
|
/// - [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;
|
library;
|
||||||
|
|
||||||
export 'src/foundation/countable_interface.dart';
|
export 'src/foundation/countable_interface.dart';
|
||||||
export 'src/foundation/stringable_interface.dart';
|
export 'src/foundation/stringable_interface.dart';
|
||||||
|
export 'src/foundation/filter.dart';
|
||||||
export 'src/foundation/cookie.dart';
|
export 'src/foundation/cookie.dart';
|
||||||
export 'src/foundation/header_utils.dart';
|
export 'src/foundation/header_utils.dart';
|
||||||
export 'src/foundation/header_bag.dart';
|
export 'src/foundation/header_bag.dart';
|
||||||
export 'src/foundation/parameter_bag.dart';
|
export 'src/foundation/parameter_bag.dart';
|
||||||
|
export 'src/foundation/input_bag.dart';
|
||||||
export 'src/foundation/response_header_bag.dart';
|
export 'src/foundation/response_header_bag.dart';
|
|
@ -346,39 +346,45 @@ abstract class ParameterBag implements Iterable<MapEntry<String, dynamic>>, 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
|
/// 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,
|
/// basic filtering logic. If the key doesn't exist, it returns the [defaultValue].
|
||||||
/// 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:
|
/// Parameters:
|
||||||
/// [key] - The key of the parameter to retrieve and filter.
|
/// [key] - The key of the parameter to filter.
|
||||||
/// [defaultValue] - Optional. The value to return if the key is not found.
|
/// [defaultValue] - Optional. The value to return if the key doesn't exist.
|
||||||
/// [filterFunction] - A function that takes the parameter value as input
|
/// [filter] - Optional. An integer representing the filter type (not used in the base implementation).
|
||||||
/// and returns a transformed or validated value.
|
/// [options] - Optional. Additional options for filtering (not used in the base implementation).
|
||||||
///
|
///
|
||||||
/// Returns:
|
/// Returns:
|
||||||
/// The filtered and transformed parameter value, or the defaultValue if
|
/// The filtered value if the key exists, otherwise the [defaultValue].
|
||||||
/// the key is not found.
|
|
||||||
///
|
|
||||||
/// Throws:
|
|
||||||
/// [UnexpectedValueException] if the filterFunction throws an exception,
|
|
||||||
/// indicating that the parameter value is invalid.
|
|
||||||
///
|
///
|
||||||
/// Example:
|
/// Example:
|
||||||
/// var age = parameterBag.filter('age',
|
/// parameterBag.set('name', ' John Doe ');
|
||||||
/// defaultValue: 0,
|
/// print(parameterBag.filter('name')); // Outputs: 'John Doe'
|
||||||
/// filterFunction: (value) => int.parse(value.toString()));
|
dynamic filter(String key, {dynamic defaultValue, int? filter, dynamic options}) {
|
||||||
dynamic filter(String key, {dynamic defaultValue, required String Function(dynamic) filterFunction}) {
|
if (!has(key)) {
|
||||||
final value = get(key, defaultValue);
|
return defaultValue;
|
||||||
if (value == null) return defaultValue;
|
|
||||||
|
|
||||||
try {
|
|
||||||
return filterFunction(value);
|
|
||||||
} catch (e) {
|
|
||||||
throw UnexpectedValueException('Parameter value "$key" is invalid: ${e.toString()}');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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.
|
/// Returns an iterator for the entries in the parameters map.
|
||||||
|
|
Loading…
Reference in a new issue