# isISBN method

bool isISBN([

1. Object? version

])

Check if the string is an ISBN (version 10 or 13)

## Implementation

    bool isISBN([Object? version]) {
      var str = this;

      if (version == null) {
        return str.isISBN('10') || str.isISBN('13');
      }

      version = version.toString();

      String sanitized = str.replaceAll(RegExp(r'[\s-]+'), '');
      int checksum = 0;

      if (version == '10') {
        if (!RegexUtils.isbn10.hasMatch(sanitized)) {
          return false;
        }
        for (int i = 0; i < 9; i++) {
          checksum += (i + 1) * int.parse(sanitized[i]);
        }
        if (sanitized[9] == 'X') {
          checksum += 10 * 10;
        } else {
          checksum += 10 * int.parse(sanitized[9]);
        }
        return (checksum % 11 == 0);
      } else if (version == '13') {
        if (!RegexUtils.isbn13.hasMatch(sanitized)) {
          return false;
        }
        var factor = [1, 3];
        for (int i = 0; i < 12; i++) {
          checksum += factor[i % 2] * int.parse(sanitized[i]);
        }
        return (int.parse(sanitized[12]) - ((10 - (checksum % 10)) % 10) == 0);
      }

      return false;
    }