map_enhancer 1.0.0

  • Readme
  • Changelog
  • Example
  • Installing
  • new50

map_enhancer #

A plugin which extends Dart's native Map type with a couple of handy methods.

Getting Started #

Import the plugin by:

import 'package:map_enhancer/map_enhancer.dart`;

Usage #

Let's start with a simple Map:

final Map peter = {
  'name': {
    'firstName': 'Peter',
    'lastName': 'Petrelli',
  },
  'age': 29,
};

Get a nested value: #

print(
  peter.getIn(['name', 'firstName']),
);
// Output: Peter

// or if you prefer the JSON "dot notation":
print(
  peter.getIn('name.firstName'.split('.')),
);
// Output: Peter

// call with default value:
print(
  peter.getIn(
    'name.nickName'.split('.'),
    defaultValue: 'Pete',
  ),
);
// Output: Pete

Set a nested value: #

peter.setIn(['ability'], 'Empathic mimicry');
print(peter['ability']);
// Output: Empathic mimicry

Remove a nested key: #

peter.unsetIn(['name', 'lastName']);
print(peter['name']['lastName']);
// Output: null

Check if a nested key is present: #

print(peter.hasIn(['name', 'nickname']));
// Output: false

[1.0.0] - 2020-4-27 #

  • Renamed methods.
  • Added Map.hasIn() method.

[0.1.0] - 2020-4-25 #

  • Added Map.get(), Map.set(), and Map.unset() methods.

example/main.dart

import 'package:map_enhancer/map_enhancer.dart';

void main() {
  final Map peter = {
    'name': {
      'firstName': 'Peter',
      'lastName': 'Petrelli',
    },
    'age': 29,
  };

  print(
    peter.getIn(['name', 'firstName']),
  );
  // Output: Peter

  // or if you prefer the JSON "dot notation":
  print(
    peter.getIn('name.firstName'.split('.')),
  );
  // Output: Peter

  // call with default value:
  print(
    peter.getIn(
      'name.nickName'.split('.'),
      defaultValue: 'Pete',
    ),
  );
  // Output: Pete

  peter.setIn(['ability'], 'Empathic mimicry');
  print(peter['ability']);
  // Output: Empathic mimicry

  peter.unsetIn(['name', 'lastName']);
  print(peter['name']['lastName']);
  // Output: null

  print(peter.hasIn(['name', 'nickname']));
  // Output: false
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  map_enhancer: ^1.0.0

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:map_enhancer/map_enhancer.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
0
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
50
Learn more about scoring.

We analyzed this package on May 13, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.1
  • pana: 0.13.8-dev

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.7.0 <3.0.0
Dev dependencies
flutter_test