flat 0.4.0 copy "flat: ^0.4.0" to clipboard
flat: ^0.4.0 copied to clipboard

outdated

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}
//   }
// };
12
likes
0
pub points
85%
popularity

Publisher

unverified uploader

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

License

unknown (LICENSE)

More

Packages that depend on flat