transform method

dynamic transform(
  1. dynamic value,
  2. int start, [
  3. int? end
])

Implementation

dynamic transform(dynamic value, int start, [int? end]) {
  if (value == null) return value;
  if (!supports(value)) {
    throw InvalidPipeArgumentException(SlicePipe, 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.
  var 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 ? '' : <Object>[];
  }
  if (value is String) {
    return value.substring(start, end);
  } else if (value is List<Object?>) {
    return value.sublist(start, end);
  } else {
    return null;
  }
}