flat 0.2.0

Dart native js
Flutter Android iOS web

A simple, no dependency 🚀 way to take a nested Map and flatten it into a single depth Map. Based on Node.js `flat` package.

flat #

Take a nested Map and flatten it with delimited keys. Entirely based on node.js flat.

It does not achieve feature parity yet, as some options are missing from flatten (maxDepth, transformKey) and unflatten is not yet implemented.

Currently, it bails out of a tree if it finds something different than a Map or List.

Usage #

import 'package:flat/flat.dart';

flatten({
  'key1': {'keyA': 'valueI'},
  'key2': {'keyB': 'valueII'},
  'key3': {
    'a': {
      'b': {'c': 2}
    }
  }
});

// {
//   'key1.keyA': 'valueI',
//   'key2.keyB': 'valueII',
//   'key3.a.b.c': 2
// };

Options #

delimiter #

Use a custom delimiter for flattening your objects, instead of .

safe #

When enabled, flat will preserve arrays and their contents. This is disabled by default.

import 'package:flat/flat.dart';

flatten({
  'this': [
    {'contains': 'arrays'},
    {
      'preserving': {'them': 'for you'}
    }
  ]
}, safe: true);

// {
//   'this': [
//     {'contains': 'arrays'},
//     {
//       'preserving': {'them': 'for you'}
//     }
//   ]
// };

maxDepth #

Maximum number of nested objects to flatten.

import 'package:flat/flat.dart';

flatten({
  'key1': {'keyA': 'valueI'},
  'key2': {'keyB': 'valueII'},
  'key3': {
    'a': {
      'b': {'c': 2}
    }
  }
}, maxDepth: 2);

// {
//   'key1.keyA': 'valueI',
//   'key2.keyB': 'valueII',
//   'key3.a': {
//     'b': {'c': 2}
//   }
// };
5
likes
110
pub points
76%
popularity

A simple, no dependency 🚀 way to take a nested Map and flatten it into a single depth Map. Based on Node.js `flat` package.

Repository (GitHub)
View/report issues

Documentation

API reference

Uploader

danilofuchs12345@gmail.com

License

MIT (LICENSE)

More

Packages that depend on flat