js_mimicry 1.0.0

  • README.md
  • Installing
  • Versions
  • 44


Allows the use of Dart classes and objects in javascript. Generates a special proxy classes.

Create javascript API for Dart become easier.


  • Class inheritance ( with @JsProxy )
  • Named constructors
  • Method
  • Optional positional parameters
  • Optional named parameters
  • Input parameter transform
  • Result mutation
  • Future (via result mutator)
  • Field
  • Getter/Setter

Not support:

  • Factory
  • Operator

Try It Now

Add the js_mimicry package to your pubspec.yaml file:

  js_mimicry: ">=0.2.0 <0.3.0"

Building and Deploying

To build a deployable version of your app, add the js_mimicry transformers to your pubspec.yaml file:

- js_mimicry


##Dart code

    class Test1{
      method1(p1,[p2]){/* code */}
      method2(p1,p2){/* code */}
    class Test2 extends Test1{
      int method2(p1,p2){/* new logic */}
      String method3(Test1 obj){/* code */}
      Future<int> method4(){/* code */}
      Test1 method5({namedP1, namedP2}){/* code */}
      String method6(int value){/* code */}

##Add annotation for class

    class Test1{  // ... cut ...

    class Test2 extends Test1{ // ... cut ...

##Add annotation for transform input parameter

    String method6(@JsTransform(ANY_TO_INT) int value){/* code */}

    static int ANY_TO_INT(Object v){
        if (v is String){
         return int.parse(v);
        return v as int;

##Add annotation for mutation result Future

    @JsMutator(insertParams:const ["resultCb","errorCb"],result:Test2.futureToCallbacks)
    Future<int> method4(){/* code */}
    static futureToCallbacks(Future result,js.JsFunction resultCb,[js.JsFunction errorCb]){
        if (errorCb!=null){
            result = result.catchError((err)=>errorCb.apply([err]));
        return result;

##Add annotation for mutation result

    Test1 method5(){/* code */}

    static ANY_TO_STRING(v)=>v.toString();

Import to javascript

    import 'dart:js' as js;
    import 'package:js_mimicry/annotation.dart';
      // Create instance Test1
      js.context["dartInstanceTest1"] = JsProxyFactory.toJs(new Test1());

Uses in javascript

    // Create Test2 instance, call method5 with named parameters
    new Test2().method5({namedP1:"123"});
    // call Test1.method1 with optional parameters

JsProxyFactory methods

###JsObject toJs(DartClass obj) Create proxy object for Test2 object. ###DartClass toDart(Type dartType, JsObject obj) Convert javascript proxy to real Dart object.



  • upgrade code_transformers: ^0.5.0


  • disable js_mimicry transformer


  • useSharedSources mode enabled in the resolver
  • fix analyzer: '>=0.23.0 <0.26.1+15'


  • reduced memory consumption


  • upgrade analyzer: '>=0.23.0 <0.27.0'


  • Fix: JsTransform for optional and named param


  • Support JsIgnore


  • Support abstract class


  • Added tests
  • Fix: source shift
  • Fix: skip not jsProxy parent


  • Initial transformer release.

Use this package as a library

1. Depend on it

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

  js_mimicry: ^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:js_mimicry/annotation.dart';
import 'package:js_mimicry/generator.dart';
import 'package:js_mimicry/instance_transformer.dart';
import 'package:js_mimicry/resolver_transformer.dart';
import 'package:js_mimicry/transformer.dart';
Version Uploaded Documentation Archive
1.0.0 Mar 31, 2017 Go to the documentation of js_mimicry 1.0.0 Download js_mimicry 1.0.0 archive
0.2.2 Apr 1, 2016 Go to the documentation of js_mimicry 0.2.2 Download js_mimicry 0.2.2 archive
0.2.1+4 Nov 30, 2015 Go to the documentation of js_mimicry 0.2.1+4 Download js_mimicry 0.2.1+4 archive
0.2.1+3 Nov 27, 2015 Go to the documentation of js_mimicry 0.2.1+3 Download js_mimicry 0.2.1+3 archive
0.2.1+2 Nov 23, 2015 Go to the documentation of js_mimicry 0.2.1+2 Download js_mimicry 0.2.1+2 archive
0.2.1+1 Jun 29, 2015 Go to the documentation of js_mimicry 0.2.1+1 Download js_mimicry 0.2.1+1 archive
0.2.1 Jun 25, 2015 Go to the documentation of js_mimicry 0.2.1 Download js_mimicry 0.2.1 archive
0.2.0+4 Jun 21, 2015 Go to the documentation of js_mimicry 0.2.0+4 Download js_mimicry 0.2.0+4 archive
0.2.0+3 Jun 21, 2015 Go to the documentation of js_mimicry 0.2.0+3 Download js_mimicry 0.2.0+3 archive
0.2.0+2 Jun 16, 2015 Go to the documentation of js_mimicry 0.2.0+2 Download js_mimicry 0.2.0+2 archive

All 17 versions...

Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

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

  • Dart: 2.0.0
  • pana: 0.11.8


Detected platforms: unsure

Error(s) prevent platform classification:

Fix dependencies in pubspec.yaml.

Issues and suggestions

Fix dependencies in pubspec.yaml.

Running pub upgrade failed with the following output:

ERR: The current Dart SDK version is 2.0.0.
 Because js_mimicry depends on code_transformers >=0.0.1-dev.1 which requires SDK version >=1.0.0 <2.0.0, version solving failed.

Fix platform conflicts.

Error(s) prevent platform classification:

Fix dependencies in pubspec.yaml.

Running dartdoc failed.

Make sure dartdoc runs without any issues.

Package is getting outdated.

The package was released 72 weeks ago.

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 js_mimicry.dart.

Format lib/annotation.dart.

Run dartfmt to format lib/annotation.dart.

Format lib/generator.dart.

Run dartfmt to format lib/generator.dart.

Fix additional 19 files with analysis or formatting issues.

Additional issues in the following files:

  • lib/instance_transformer.dart (Run dartfmt to format lib/instance_transformer.dart.)
  • lib/resolver_transformer.dart (Run dartfmt to format lib/resolver_transformer.dart.)
  • lib/src/dart_class_info.dart (Run dartfmt to format lib/src/dart_class_info.dart.)
  • lib/src/dart_class_visitor.dart (Run dartfmt to format lib/src/dart_class_visitor.dart.)
  • lib/src/dart_method_info.dart (Run dartfmt to format lib/src/dart_method_info.dart.)
  • lib/src/dart_method_mutator.dart (Run dartfmt to format lib/src/dart_method_mutator.dart.)
  • lib/src/dart_property_info.dart (Run dartfmt to format lib/src/dart_property_info.dart.)
  • lib/src/generator_js_mimicry.dart (Run dartfmt to format lib/src/generator_js_mimicry.dart.)
  • lib/src/metadata.dart (Run dartfmt to format lib/src/metadata.dart.)
  • lib/test/test1.dart (Run dartfmt to format lib/test/test1.dart.)
  • lib/test/test11.dart (Run dartfmt to format lib/test/test11.dart.)
  • lib/test/test2.dart (Run dartfmt to format lib/test/test2.dart.)
  • lib/test/test22.dart (Run dartfmt to format lib/test/test22.dart.)
  • lib/test/test3.dart (Run dartfmt to format lib/test/test3.dart.)
  • lib/test/test4.dart (Run dartfmt to format lib/test/test4.dart.)
  • lib/test/test5.dart (Run dartfmt to format lib/test/test5.dart.)
  • lib/test/test_lib1.dart (Run dartfmt to format lib/test/test_lib1.dart.)
  • lib/test/test_mimicry1.dart (Run dartfmt to format lib/test/test_mimicry1.dart.)
  • lib/transformer.dart (Run dartfmt to format lib/transformer.dart.)


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.14.0