dart_ext 1.0.0

  • README.md
  • CHANGELOG.md
  • Installing
  • Versions
  • 60

#dart_ext A set of useful helper functions

##Installing

###1. Depend on it Add this to your package's pubspec.yaml file:

  dependencies:
    dart_ext: any

###2. Install it

  run pub get in Dart Editor or form command line

###3. Import it Add this line in your dart code:

  import 'package:dart_ext/dart_ext.dart';

##API

###Object ####dynamic clone(dynamic source) return a clone of the specified object

###Function ####relaxFn(Function function) An funtion wrapper which support flexable number of arguments

####bind(Function functoin, List args) Partially apply a function by filling in 0 to 5 number of its arguments;

  • function - The function with partially filled args
  • args - A List of prefilled args.

Example:

    Function add = (num a, num b) { return a + b; };
    var add5 = new bind(add, [5]);
    num rt = add5(6);

####invokeMethod(var target, String methodName, [arg0, arg1, arg2, arg3, arg4, arg5]) Invoke the given method in the target object.

  • target - the object where the mehtod invoked from
  • 'methodName` - the function name
  • [arg0, arg1, arg2, arg3, arg4, arg5] - optional arguments. Suport 0 to 6 args. Exception: if the method didn't exist in the target object, it throws

###String ####String capitalize(String s) return a capitalized string

###Map ####dynamic getValue(Map source, dynamic key, [defaultValue = null]) return the value of given key in the map. If the key didn't exit, return given defaultValue or null if defaultValue didn't represent.

  • source - the map to get value from
  • key - the key of the value to get
  • defaultValue - the defaultValue to return if the key didn't exist in the map. defaultValue can be a function.

Example:

    Map m = {
      'one': 1,
      'two': 2
    }
    
    num two = getValue(m, 'two');       //  two = 2
    num zero = getValue(m, 'zero');     //  zero = null
    zero = getValue(m, 'zero', 0);      //  zero = 0
    num four = getValue(m, 'three', (){ return getValue(m, 'three', 3) + 1; });  // four = 4

####void setValue(Map source, dynamic key, dynamic value) Add key/value to the given map. Equivalent to source[key] = value. It is convenient to use in a setter which set a value in map.

  Map _config = {};
  
  void set name(String value) => setValue(_config, 'name', value);

####Map merge(Map map1, others, {Function iterableMergeFunc}) Merge maps into a new map.

  • others - can be a Map or a list<Map>
  • iterableMergeFunc - a custom merge function to override default iterable merge behavior
  import 'package:dart_ext/collection_ext.dart';  // only import collection extension
  
  Map one = {
    'a': 'a',
    'b': 'b',
    'list': [{ 'one': 1 }, { 'two': 2 }]
  }
  
  Map two = {
    'a': 'A'
    'b': 3,
    'list': [{ 'two': 2 }, { 'three': 3 }, 4 ]
  }
  
  Map three = {
    'a': 'A',
    'b': 4,
    'list': [{ 'three': 3 }, { 'four': 4}, 5, 6]
  }
  
  Map merged = merge(one, two);
  // merged is:
  {
    'a': 'A',
    'b': 3,
    'list': [{'one': 1, 'two': 2}, {'two': 2, 'three': 3}, 4]
  }
  
  merged = merge(one, [two, three]);
  // merged is:
  {
    'a': 'A',
    'b': 4,
    'list': [{'one': 1, 'two': 2, 'three': 3}, {'two': 2, 'three': 3, 'four': 4}, 5, 6]
  }
  
  merged = merge(one, two, (target, other) {
    list<num> toReturn = [];
    
    void _merge(List l) {
        target.forEach((t) {
            if (t is Map) {
                t.forEach((k, v) {
                    if (toReturn.contains(v) == false) {
                        toReturn.add(v);
                    }
                });
            } else if (toReturn.contains(v) == false) {
                toReturn.add(v);
            }
        });
    }
    
    _merge(target);
    _merge(orther);
    return toReturn;
  });
  // merged is:
  {
    'a': 'A',
    'b': 3,
    'list': [1, 2, 3, 4]
  }

