js_util 0.2.0

  • README.md
  • Example
  • Installing
  • Versions
  • 41


Build Status

Utilities to access JavaScript from Dart.

  • toJS(o): Converts a Dart object to a JavaScript object.
  • newObject(): Creates a new JavaScript object.
  • defineProperty(o, String prop, PropertyDescription desc): A wrapper for Object.defineProperty
  • getValue(o, String prop): Returns o[prop].
  • setValue(o, String prop, value): Performs o[prop] = value.

These utilities are of great help if a JavaScript API takes a JavaScript object with keys that are not fixed because js package does not let you create a JavaScript object without declaring a Dart class with @JS() and @anonymous.

Getting Started

Include js_util.js in index.html to use js_util functions.

    <script async src="packages/js_util/dist/js_util.js"></script>
    <script async src="packages/browser/dart.js"></script>


A simple usage example:

final obj = newObject();
defineProperty(obj, 'foo', new PropertyDescription(enumerable: true, value: 1));
defineProperty(obj, 'bar', new PropertyDescription(enumerable: false, value: 2));
final obj = newObject();
setValue(obj, 'foo', 1);
setValue(obj, 'bar', 2);

print(getValue(obj, 'foo')); // 1
print(getValue(obj, 'bar')); // 2
final jsObj = toJS({
  'people': [
    {'firstName': 'Kwang Yul', 'lastName': 'Seo'},
    {'firstName': 'DoHyung', 'lastName': 'Kim'},
    {'firstName': 'Kyusun', 'lastName': 'Kim'}

final people = getValue(jsObj, 'people');
print(getValue(people[0], 'firstName')); // 'Kwang Yul'

Features and bugs

Please file feature requests and bugs at the issue tracker.



  • Add @JS annotations on library directives to support 1.16.0
  • Add the minified version of js_util.js


  • Initial version


import 'dart:html';

import 'package:js_util/js_util.dart';

void main() {
  final jsObj = toJS({
    'people': [
      {'firstName': 'Kwang Yul', 'lastName': 'Seo'},
      {'firstName': 'DoHyung', 'lastName': 'Kim'},
      {'firstName': 'Kyusun', 'lastName': 'Kim'}

  final people = getValue(jsObj, 'people');
  final firstPerson = people[0];
  final text =
      '${getValue(firstPerson, "firstName")} ${getValue(firstPerson, "lastName")}';
  document.querySelector('#container').innerHtml = text;

1. Depend on it

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

  js_util: "^0.2.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_util/js_util.dart';
Version Uploaded Documentation Archive
0.2.0 May 2, 2016 Go to the documentation of js_util 0.2.0 Download js_util 0.2.0 archive
0.1.0 Mar 30, 2016 Go to the documentation of js_util 0.1.0 Download js_util 0.1.0 archive


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

  • Dart: 2.0.0-dev.49.0
  • pana: 0.10.6


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


Detected platforms: web, other

Primary library: package:js_util/js_util.dart with components: js.


  • The description is too short.

    Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.

  • Package is pre-v1 release.

    While there is nothing inherently wrong with versions of 0.*.*, it usually means that the author is still experimenting with the general direction API.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.8.0 <2.0.0
js >=0.6.0 <0.7.0 0.6.1
quiver_iterables >=1.0.0 <2.0.0 1.0.1
Transitive dependencies
meta 1.1.2
Dev dependencies
browser >=0.10.0 <0.11.0
test >=0.12.0 <0.13.0