Skip to main content

dartool 0.1.0 copy "dartool: ^0.1.0" to clipboard
dartool: ^0.1.0 copied to clipboard

A Hutool-style toolkit for Dart: strings, collections, dates, regex, validation, conversion and more.

dartool #

pub version 中文文档

A Hutool-style toolkit for Dart -- simple, unified and out-of-the-box.

dartool is the pure-Dart core package of the dartool project. It has zero Flutter dependencies, so it works in both Flutter apps and pure Dart CLI / server projects. Inspired by Hutool, it follows the philosophy of "one method for one problem -- modular, on-demand, no bloat."

Features #

  • Modular -- pick only what you need, no unnecessary dependencies
  • Pure Dart -- zero Flutter dependency, usable in CLI and server projects
  • Unified API -- consistent naming, friendly parameters, ready to use
  • Well tested -- unit tests for every core module
  • Dart 3 + null-safe -- built on Dart 3.9 SDK with lints

Installation #

dependencies:
  dartool: ^0.1.0-dev.2
dart pub get

Quick Start #

import 'package:dartool/dartool.dart';

void main() {
  // String utilities
  print(StrUtil.isBlank('   '));               // true
  print(StrUtil.toCamelCase('hello_world'));   // helloWorld

  // Collection utilities
  print(CollectionUtil.isEmpty([]));            // true
  print(CollectionUtil.distinct([3, 1, 2, 1]));   // [3, 1, 2]

  // Date utilities
  print(DateUtil.formatNow());                  // 2026-09-21 12:00:00

  // Validation utilities
  print(ValidateUtil.isEmail('a@b.com'));       // true
  print(ValidateUtil.isPhone('13800138000'));   // true

  // ID generation
  print(IdUtil.uuid());                         // xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

  // Color utilities
  print(ColorUtil.toHex(0xFF4080FF));           // #4080FF
  print(ColorUtil.hexToInt('#4080ff'));         // 0xFF4080FF

  // Crypto utilities
  print(CryptoUtil.md5('hello'));               // 5d41402abc4b2a76b9719d911017c592
  print(CryptoUtil.base64Encode('hello'));      // aGVsbG8=

  // Result container
  final r = Result.success('ok');
  print(r.isSuccess);                           // true

  // Optional container
  final op = Optional.of('hello');
  print(op.getOrElse('default'));                 // hello
}

API Overview #

Class Description
StrUtil String blank checks, case conversion, trimming, truncation, camel/snake conversion
CollectionUtil Collection empty checks, dedup, pagination, flatten, grouping
DateUtil Formatting, parsing, timestamp conversion, relative time, timezones
RegexUtil Common regex patterns (phone, email, URL, ID card) and matchers
EnumUtil Enum name/value resolution, iteration
ValidateUtil Data validation (non-null, email, phone, ID card, range)
ConvertUtil Type conversion (String <-> num <-> bool <-> DateTime) with fallbacks
IdUtil UUID, snowflake ID, short unique ID generation
ColorUtil Color conversion (ARGB int <-> hex), luminance, interpolation
CryptoUtil Base64 / Hex encoding, MD5 / SHA1 / SHA256 / SHA512 hashing, HMAC, XOR obfuscation
Optional Null-safe value container (Java Optional style)
Result Success / failure container with data or error

Development #

# Install melos (from workspace root)
dart pub global activate melos
melos bootstrap

# Develop inside this package
cd packages/dartool
dart analyze
dart test

Documentation #

  • API docs are generated by dart doc
  • Source code contains detailed documentation comments
  • 中文文档

Contributing #

Issues and PRs are welcome. Follow Conventional Commits, respect the lints rules, and add tests for new features.

License #

MIT

1
likes
160
points
402
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

A Hutool-style toolkit for Dart: strings, collections, dates, regex, validation, conversion and more.

Homepage
Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

crypto

More

Packages that depend on dartool