From 6e4c23a8df90d7c59772769782f84234c0c4ad41 Mon Sep 17 00:00:00 2001 From: kabrunko-dev Date: Thu, 21 Dec 2023 16:04:27 -0300 Subject: [PATCH] =?UTF-8?q?feat(i18n-ptBR):=20=F0=9F=94=A5=20add=20support?= =?UTF-8?q?=20for=20last=20name=20generation=20with=20locale?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/lib/i18n/pt-br/last-name.i18n.json | 228 ++++++++++++++++++ packages/falso/src/lib/last-name.ts | 7 +- packages/falso/src/tests/last-name.spec.ts | 36 ++- 3 files changed, 268 insertions(+), 3 deletions(-) create mode 100644 packages/falso/src/lib/i18n/pt-br/last-name.i18n.json diff --git a/packages/falso/src/lib/i18n/pt-br/last-name.i18n.json b/packages/falso/src/lib/i18n/pt-br/last-name.i18n.json new file mode 100644 index 000000000..6a6e0d73b --- /dev/null +++ b/packages/falso/src/lib/i18n/pt-br/last-name.i18n.json @@ -0,0 +1,228 @@ +{ + "data": { + "withAccents": [ + "Apolinário", + "Aragão", + "Araújo", + "Assunção", + "Ávila", + "Belém", + "Conceição", + "Custódio", + "Córdoba", + "Cortês", + "Damásio", + "da Conceição", + "Dinís", + "D'Ávila", + "Guimarães", + "Góis", + "Hilário", + "Hipólito", + "Jordão", + "Magalhães", + "Nóbrega" + ], + "withoutAccents": [ + "Agostinho", + "Aguiar", + "Albuquerque", + "Albuquerque", + "Alegria", + "Alencastro", + "Almada", + "Almeida", + "Alves", + "Alves", + "Alvim", + "Amorim", + "Andrade", + "Antunes", + "Arruda", + "Assis", + "Baptista", + "Barbosa", + "Barreto", + "Barros", + "Barros", + "Barros", + "Batista", + "Beira-Mar", + "Belchior", + "Bernardes", + "Bittencourt", + "Boaventura", + "Bonfim", + "Botelho", + "Braga", + "Brites", + "Brito", + "Caetano", + "Caldeira", + "Camacho", + "Camilo", + "Campos", + "Capelo", + "Cardoso", + "Carvalho", + "Castro", + "Castro", + "Cavalcante", + "Cavalcanti", + "Chaves", + "Corte Real", + "Costa", + "Costa", + "Coutinho", + "Crespo", + "Cunha", + "Curado", + "Dantas", + "da Costa", + "da Cruz", + "da Cunha", + "da Luz", + "da Mata", + "da Mota", + "da Paz", + "da Rocha", + "da Rosa", + "das Neves", + "Dias", + "Dias", + "Domingues", + "dos Reis", + "Drummond", + "Duarte", + "Escobar", + "Espinosa", + "Esteves", + "Evangelista", + "Farias", + "Fernandes", + "Ferrari", + "Ferreira", + "Figueiredo", + "Figueiroa", + "Flores", + "Fogaça", + "Franco", + "Freitas", + "Furtado", + "Garcia", + "Gaspar", + "Gentil", + "Geraldes", + "Gil", + "Godinho", + "Gomes", + "Gonzaga", + "Gonçalves", + "Goulart", + "Gouveia", + "Guedes", + "Hernandes", + "Ilha", + "Infante", + "Jaques", + "Jesus", + "Lacerda", + "Lessa", + "Lima", + "Lopes", + "Macedo", + "Machado", + "Maciel", + "Maia", + "Maldonado", + "Marinho", + "Marques", + "Martins", + "Medeiros", + "Meireles", + "Mello", + "Melo", + "Mendes", + "Menezes", + "Mesquita", + "Modesto", + "Monteiro", + "Moraes", + "Morais", + "Moreira", + "Morgado", + "Moura", + "Muniz", + "Nascimento", + "Neves", + "Nogueira", + "Novaes", + "Novais", + "Nunes", + "Oliveira", + "Ourique", + "Pacheco", + "Padilha", + "Paiva", + "Paris", + "Peixoto", + "Peralta", + "Pereira", + "Peres", + "Pilar", + "Pimenta", + "Pinheiro", + "Pinto", + "Pires", + "Portela", + "Porto", + "Quaresma", + "Quarteira", + "Queiroz", + "Ramires", + "Ramos", + "Rebelo", + "Reis", + "Resende", + "Rezende", + "Ribeiro", + "Rocha", + "Rodrigues", + "Salazar", + "Sales", + "Salgado", + "Salgueiro", + "Sampaio", + "Sanches", + "Santana", + "Santos", + "Saraiva", + "Silva", + "Silveira", + "Siqueira", + "Soares", + "Souza", + "Subtil", + "Tavares", + "Taveira", + "Teixeira", + "Teles", + "Torres", + "Trindade", + "Varela", + "Vargas", + "Vasconcelos", + "Vasques", + "Veiga", + "Veloso", + "Viana", + "Vidal", + "Vieira", + "Vilela", + "Xavier", + "Ximenes", + "Zaganelli", + "Zanette" + ] + } +} diff --git a/packages/falso/src/lib/last-name.ts b/packages/falso/src/lib/last-name.ts index 0ff755d50..581cf2cac 100644 --- a/packages/falso/src/lib/last-name.ts +++ b/packages/falso/src/lib/last-name.ts @@ -1,7 +1,7 @@ import { fake } from './core/core'; -import { data } from './last-name.json'; import { randBoolean } from './boolean'; import { NameOptions } from './full-name'; +import { data } from './last-name.json'; /** * Generate a random last name. @@ -25,7 +25,10 @@ export function randLastName( options?: Options ) { const withAccents = options?.withAccents ?? randBoolean(); - const names = withAccents ? data['withAccents'] : data['withoutAccents']; + const locale = options?.locale || data; + const names: string[] = withAccents + ? locale['withAccents'] + : locale['withoutAccents']; return fake(names, options); } diff --git a/packages/falso/src/tests/last-name.spec.ts b/packages/falso/src/tests/last-name.spec.ts index 2a506c633..4abcb07d9 100644 --- a/packages/falso/src/tests/last-name.spec.ts +++ b/packages/falso/src/tests/last-name.spec.ts @@ -1,7 +1,10 @@ import { randLastName } from '../lib/last-name'; -import { data } from '../lib/last-name.json'; +import { NameOptions } from '../lib/full-name'; import * as randBooleanFunctions from '../lib/boolean'; +import { data } from '../lib/last-name.json'; +import { data as locale_ptBR } from '../lib/i18n/pt-br/last-name.i18n.json'; + describe('lastName', () => { let specialCharRegex: RegExp; @@ -108,4 +111,35 @@ describe('lastName', () => { }); }); }); + + describe('with provided locale PT-BR data', () => { + const data = locale_ptBR; + let options: NameOptions; + + beforeEach(() => { + options = { + locale: data, + }; + }); + + it('should return a lastName with at least 1 accented character', () => { + const result = randLastName({ + ...options, + withAccents: true, + }); + + expect(result.match(specialCharRegex)).toBeTruthy(); + expect(data.withAccents.includes(result)).toBe(true); + }); + + it('should return a lastName with only non-accented characters', () => { + const result = randLastName({ + ...options, + withAccents: false, + }); + + expect(result.match(specialCharRegex)).toBeFalsy(); + expect(data.withoutAccents.includes(result)).toBe(true); + }); + }); });