Skip to content

Source on GitHublib/src/utils/fast_extension/

Overview

Import package:fast_package/fast_package.dart to use Dart extensions on String / nullable strings, nullable bool / int / double / num, and non-null num. APIs are getters or instance methods; they do not change the underlying types.

ExtensionReceiverSummary
FastStringExtensionStringcamel / snake / kebab case, isValidUrl
FastStringNullSafeExtensionString?empty defaults, optional default, non-null assert
FastBoolNullSafeExtensionbool?default false / true, optional default
FastNumExtensionnumrange check, divisibility
FastNumNullSafeExtension etc.num? / int? / double?zero defaults and nullSafeThrow

String case

FastStringExtension splits on word boundaries (spaces, -, _, ., and camelCase breaks), then rejoins. Empty string → ''.

Examples

dart
'hello_world'.toCamelCase;      // helloWorld
'user-name'.toPascalCase;       // UserName
'helloWorld'.toSnakeCase;       // HELLO_WORLD
'FirstName'.toSnakeCaseLower;   // first_name
'hello_world'.toKebabCase;      // hello-world

'https://example.com'.isValidUrl; // true

API reference


toCamelCase / toPascalCase

Lower camelCase (first word lowercase) and PascalCase (each word capitalized).

TypeDescription
ReturnString (getter)Converted name; '' when isEmpty.

toSnakeCase / toSnakeCaseLower

UPPER_SNAKE and lower_snake.

TypeDescription
ReturnString (getter)Words joined with _.

toKebabCase

Lowercase kebab-case with -.

TypeDescription
ReturnString (getter)Words joined with -.

isValidUrl

Rough URL check via built-in regex (optional http/https).

TypeDescription
Returnbool (getter)true when matched.

Nullable strings

FastStringNullSafeExtension on String?.

Examples

dart
String? name;
name.nullSafeOrEmpty;           // ''
name.nullSafe(value: 'guest');  // guest
name.isNullOrEmpty;             // true

name.nullSafeThrow(); // throws ArgumentError when null (optional message / exception)

API reference


nullSafeOrEmpty

TypeDescription
ReturnString (getter)null''.

nullSafe

ParameterTypeRequiredDescription
valueString?noFallback when null; still empty → nullSafeOrEmpty.
ReturnTypeDescription
StringUse this when non-null; else value then empty fallback.

nullSafeThrow

ParameterTypeRequiredDescription
exceptionException?noCustom exception; default ArgumentError.
messageString?noDefault message when no exception.
ReturnTypeDescription
StringReturns self when non-null.

isNullOrEmpty

TypeDescription
Returnbool (getter)true for null or ''.

Nullable booleans

FastBoolNullSafeExtension on bool?.

Examples

dart
bool? flag;
flag.nullSafeOrFalse;  // false
flag.nullSafeOrTrue;   // true
flag.nullSafe(value: true); // true

API reference

APIReturnDescription
nullSafeOrFalseboolnullfalse
nullSafeOrTrueboolnulltrue
nullSafe({bool? value})boolFallback via value, then nullSafeOrFalse
nullSafeThrow({Exception? exception})boolThrow when null; else self

Number utilities

FastNumExtension on num (non-null).

Examples

dart
5.isBetween(1, 10);   // true (closed interval; argument order ignored)
10.isDivisibleBy(2);  // true
10.isDivisibleBy(0);  // false (divisor 0)

API reference


isBetween

ParameterTypeRequiredDescription
betweenOnenumyesOne end of the interval
betweenTwonumyesOther end
ReturnTypeDescription
boolWhether this lies in the closed interval

isDivisibleBy

ParameterTypeRequiredDescription
divisornumyesDivisor; 0false
ReturnTypeDescription
boolWhether division is exact

Nullable numbers

Separate extensions for int?, double?, and num? with the same shape; zero defaults are 0, 0.0, and 0.

Examples

dart
int? count;
count.nullSafeOrEmpty;        // 0
count.nullSafe(value: 42);    // 42
count.nullSafeThrow();        // null → ArgumentError

double? rate;
rate.nullSafeOrEmpty;         // 0.0

API reference

Each type provides:

APIDescription
nullSafeOrEmptyZero value when null
nullSafe({T? value})Optional default, then zero fallback
nullSafeThrow({Exception? exception})Non-null assert

Types: FastIntNullSafeExtension, FastDoubleNullSafeExtension, FastNumNullSafeExtension.

Released under the MIT License