bin/build-metadata.js
function processLibPhoneNumberMetadata( libPhoneNumberData ) {
	const data = {};
	for ( let countryCode in libPhoneNumberData ) {
		if ( libPhoneNumberData.hasOwnProperty( countryCode ) ) {
			const countryCodeUpper = countryCode.toUpperCase();
			const country = libPhoneNumberData[ countryCode ];
			data[ countryCodeUpper ] = {
				isoCode: countryCodeUpper,
				dialCode: String(
					country[ libPhoneNumberIndexes.COUNTRY_DIAL_CODE ] +
						( country[ libPhoneNumberIndexes.REGION_AREA_CODE ] || '' )
				),
				countryDialCode: String( country[ libPhoneNumberIndexes.COUNTRY_DIAL_CODE ] ),
				regionCode: country[ libPhoneNumberIndexes.REGION_AREA_CODE ] || '',
				areaCodes: areaCodes[ countryCode ],
				nationalPrefix: country[ libPhoneNumberIndexes.NATIONAL_PREFIX ],
				patterns: ( country[ libPhoneNumberIndexes.NUMBER_FORMAT ] || [] ).map(
					processNumberFormat
				),
				internationalPatterns: (
					country[ libPhoneNumberIndexes.INTERNATIONAL_NUMBER_FORMAT ] || []
				).map( processNumberFormat ),
				priority: priorityData[ countryCodeUpper ],
			};
		}
	}

	const noPattern = _.filter( data, _.conforms( { patterns: patterns => patterns.length === 0 } ) );
	_.forIn( noPattern, function( country ) {
		country.patternRegion = (
			_.maxBy( _.values( _.filter( data, { dialCode: country.dialCode } ) ), 'priority' ) || {}
		).isoCode;
		console.log(
			'Info: ' +
				country.isoCode +
				" didn't have a pattern" +
				( country.patternRegion ? ' so we use ' + country.patternRegion : '.' )
		);
	} );
	return data;
}
function processLibPhoneNumberMetadata( libPhoneNumberData ) {
	const data = {};
	for ( let countryCode in libPhoneNumberData ) {
		if ( libPhoneNumberData.hasOwnProperty( countryCode ) ) {
			const countryCodeUpper = countryCode.toUpperCase();
			const country = libPhoneNumberData[ countryCode ];
			data[ countryCodeUpper ] = {
				isoCode: countryCodeUpper,
				dialCode: String(
					country[ libPhoneNumberIndexes.COUNTRY_DIAL_CODE ] +
						( country[ libPhoneNumberIndexes.REGION_AREA_CODE ] || '' )
				),
				countryDialCode: String( country[ libPhoneNumberIndexes.COUNTRY_DIAL_CODE ] ),
				regionCode: country[ libPhoneNumberIndexes.REGION_AREA_CODE ] || '',
				areaCodes: areaCodes[ countryCode ],
				nationalPrefix: country[ libPhoneNumberIndexes.NATIONAL_PREFIX ],
				patterns: ( country[ libPhoneNumberIndexes.NUMBER_FORMAT ] || [] ).map(
					processNumberFormat
				),
				internationalPatterns: (
					country[ libPhoneNumberIndexes.INTERNATIONAL_NUMBER_FORMAT ] || []
				).map( processNumberFormat ),
				priority: priorityData[ countryCodeUpper ],
			};
		}
	}

	const noPattern = _.filter( data, _.conforms( { patterns: patterns => patterns.length === 0 } ) );
	_.forIn( noPattern, function( country ) {
		country.patternRegion = (
			_.maxBy( _.values( _.filter( data, { dialCode: country.dialCode } ) ), 'priority' ) || {}
		).isoCode;
		console.log(
			'Info: ' +
				country.isoCode +
				" didn't have a pattern" +
				( country.patternRegion ? ' so we use ' + country.patternRegion : '.' )
		);
	} );
	return data;
}
Processes Google's libphonenumber data and generates a proper JS object
@param {{}} libPhoneNumberData
@returns {{}}