Safe Lodash

A Dart utility library inspired by JavaScript Lodash. It provides a variety of helpful functions to make working with and manipulating data in Dart easier and safer.

pub package License: MIT

Table of Contents

Installation

Add the following dependency to your Dart project's pubspec.yaml file:

dependencies:
  safe_lodash: ^0.0.1

Then run:

dart pub get

Quick Start

import 'package:safe_lodash/safe_lodash.dart';

void main() {
  // Chunk an array
  final chunked = chunk([1, 2, 3, 4, 5], 2);
  print(chunked); // Output: [[1, 2], [3, 4], [5]]

  // Remove falsy values
  final cleaned = compact([0, 1, false, 2, '', 3, null]);
  print(cleaned); // Output: [1, 2, 3]

  // Get unique values
  final unique = uniq([2, 1, 2, 3, 1]);
  print(unique); // Output: [2, 1, 3]

  // Flatten arrays
  final flattened = flattenDeep([1, [2, [3, [4]], 5]]);
  print(flattened); // Output: [1, 2, 3, 4, 5]

  // Array operations
  final result = difference([2, 1], [[2, 3]]); // => [1]
  final sorted = sortedIndex([30, 50], 40);    // => 1
  final zipped = zip([['a', 'b'], [1, 2]]);    // => [['a', 1], ['b', 2]]
}

API References

  • List Module API - Complete documentation for all 70+ list functions
  • More modules coming soon...

Testing

Run tests with:

# Using fvm
fvm flutter test

# Or using dart directly
dart test

Contributing

Contributions are welcome! Please feel free to:

  1. Report bugs or suggest features by opening an issue
  2. Submit pull requests with improvements
  3. Improve documentation
  4. Add more utility functions

License

MIT License


Made with ❤️ for the Dart community

Libraries

safe_lodash
Support for doing something awesome.