This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* PhoneNumberFormatter.swift | |
* | |
* Created by Diney Bomfim on 12/12/22. | |
* | |
* Swift code that automatically loads the global phone format list, parses it and formats a given input. | |
* For everyone that believes Phone Number Formatting should be open source, global standard and easy to use. | |
* This is based on Google Project https://github.com/google/libphonenumber. Updated constantly by Google engineers. | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{"phoneNumberMetadata": {"territories": {"territory": [{"id": "AC","countryCode": "247","internationalPrefix": "00","generalDesc": {"nationalNumberPattern": "(?:[01589]\\d|[46])\\d{4}"},"fixedLine": {"possibleLengths": {"national": "5"},"exampleNumber": "62889","nationalNumberPattern": "6[2-467]\\d{3}"},"mobile": {"possibleLengths": {"national": "5"},"exampleNumber": "40123","nationalNumberPattern": "4\\d{4}"},"uan": {"possibleLengths": {"national": "6"},"exampleNumber": "542011","nationalNumberPattern": "(?:0[1-9]|[1589]\\d)\\d{4}"}},{"id": "AD","countryCode": "376","internationalPrefix": "00","availableFormats": {"numberFormat": [{"pattern": "(\\d{3})(\\d{3})","leadingDigits": "[135-9]","format": "$1 $2"},{"pattern": "(\\d{4})(\\d{4})","leadingDigits": "1","format": "$1 $2"},{"pattern": "(\\d{3})(\\d{3})(\\d{3})","leadingDigits": "6","format": "$1 $2 $3"}]},"generalDesc": {"nationalNumberPattern": "(?:1|6\\d)\\d{7}|[135-9]\\d{5}"},"noInternationalDialling": {"possibleLengths": {"national": "8"},"nationalNum |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public extension Locale { | |
private static var availableRegions: [Locale] = { Locale.availableIdentifiers.map { Locale(identifier: $0) } }() | |
init?(isoCode: String, from: Locale = .autoupdatingCurrent) { | |
guard let locale = from.locale(isoCode: isoCode) else { return nil } | |
self = locale | |
} | |
func alpha2Code(from isoCode: String) -> String? { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Full Swift Codable object compatible with dynamic JSON structures. Able to encode and decode any kind of JSON. | |
// | |
// How to use it? | |
// | |
// Try it out on your playground at the end of the file: | |
public struct AnyCodable { | |
// MARK: - Properties | |