object_modifier 1.0.0 copy "object_modifier: ^1.0.0" to clipboard
object_modifier: ^1.0.0 copied to clipboard

A lightweight Dart library for merging, normalizing, and handling complex JSON structures effortlessly.

example/lib/main.dart

import 'package:object_modifier/object_modifier.dart';

void main() {
  // Example 1: Merge two simple maps
  final a = {'name': 'Alice', 'age': 25};
  final b = {'age': 24, 'city': 'Paris'};

  final mergedMap = ObjectModifier.mergeMap(a, b);
  print('Merged Map: $mergedMap');
  // Output: {name: Alice, age: 25, city: Paris}

  // Example 2: Merge list of maps with automatic ID detection
  final listA = [
    {'id': 1, 'name': 'Alice'},
    {'id': 2, 'name': 'Bob'},
  ];
  final listB = [
    {'id': 1, 'age': 25},
    {'id': 3, 'name': 'Charlie'},
  ];

  final mergedList = ObjectModifier.mergeList(listA, listB);
  print('Merged List: $mergedList');
  // Output (order may vary):
  // [
  //   {id: 1, name: Alice, age: 25},
  //   {id: 2, name: Bob},
  //   {id: 3, name: Charlie}
  // ]

  // Example 3: Use custom normalizer for non-encodable objects
  final x = {'created': DateTime(2025, 1, 1)};
  final y = {'created': 'old'};

  final normalized = ObjectModifier.mergeMap(x, y, (a, b) {
    if (a is DateTime) return a.toIso8601String();
    return a ?? b;
  });

  print('Normalized: $normalized');
  // Output: {created: 2025-01-01T00:00:00.000}
}
1
likes
150
points
16
downloads

Publisher

unverified uploader

Weekly Downloads

A lightweight Dart library for merging, normalizing, and handling complex JSON structures effortlessly.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter

More

Packages that depend on object_modifier