cropEndOptional function

Object? cropEndOptional(
  1. Parser parser,
  2. Object data,
  3. bool debug
)

Implementation

Object? cropEndOptional(Parser parser, Object data, bool debug) {
  int? cropEnd = parser.optional!.cropEnd;
  try {
    Object tmp = data;
    if (cropEnd != null) {
      if (tmp is List) {
        if (cropEnd <= tmp.length) {
          tmp.removeRange(tmp.length - cropEnd, tmp.length);
          return tmp;
        }
      } else if (tmp is String) {
        if (tmp.length >= cropEnd && cropEnd > 0) {
          return tmp.substring(0, tmp.length - cropEnd).trim();
        }
      }
    }
  } catch (e) {
    printLog(
      "Error in function cropEndOptional: $e",
      debug,
      color: LogColor.red,
    );
  }
  return null;
}