util library
Utility functions for Dart <> JS interoperability.
Classes
Properties
- globalThis → Object
-
no setter
- objectPrototype → Object?
-
Returns the
Object
prototype. Equivalent toObject.prototype
.no setter - util → Util
-
no setter
Functions
-
add<
T> (Object? first, Object? second) → T -
Perform JavaScript addition (
+
) on two values. -
allowInterop<
F extends Function> (F f) → F -
Returns a wrapper around function
f
that can be called from JavaScript usingpackage:js
JavaScript interop. -
allowInteropCaptureThis(
Function f) → Function -
Returns a wrapper around function
f
that can be called from JavaScript usingpackage:js
JavaScript interop, passing JavaScriptthis
as the first argument. -
and<
T> (Object? first, Object? second) → T -
Perform JavaScript logical and comparison (
&&
) of two expressions. -
callbackToCompleter<
T> (Completer< T> completer) → void Function(Object?, T) -
Returns a function that can be passed to a Node.js-style asynchronous
callback that will complete
completer
with that callback's error or success result. -
callConstructor<
T> (Object constr, List< Object?> ? arguments) → T -
callMethod<
T> (Object o, Object method, List< Object?> args) → T -
createDartExport<
T extends Object> (T dartObject) → Object -
Given a Dart object that is marked exportable, creates a JS object literal
that forwards to that Dart class. Look at the
@JSExport
annotation to determine what constitutes "exportable" for a Dart class. The object literal will be a map of export names (which are either the written instance member names or their rename) to their respective Dart instance members. -
createStaticInteropMock<
T extends Object, U extends Object> (U dartMock, [Object? proto = null]) → T -
Given a
@staticInterop
type T and an instancedartMock
of a Dart class U that implements the external extension members of T, creates a forwarding mock. -
dartify<
T> (dynamic jsObject) → T - Returns Dart representation from JS Object.
-
delete<
T> (Object o, Object property) → bool -
Perform JavaScript delete operator (
delete
) on the given property of the given object. -
divide<
T> (Object? first, Object? second) → T -
Perform JavaScript division (
/
) on two values. -
equal<
T> (Object? first, Object? second) → bool -
Perform JavaScript equality comparison (
==
) on two values. -
exponentiate<
T> (Object? first, Object? second) → T -
Perform JavaScript exponentiation (
**
) on two values. -
futureToPromise<
T> (Future< T> future) → Promise -
Creates JS
Promise
which is resolved whenfuture
completes. -
getProperty<
T> (Object o, Object name) → T -
greaterThan<
T> (Object? first, Object? second) → bool -
Perform JavaScript greater than comparison (
>
) of two values. -
greaterThanOrEqual<
T> (Object? first, Object? second) → bool -
Perform JavaScript greater than or equal comparison (
>=
) of two values. -
hasProperty(
Object o, Object name) → bool -
instanceof(
Object? o, Object type) → bool -
Check whether
o
is an instance oftype
. -
instanceOfString(
Object? element, String objectType) → bool - Like instanceof only takes a String for the object name instead of a constructor object.
-
invokeAsync0<
T> (void function(void (Object?, T))) → Future< T> -
Invokes a zero-argument Node.js-style asynchronous function and encapsulates
the result in a
Future
. -
invokeAsync1<
S, T> (void function(S, void (Object?, T)), S arg1) → Future< T> -
Invokes a single-argument Node.js-style asynchronous function and
encapsulates the result in a
Future
. -
isJavaScriptArray(
dynamic value) → bool -
Returns
true
if a given object is a JavaScript array. -
isJavaScriptSimpleObject(
dynamic value) → bool -
Returns
true
if a given object is a simple JavaScript object. -
isTruthy<
T> (Object? o) → bool - Determines if the given object is truthy or falsy.
-
jsify(
Object dartObject) → dynamic - Returns the JS representation from Dart Object.
-
lessThan<
T> (Object? first, Object? second) → bool -
Perform JavaScript less than comparison (
<
) of two values. -
lessThanOrEqual<
T> (Object? first, Object? second) → bool -
Perform JavaScript less than or equal comparison (
<=
) of two values. -
modulo<
T> (Object? first, Object? second) → T -
Perform JavaScript remainder (
%
) on two values. -
multiply<
T> (Object? first, Object? second) → T -
Perform JavaScript multiplication (
*
) on two values. -
newObject<
T> () → T -
not<
T> (Object? o) → T -
Perform JavaScript logical not (
!
) on the given object. -
notEqual<
T> (Object? first, Object? second) → bool -
Perform JavaScript inequality comparison (
!=
) on two values. -
objectGetPrototypeOf(
Object? object) → Object? -
Returns the prototype of a given object. Equivalent to
Object.getPrototypeOf
. -
objectKeys(
Object? object) → List< Object?> -
Returns the keys for a given object. Equivalent to
Object.keys(object)
. -
or<
T> (Object? first, Object? second) → T -
Perform JavaScript logical or comparison (
||
) of two expressions. -
promiseToFuture<
T> (Promise promise) → Future< T> -
Creates Dart
Future
which completes whenpromise
is resolved or rejected. -
setProperty<
T> (Object o, Object name, T? value) → T -
strictEqual<
T> (Object? first, Object? second) → bool -
Perform JavaScript strict equality comparison (
===
) on two values. -
strictNotEqual<
T> (Object? first, Object? second) → bool -
Perform JavaScript strict inequality comparison (
!==
) on two values. -
subtract<
T> (Object? first, Object? second) → T -
Perform JavaScript subtraction (
-
) on two values. -
typeofEquals<
T> (Object? o, String type) → bool -
Perform JavaScript
typeof
operator on the given object and determine if the result is equal to the given type. Exposes the wholetypeof
equal expression to maximize browser optimization. -
unsignedRightShift(
Object? leftOperand, Object? rightOperand) → num -
Perform JavaScript unsigned right shift operator (
>>>
) on the given left operand by the amount specified by the given right operand.
Exceptions / Errors
- NullRejectionException
-
Exception for when the promise is rejected with a
null
orundefined
value.