diff --git a/country.go b/country.go index bb46979..c1df367 100644 --- a/country.go +++ b/country.go @@ -182,6 +182,13 @@ func (c *Country) FormatAddress(recipient, street, postalCode, city, region stri return a } +// GDPRCompliant returns true if the country is GDPR (General Data Protection +// Regulation) compliant. A country is GDPR compliant if is a member of the +// European Economic Area or it is UK. +func (c *Country) GDPRCompliant() bool { + return c.EEAMember || c.Alpha2 == "GB" +} + var flagsCodePoints = map[rune]rune{ 'a': '🇦', 'b': '🇧', diff --git a/country_test.go b/country_test.go index 942555e..e9a8af7 100644 --- a/country_test.go +++ b/country_test.go @@ -400,6 +400,23 @@ func ExampleCountry_FormatAddress() { // United States of America } +func ExampleCountry_GDPRCompliant() { + c := countries.Get("IT") + fmt.Println(c.GDPRCompliant()) + // Output: true +} + +func TestGDPRCompliant(t *testing.T) { + c := countries.Get("IT") + assert.True(t, c.GDPRCompliant()) + + c = countries.Get("GB") + assert.True(t, c.GDPRCompliant()) + + c = countries.Get("US") + assert.False(t, c.GDPRCompliant()) +} + func ExampleCountry_EmojiFlag() { c := countries.Get("US") fmt.Println(c.EmojiFlag())