formatNsn static method

String formatNsn(
  1. PhoneNumber phoneNumber
)

format national number for international use

Implementation

static String formatNsn(PhoneNumber phoneNumber) {
  if (phoneNumber.nsn.isEmpty) {
    return phoneNumber.nsn;
  }
  final missingDigits = _getMissingDigits(phoneNumber);
  final completePhoneNumber = phoneNumber.nsn + missingDigits;
  final formatingRules =
      MetadataFinder.getMetadataFormatsForIsoCode(phoneNumber.isoCode);
  final formatingRule = _getMatchingFormatRules(
    formatingRules: formatingRules,
    nsn: completePhoneNumber,
  );
  // for incomplete phone number

  if (formatingRule == null) {
    return phoneNumber.nsn;
  }
  var transformRule = formatingRule.format;
  // if there is an international format, we use it
  final intlFormat = formatingRule.intlFormat;
  if (intlFormat != null && intlFormat != 'NA') {
    transformRule = intlFormat;
  }

  var formatted = RegexpManager.applyTransformRules(
    appliedTo: completePhoneNumber,
    pattern: formatingRule.pattern,
    transformRule: transformRule,
  );
  formatted = _removeMissingDigits(formatted, missingDigits);
  return formatted;
}