#####Note:

  1. merge didn't check value type.
  2. if the value was a Iterable, it merge items at the same index.

#0.0.11

  • Remove mirror from function_ext.dart
  • Removed dart_ext.dart file

#0.0.10

  • Separate invoke method into function_ext_mirror_invoke.dart;

#0.0.9

  • fixed an issue where null value in map was treated not exist.

#v0.0.8

  • Suport merge unlimieted number of Map
  • Add ability to override default Iterable merge behavior

#v0.0.7

  • Add @MirrorUsed annotation

#v0.0.6

  • Changed partial to bind
  • Added getMethod and invokeMethod in function_ext.

#v0.0.5 Features:

  • Add relaxFn - a function with flexible arguments
  • Add partial - a fuction callback with partially filled arguments.

Use this package as a library

1. Depend on it

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


dependencies:
  dart_ext: ^1.0.0

2. Install it

You can install packages from the command line:

with pub:


$ pub get

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

3. Import it

Now in your Dart code, you can use:


import 'package:dart_ext/collection_ext.dart';
import 'package:dart_ext/function_ext.dart';
import 'package:dart_ext/function_ext_mirror_invoke.dart';
import 'package:dart_ext/string_ext.dart';
  
Version Uploaded Documentation Archive
1.0.0 Mar 2, 2018 Go to the documentation of dart_ext 1.0.0 Download dart_ext 1.0.0 archive
0.0.13 Mar 2, 2018 Go to the documentation of dart_ext 0.0.13 Download dart_ext 0.0.13 archive
0.0.12 Jun 2, 2015 Go to the documentation of dart_ext 0.0.12 Download dart_ext 0.0.12 archive
0.0.11 May 17, 2015 Go to the documentation of dart_ext 0.0.11 Download dart_ext 0.0.11 archive
0.0.10 May 12, 2015 Go to the documentation of dart_ext 0.0.10 Download dart_ext 0.0.10 archive
0.0.9 Mar 25, 2015 Go to the documentation of dart_ext 0.0.9 Download dart_ext 0.0.9 archive
0.0.8 Nov 21, 2014 Go to the documentation of dart_ext 0.0.8 Download dart_ext 0.0.8 archive
0.0.7 May 13, 2014 Go to the documentation of dart_ext 0.0.7 Download dart_ext 0.0.7 archive
0.0.6 May 12, 2014 Go to the documentation of dart_ext 0.0.6 Download dart_ext 0.0.6 archive
0.0.5 Apr 28, 2014 Go to the documentation of dart_ext 0.0.5 Download dart_ext 0.0.5 archive

All 14 versions...

Popularity:
Describes how popular the package is relative to other packages. [more]
26
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
60
Learn more about scoring.

We analyzed this package on Sep 18, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0
  • pana: 0.12.3

Platforms

Detected platforms: web, other

Platform components identified in package: mirrors.

Suggestions

Maintain an example.

Create a short demo in the example/ directory to show how to use this package. Common file name patterns include: main.dart, example.dart or you could also use dart_ext.dart.

Format lib/collection_ext.dart.

Run dartfmt to format lib/collection_ext.dart.

Fix lib/function_ext.dart.

Analysis of lib/function_ext.dart reported 1 hint:

line 34 col 7: Name types using UpperCamelCase.

Fix lib/function_ext_mirror_invoke.dart.

Analysis of lib/function_ext_mirror_invoke.dart reported 1 hint:

line 3 col 2: 'MirrorsUsed' is deprecated and shouldn't be used.

Format lib/string_ext.dart.

Run dartfmt to format lib/string_ext.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.24.0 <2.0.1
Dev dependencies
test ^0.12.0