ms_map_utils 0.5.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 68

Overview Pub GitHub stars #

A simple lib to incremease Map with usefull functions

Whats MS_Map_Utils do #

Add usefull functions to map:

  • trim trim all Strings in a map it's recursive
  • compact remove all MapEntries thats values is null it's recursive too
  • reduce iterate all items in Map for reduce to a unique value returned from callback ReduceFunction.
  • removeKeys remove all entries that contains a key in list.
  • removeKeysExcept remove all entries that NOT contains a key in list.
  • putIfAbsentAsync put a item if absent or return existent value async.
  • containsKeys check if map contains all keys of list.

Usage #

Just import lib and use extensions, call the functions to starts work:

import 'package:ms_map_utils/ms_map_utils.dart';

Map itsAMap = {'key1':null,'key2':'         just a String withs extras spaces en start and end            '};
itsAMap.compact(); // Output: {'key2':'         just a String withs extras spaces en start and end            '}
itsAMap.trim(); // Output: {'key2':'just a String withs extras spaces en start and end'}

Map mapNumbers = {'key1':50,'key2':7,'key3':71,'key4':45,'key5':5};
// In reduceFunction you must check if `accumulated` is null and set a initial value for it
mapNumbers.reduce<int>((int accumulated, _, value) => (accumulated ?? 0) + (value as int)); // Output 178
mapNumbers.removeKeys(['key1','key5']); //{'key2':7,'key3':71,'key4':45}
mapNumbers.removeKeysExcept(['key3']); //{'key3':71}
var item = await anyMap.putIfAbsentAsync('randomKey', () async {
        await Future.delayed(Duration(milliseconds: 1500));
        return 'Random Value';
      });
if (mapNumbers.containsKeys(['key1','key2'])) {
  print('The map contians all keys [key1, key2]');
}

Changelog #

[0.5.0] - 04/16/2020 #

  • constainsKeys: is like containsKey but support a list of keys e diferente rules

[0.4.0] - 03/02/2020 #

  • putIfAbsentAsync: is like putIfAbsent but with async mode

[0.3.0] - 02/11/2020 #

  • RemoveKeys function implemented.
  • RemoveKeysExcept function implemented.

[0.2.0] - 02/06/2020 #

  • Reduce function implemented.

[0.1.0] - 01/13/2020 #

  • First Release.

example/main.dart

import 'package:ms_map_utils/ms_map_utils.dart';

Future<void> main(List<String> args) async {
  // Compat a Map
  print({'key1': null, 'key2': 'Non Null Value'}.compact());

  // Trim all strings values
  print({'key1': '    Imagine random string here   '}.trim());

  Map justMap = {
    'key1': null,
    'key2':
        '         just a String withs extras spaces en start and end            '
  };

  // Will remove key1
  // {key2:          just a String withs extras spaces en start and end            }
  print(justMap.compact());

  // Will trim value string
  // {key2: just a String withs extras spaces en start and end}
  print(justMap.trim());

  Map mapNumbers = {'key1': 50, 'key2': 7, 'key3': 71, 'key4': 45, 'key5': 5};
  // In reduceFunction you must check is acc is null and set a initial value for it
  var sumValues = mapNumbers.reduce<int>((int accumulated, _, value) =>
      (accumulated ?? 0) + (value as int)); // Output 178
  print(sumValues);
  mapNumbers.removeKeys(['key1', 'key5']);
  print(mapNumbers);
  mapNumbers.removeKeysExcept(['key3']);
  print(mapNumbers);

  var item = await justMap.putIfAbsentAsync('randomKey', () async {
    // do hard work here
    await Future.delayed(Duration(milliseconds: 1500));
    return 'Random String';
  });
  print(item);

  if (mapNumbers.containsKeys(['key1', 'key2'])) {
    print('The map contians all keys [key1, key2]');
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  ms_map_utils: ^0.5.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:ms_map_utils/ms_map_utils.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
36
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]
68
Learn more about scoring.

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

  • Dart: 2.8.4
  • pana: 0.13.14

Health suggestions

Fix lib/ms_map_utils.dart. (-0.50 points)

Analysis of lib/ms_map_utils.dart reported 1 hint:

line 48 col 27: Avoid shadowing type parameters.

Format lib/functions/compact.dart.

Run dartfmt to format lib/functions/compact.dart.

Format lib/functions/put_if_absent_async.dart.

Run dartfmt to format lib/functions/put_if_absent_async.dart.

Fix additional 3 files with analysis or formatting issues.

Additional issues in the following files:

  • lib/functions/reduce.dart (Run dartfmt to format lib/functions/reduce.dart.)
  • lib/functions/remove_keys.dart (Run dartfmt to format lib/functions/remove_keys.dart.)
  • lib/functions/trim.dart (Run dartfmt to format lib/functions/trim.dart.)

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.6.0 <3.0.0
Dev dependencies
test ^1.9.2