when method

Object when({
  1. int isInt(
    1. int
    )?,
  2. double isDouble(
    1. double
    )?,
  3. bool isBool(
    1. bool
    )?,
  4. String isString(
    1. String
    )?,
  5. List isArray(
    1. JSArray<JSAny?>
    )?,
  6. Map isMap(
    1. JSAny
    )?,
  7. Object isOther(
    1. Object
    )?,
})

Implementation

Object when({
  int Function(int)? isInt,
  double Function(double)? isDouble,
  bool Function(bool)? isBool,
  String Function(String)? isString,
  List Function(JSArray)? isArray,
  Map Function(JSAny)? isMap,
  Object Function(Object)? isOther,
}) {
  if (isArray != null && isJavaScriptArray(this)) {
    return isArray(this as JSArray);
  }
  if (isInt != null && (this is num || instanceOfString(this, 'Number'))) {
    return isInt(this as int);
  }
  if (isDouble != null && (this is num || instanceOfString(this, 'Number'))) {
    return isDouble(this as double);
  }
  if (isBool != null && (this is bool || instanceOfString(this, 'Boolean'))) {
    return isBool(this as bool);
  }
  if (isString != null &&
      (this is String || instanceOfString(this, 'String'))) {
    return isString(this as String);
  }
  if (isMap != null && isJavaScriptSimpleObject(this)) {
    return isMap(this as JSAny);
  }
  if (isOther != null) {
    return isOther(this);
  }

  throw Exception('Unknown javascript object $this $runtimeType');
}