Skip to content

Commit

Permalink
Merge pull request #372 from kabrunko-dev/i18n-ptbr
Browse files Browse the repository at this point in the history
feat(i18n-ptBR): 🔥 add support for last name generation with locale
  • Loading branch information
NetanelBasal authored Dec 22, 2023
2 parents b65531d + 6e4c23a commit 37cdf01
Show file tree
Hide file tree
Showing 3 changed files with 268 additions and 3 deletions.
228 changes: 228 additions & 0 deletions packages/falso/src/lib/i18n/pt-br/last-name.i18n.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
}
7 changes: 5 additions & 2 deletions packages/falso/src/lib/last-name.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -25,7 +25,10 @@ export function randLastName<Options extends NameOptions = never>(
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);
}
36 changes: 35 additions & 1 deletion packages/falso/src/tests/last-name.spec.ts
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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);
});
});
});

0 comments on commit 37cdf01

Please sign in to comment.