dynamic transform(value, num start, [ num end = null ])

Source

dynamic transform(dynamic value, num start, [num end = null]) {
  if (!this.supports(value)) {
    throw new InvalidPipeArgumentException(SlicePipe, value);
  }
  if (value == null) return value;
  // This used to have JS behavior with TS-transpiled facades. To avoid a
  // breaking change, we inline the behavior here and will cleanup after all
  // facades are removed.
  int length = value.length as int;
  start = start < 0 ? math.max(0, length + start) : math.min(start, length);
  if (end != null) {
    end = end < 0 ? math.max(0, length + end) : math.min(end, length);
    if (end < start) return value is String ? '' : [];
  }
  if (value is String) {
    return value.substring(start, end);
  } else if (value is List) {
    return value.sublist(start, end);
  } else {
    return null;
  }
}