getTemplateForFormat(format, {
		nationalSignificantNumber,
		international,
		nationalPrefix,
		complexPrefixBeforeNationalSignificantNumber
	}) {
		let pattern = format.pattern()

		/* istanbul ignore else */
		if (SUPPORT_LEGACY_FORMATTING_PATTERNS) {
			pattern = pattern
				// Replace anything in the form of [..] with \d
				.replace(CREATE_CHARACTER_CLASS_PATTERN(), '\\d')
				// Replace any standalone digit (not the one in `{}`) with \d
				.replace(CREATE_STANDALONE_DIGIT_PATTERN(), '\\d')
		}

		// Generate a dummy national number (consisting of `9`s)
		// that fits this format's `pattern`.
		//
		// This match will always succeed,
		// because the "longest dummy phone number"
		// has enough length to accomodate any possible
		// national phone number format pattern.
		//
		let digits = LONGEST_DUMMY_PHONE_NUMBER.match(pattern)[0]

		// If the national number entered is too long
		// for any phone number format, then abort.
		if (nationalSignificantNumber.length > digits.length) {
			return
		}

		// Get a formatting template which can be used to efficiently format
		// a partial number where digits are added one by one.

		// Below `strictPattern` is used for the
		// regular expression (with `^` and `$`).
		// This wasn't originally in Google's `libphonenumber`
		// and I guess they don't really need it
		// because they're not using "templates" to format phone numbers
		// but I added `strictPattern` after encountering
		// South Korean phone number formatting bug.
		//
		// Non-strict regular expression bug demonstration:
		//
		// this.nationalSignificantNumber : `111111111` (9 digits)
		//
		// pattern : (\d{2})(\d{3,4})(\d{4})
		// format : `$1 $2 $3`
		// digits : `9999999999` (10 digits)
		//
		// '9999999999'.replace(new RegExp(/(\d{2})(\d{3,4})(\d{4})/g), '$1 $2 $3') = "99 9999 9999"
		//
		// template : xx xxxx xxxx
		//
		// But the correct template in this case is `xx xxx xxxx`.
		// The template was generated incorrectly because of the
		// `{3,4}` variability in the `pattern`.
		//
		// The fix is, if `this.nationalSignificantNumber` has already sufficient length
		// to satisfy the `pattern` completely then `this.nationalSignificantNumber`
		// is used instead of `digits`.

		const strictPattern = new RegExp('^' + pattern + '$')
		const nationalNumberDummyDigits = nationalSignificantNumber.replace(/\d/g, DUMMY_DIGIT)

		// If `this.nationalSignificantNumber` has already sufficient length
		// to satisfy the `pattern` completely then use it
		// instead of `digits`.
		if (strictPattern.test(nationalNumberDummyDigits)) {
			digits = nationalNumberDummyDigits
		}

		let numberFormat = this.getFormatFormat(format, international)
		let nationalPrefixIncludedInTemplate

		// If a user did input a national prefix (and that's guaranteed),
		// and if a `format` does have a national prefix formatting rule,
		// then see if that national prefix formatting rule
		// prepends exactly the same national prefix the user has input.
		// If that's the case, then use the `format` with the national prefix formatting rule.
		// Otherwise, use  the `format` without the national prefix formatting rule,
		// and prepend a national prefix manually to it.
		if (this.shouldTryNationalPrefixFormattingRule(format, { international, nationalPrefix })) {
			const numberFormatWithNationalPrefix = numberFormat.replace(
				FIRST_GROUP_PATTERN,
				format.nationalPrefixFormattingRule()
			)
			// If `national_prefix_formatting_rule` of a `format` simply prepends
			// national prefix at the start of a national (significant) number,
			// then such formatting can be used with `AsYouType` formatter.
			// There seems to be no `else` case: everywhere in metadata,
			// national prefix formatting rule is national prefix + $1,
			// or `($1)`, in which case such format isn't even considered
			// when the user has input a national prefix.
			/* istanbul ignore else */
			if (parseDigits(format.nationalPrefixFormattingRule()) === (nationalPrefix || '') + parseDigits('$1')) {
				numberFormat = numberFormatWithNationalPrefix
				nationalPrefixIncludedInTemplate = true
				// Replace all digits of the national prefix in the formatting template
				// with `DIGIT_PLACEHOLDER`s.
				if (nationalPrefix) {
					let i = nationalPrefix.length
					while (i > 0) {
						numberFormat = numberFormat.replace(/\d/, DIGIT_PLACEHOLDER)
						i--
					}
				}
			}
		}

		// Generate formatting template for this phone number format.
		let template = digits
			// Format the dummy phone number according to the format.
			.replace(new RegExp(pattern), numberFormat)
			// Replace each dummy digit with a DIGIT_PLACEHOLDER.
			.replace(new RegExp(DUMMY_DIGIT, 'g'), DIGIT_PLACEHOLDER)

		// If a prefix of a national (significant) number is not as simple
		// as just a basic national prefix, then just prepend such prefix
		// before the national (significant) number, optionally spacing
		// the two with a whitespace.
		if (!nationalPrefixIncludedInTemplate) {
			if (complexPrefixBeforeNationalSignificantNumber) {
				// Prepend the prefix to the template manually.
				template = repeat(DIGIT_PLACEHOLDER, complexPrefixBeforeNationalSignificantNumber.length) +
					' ' +
					template
			} else if (nationalPrefix) {
				// Prepend national prefix to the template manually.
				template = repeat(DIGIT_PLACEHOLDER, nationalPrefix.length) +
					this.getSeparatorAfterNationalPrefix(format) +
					template
			}
		}

		if (international) {
			template = applyInternationalSeparatorStyle(template)
		}

		return template
	}
Generates formatting template for a national phone number,
optionally containing a national prefix, for a format.
@param  {Format} format
@param  {string} nationalPrefix
@return {string}