finch_tools library

Classes

ConvertSize
A utility class for converting file sizes from bytes to human-readable format. The ConvertSize class provides a static method for converting a file size in bytes into a more understandable string format, including bytes (B), kilobytes (KB), megabytes (MB), and gigabytes (GB). The conversion takes into account the size of the file and returns the size in the appropriate units with two decimal places for precision.
FinchJson
Provides utility methods for encoding and decoding JSON data. The FinchJson class includes static methods for converting data to JSON format and parsing JSON strings into Dart objects. It handles custom encoding for specific types such as TString, ObjectId, DateTime, and Duration.
QueryString
A utility class for parsing query strings into a Map. This class provides a static method to convert a query string into a map, handling URL decoding and array notation.
TString
Class representing a translatable string. Use this class to handle translations of a string based on the current or specified language.

Extensions

ConvertMap on Map
Extension methods for Map to provide utilities for map manipulation. This extension adds methods to the Map class for joining map entries into a single string with a specified separator.
ConvertString on String
Extension methods for String to provide various utilities for string manipulation, encoding, decoding, and hashing. This extension adds methods to the String class for tasks such as hashing the string using MD5, converting between different encoding formats (Base64, Base32), converting a string to an ObjectId, and generating slugs.
DateTimeFormat on DateTime
FinchDirectory on Directory
FinchFile on File
Extension methods for File to provide convenient path and name utilities. FinchFile adds helpful methods to the File class for extracting different parts of file paths and names. This extension simplifies common file operations by providing direct access to file components without manually parsing paths. Example usage:
MapTools on Map<K, V>
Provides utility methods for manipulating Map instances. This extension adds additional functionality to the Map class, allowing you to easily remove multiple entries, select a subset of entries, and add new entries. Example usage:
SafeString on String
Extension on String to provide additional security and sanitization methods.
StringValidator on String
Extension on String to provide additional validation and conversion methods.
TranslateString on String
Extension on String to provide translation functionality.

Properties

pathApp String
Retrieves the base directory path of the application. This getter uses the script path from Platform.script and navigates up two levels to return the root application path. Example usage:
no setter

Functions

endpointNorm(List<String> paths, {bool normSlashs = true, dynamic endWithSlash = true, dynamic startWithSlash = true}) String
Normalizes endpoint paths for URL routing with customizable formatting options. This function takes a list of path segments and combines them into a normalized endpoint path suitable for web routing. It provides fine-grained control over the formatting including slash handling and path structure. normSlashs If true, converts backslashes to forward slashes (default: true) endWithSlash If true, ensures the path ends with a forward slash (default: true) startWithSlash If true, ensures the path starts with a forward slash (default: true) The function also handles double slashes by replacing them with single slashes Example usage:
joinPaths(List<String> paths) String
Joins a list of paths into a single normalized path string. The first element in paths is joined as-is, while subsequent elements are normalized using pathNorm to ensure consistency. Example usage:
pathNorm(String path, {bool? normSlashs, dynamic endWithSlash = false}) String
Normalizes a given path by removing leading slashes and optionally converting backslashes to forward slashes. The normSlashs parameter, if set to true, replaces all backslashes (\) with forward slashes (/) in the normalized path. Example usage:
pathsEqual(List<String> paths, {bool normSlashs = true, dynamic endWithSlash = true, dynamic startWithSlash = true}) bool
Compares multiple paths for equality after normalization. This function normalizes all provided paths using the same formatting options and then compares them to determine if they represent the same endpoint. This is useful for route matching and path comparison in web applications. paths List of path strings to compare for equality normSlashs If true, converts backslashes to forward slashes (default: true) endWithSlash If true, ensures paths end with a forward slash (default: true) startWithSlash If true, ensures paths start with a forward slash (default: true) Returns true if all paths are equivalent after normalization, false otherwise. Returns true if the paths list is empty. Example usage:
pathTo(String path) String
Normalizes and joins a given path with the application base directory path. This function normalizes the input path, formats it as a URI, applies additional path normalization, and finally joins it with the application directory path obtained from pathApp. Example usage: