Skip to content

Commit c042294

Browse files
committed
chore: wip
1 parent 882c1bd commit c042294

File tree

24 files changed

+2501
-93
lines changed

24 files changed

+2501
-93
lines changed

bin/nanofaker

56.8 MB
Binary file not shown.

build.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ import { dts } from 'bun-plugin-dtsx'
33
await Bun.build({
44
entrypoints: ['src/index.ts'],
55
outdir: './dist',
6+
target: 'bun',
67
plugins: [dts()],
78
})

src/config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import type { FakerConfig } from './types'
22
import { loadConfig } from 'bunfig'
33

44
export const defaultConfig: FakerConfig = {
5-
verbose: true,
5+
verbose: false,
6+
locale: 'en',
67
}
78

89
// eslint-disable-next-line antfu/no-top-level-await

src/faker.ts

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
import type { FakerOptions, LocaleDefinition } from './types'
2+
import { Random } from './random'
3+
import { PersonModule } from './modules/person'
4+
import { AddressModule } from './modules/address'
5+
import { InternetModule } from './modules/internet'
6+
import { PhoneModule } from './modules/phone'
7+
import { CompanyModule } from './modules/company'
8+
import { LoremModule } from './modules/lorem'
9+
import { DateModule } from './modules/date'
10+
import { NumberModule } from './modules/number'
11+
import { StringModule } from './modules/string'
12+
import { ColorModule } from './modules/color'
13+
import { FinanceModule } from './modules/finance'
14+
import { HelpersModule } from './modules/helpers'
15+
import { locales } from './locales'
16+
17+
/**
18+
* Main Faker class - the entry point for generating fake data
19+
*
20+
* @example
21+
* ```ts
22+
* import { Faker } from 'nanofaker'
23+
*
24+
* const faker = new Faker()
25+
* console.log(faker.person.firstName()) // 'John'
26+
* console.log(faker.internet.email()) // 'john.doe@example.com'
27+
* ```
28+
*/
29+
export class Faker {
30+
private _random: Random
31+
private _locale: LocaleDefinition
32+
33+
public readonly person: PersonModule
34+
public readonly address: AddressModule
35+
public readonly internet: InternetModule
36+
public readonly phone: PhoneModule
37+
public readonly company: CompanyModule
38+
public readonly lorem: LoremModule
39+
public readonly date: DateModule
40+
public readonly number: NumberModule
41+
public readonly string: StringModule
42+
public readonly color: ColorModule
43+
public readonly finance: FinanceModule
44+
public readonly helpers: HelpersModule
45+
46+
constructor(options?: FakerOptions) {
47+
const locale = options?.locale ?? 'en'
48+
const seed = options?.seed
49+
50+
this._locale = locales[locale] ?? locales.en
51+
this._random = new Random(seed)
52+
53+
// Initialize all modules
54+
this.person = new PersonModule(this._random, this._locale)
55+
this.address = new AddressModule(this._random, this._locale)
56+
this.internet = new InternetModule(this._random, this._locale)
57+
this.phone = new PhoneModule(this._random, this._locale)
58+
this.company = new CompanyModule(this._random, this._locale)
59+
this.lorem = new LoremModule(this._random)
60+
this.date = new DateModule(this._random)
61+
this.number = new NumberModule(this._random)
62+
this.string = new StringModule(this._random)
63+
this.color = new ColorModule(this._random)
64+
this.finance = new FinanceModule(this._random)
65+
this.helpers = new HelpersModule(this._random)
66+
}
67+
68+
/**
69+
* Set a seed for reproducible results
70+
* @example faker.seed(12345)
71+
*/
72+
seed(seed: number): this {
73+
this._random = new Random(seed)
74+
75+
// Reinitialize all modules with new random instance
76+
Object.assign(this.person, new PersonModule(this._random, this._locale))
77+
Object.assign(this.address, new AddressModule(this._random, this._locale))
78+
Object.assign(this.internet, new InternetModule(this._random, this._locale))
79+
Object.assign(this.phone, new PhoneModule(this._random, this._locale))
80+
Object.assign(this.company, new CompanyModule(this._random, this._locale))
81+
Object.assign(this.lorem, new LoremModule(this._random))
82+
Object.assign(this.date, new DateModule(this._random))
83+
Object.assign(this.number, new NumberModule(this._random))
84+
Object.assign(this.string, new StringModule(this._random))
85+
Object.assign(this.color, new ColorModule(this._random))
86+
Object.assign(this.finance, new FinanceModule(this._random))
87+
Object.assign(this.helpers, new HelpersModule(this._random))
88+
89+
return this
90+
}
91+
92+
/**
93+
* Set the locale
94+
* @example faker.setLocale('es')
95+
*/
96+
setLocale(locale: string): this {
97+
this._locale = locales[locale] ?? locales.en
98+
99+
// Reinitialize modules that depend on locale
100+
Object.assign(this.person, new PersonModule(this._random, this._locale))
101+
Object.assign(this.address, new AddressModule(this._random, this._locale))
102+
Object.assign(this.internet, new InternetModule(this._random, this._locale))
103+
Object.assign(this.phone, new PhoneModule(this._random, this._locale))
104+
Object.assign(this.company, new CompanyModule(this._random, this._locale))
105+
106+
return this
107+
}
108+
109+
/**
110+
* Get current locale
111+
*/
112+
get locale(): string {
113+
return this._locale.title
114+
}
115+
116+
/**
117+
* Get available locales
118+
*/
119+
static get availableLocales(): string[] {
120+
return Object.keys(locales)
121+
}
122+
123+
/**
124+
* Laravel-compatible: Generate a random name
125+
* @example faker.name() // 'John Doe'
126+
*/
127+
name(): string {
128+
return this.person.name()
129+
}
130+
131+
/**
132+
* Laravel-compatible: Generate a random email
133+
* @example faker.email() // 'john.doe@example.com'
134+
*/
135+
email(): string {
136+
return this.internet.email()
137+
}
138+
}

src/index.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,26 @@
11
export * from './config'
22
export * from './types'
3+
export * from './faker'
4+
export * from './random'
5+
export { locales, en } from './locales'
6+
7+
// Re-export modules
8+
export { PersonModule } from './modules/person'
9+
export { AddressModule } from './modules/address'
10+
export { InternetModule } from './modules/internet'
11+
export { PhoneModule } from './modules/phone'
12+
export { CompanyModule } from './modules/company'
13+
export { LoremModule } from './modules/lorem'
14+
export { DateModule } from './modules/date'
15+
export { NumberModule } from './modules/number'
16+
export { StringModule } from './modules/string'
17+
export { ColorModule } from './modules/color'
18+
export { FinanceModule } from './modules/finance'
19+
export { HelpersModule } from './modules/helpers'
20+
21+
// Default faker instance for convenience
22+
import { Faker } from './faker'
23+
export const faker = new Faker()
24+
25+
// Default export
26+
export default faker

src/locales/en.ts

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
import type { LocaleDefinition } from '../types'
2+
3+
export const en: LocaleDefinition = {
4+
title: 'English',
5+
person: {
6+
firstName: [
7+
'James', 'John', 'Robert', 'Michael', 'William', 'David', 'Richard', 'Joseph', 'Thomas', 'Charles',
8+
'Mary', 'Patricia', 'Jennifer', 'Linda', 'Elizabeth', 'Barbara', 'Susan', 'Jessica', 'Sarah', 'Karen',
9+
'Emma', 'Olivia', 'Ava', 'Isabella', 'Sophia', 'Mia', 'Charlotte', 'Amelia', 'Harper', 'Evelyn',
10+
'Liam', 'Noah', 'Oliver', 'Elijah', 'Lucas', 'Mason', 'Logan', 'Alexander', 'Ethan', 'Jacob',
11+
],
12+
lastName: [
13+
'Smith', 'Johnson', 'Williams', 'Brown', 'Jones', 'Garcia', 'Miller', 'Davis', 'Rodriguez', 'Martinez',
14+
'Hernandez', 'Lopez', 'Gonzalez', 'Wilson', 'Anderson', 'Thomas', 'Taylor', 'Moore', 'Jackson', 'Martin',
15+
'Lee', 'Perez', 'Thompson', 'White', 'Harris', 'Sanchez', 'Clark', 'Ramirez', 'Lewis', 'Robinson',
16+
],
17+
prefix: ['Mr.', 'Mrs.', 'Ms.', 'Miss', 'Dr.', 'Prof.'],
18+
suffix: ['Jr.', 'Sr.', 'I', 'II', 'III', 'IV', 'V', 'MD', 'PhD', 'DDS'],
19+
gender: ['Male', 'Female', 'Non-binary', 'Agender', 'Bigender', 'Genderfluid', 'Genderqueer'],
20+
jobTitle: [
21+
'Software Engineer', 'Product Manager', 'Designer', 'Data Scientist', 'DevOps Engineer',
22+
'Marketing Manager', 'Sales Representative', 'Accountant', 'Human Resources Manager', 'CEO',
23+
'CTO', 'CFO', 'COO', 'Director', 'Manager', 'Analyst', 'Consultant', 'Administrator',
24+
'Coordinator', 'Specialist', 'Developer', 'Architect', 'Engineer', 'Technician', 'Assistant',
25+
],
26+
},
27+
address: {
28+
street: [
29+
'Main', 'Oak', 'Maple', 'Cedar', 'Elm', 'Washington', 'Lake', 'Hill', 'Park', 'River',
30+
'Sunset', 'Pine', 'Walnut', 'Highland', 'Madison', 'Lincoln', 'Jackson', 'Franklin',
31+
],
32+
city: [
33+
'New York', 'Los Angeles', 'Chicago', 'Houston', 'Phoenix', 'Philadelphia', 'San Antonio',
34+
'San Diego', 'Dallas', 'San Jose', 'Austin', 'Jacksonville', 'Fort Worth', 'Columbus',
35+
'Charlotte', 'San Francisco', 'Indianapolis', 'Seattle', 'Denver', 'Boston', 'Nashville',
36+
],
37+
state: [
38+
'Alabama', 'Alaska', 'Arizona', 'Arkansas', 'California', 'Colorado', 'Connecticut',
39+
'Delaware', 'Florida', 'Georgia', 'Hawaii', 'Idaho', 'Illinois', 'Indiana', 'Iowa',
40+
'Kansas', 'Kentucky', 'Louisiana', 'Maine', 'Maryland', 'Massachusetts', 'Michigan',
41+
'Minnesota', 'Mississippi', 'Missouri', 'Montana', 'Nebraska', 'Nevada', 'New Hampshire',
42+
'New Jersey', 'New Mexico', 'New York', 'North Carolina', 'North Dakota', 'Ohio',
43+
'Oklahoma', 'Oregon', 'Pennsylvania', 'Rhode Island', 'South Carolina', 'South Dakota',
44+
'Tennessee', 'Texas', 'Utah', 'Vermont', 'Virginia', 'Washington', 'West Virginia',
45+
'Wisconsin', 'Wyoming',
46+
],
47+
stateAbbr: [
48+
'AL', 'AK', 'AZ', 'AR', 'CA', 'CO', 'CT', 'DE', 'FL', 'GA', 'HI', 'ID', 'IL', 'IN', 'IA',
49+
'KS', 'KY', 'LA', 'ME', 'MD', 'MA', 'MI', 'MN', 'MS', 'MO', 'MT', 'NE', 'NV', 'NH', 'NJ',
50+
'NM', 'NY', 'NC', 'ND', 'OH', 'OK', 'OR', 'PA', 'RI', 'SC', 'SD', 'TN', 'TX', 'UT', 'VT',
51+
'VA', 'WA', 'WV', 'WI', 'WY',
52+
],
53+
country: [
54+
'United States', 'Canada', 'United Kingdom', 'Australia', 'Germany', 'France', 'Spain',
55+
'Italy', 'Japan', 'China', 'India', 'Brazil', 'Mexico', 'Russia', 'South Korea',
56+
],
57+
countryCode: ['US', 'CA', 'GB', 'AU', 'DE', 'FR', 'ES', 'IT', 'JP', 'CN', 'IN', 'BR', 'MX', 'RU', 'KR'],
58+
zipCode: ['#####', '#####-####'],
59+
buildingNumber: ['###', '####', '#', '##'],
60+
direction: ['North', 'East', 'South', 'West', 'Northeast', 'Northwest', 'Southeast', 'Southwest'],
61+
streetSuffix: [
62+
'Street', 'Avenue', 'Road', 'Boulevard', 'Drive', 'Court', 'Circle', 'Lane', 'Way',
63+
'Place', 'Terrace', 'Parkway', 'Commons', 'Trail', 'Square', 'Run', 'Crossing',
64+
],
65+
},
66+
company: {
67+
name: [
68+
'TechCorp', 'GlobalSoft', 'DataSystems', 'CloudNet', 'Innovate Inc', 'Digital Solutions',
69+
'NextGen Tech', 'FutureTech', 'SmartSystems', 'CoreTech', 'PrimeSoft', 'AlphaTech',
70+
],
71+
suffix: ['Inc', 'LLC', 'Corp', 'Group', 'Ltd', 'Co', 'Technologies', 'Solutions', 'Systems'],
72+
industry: [
73+
'Technology', 'Finance', 'Healthcare', 'Education', 'Retail', 'Manufacturing',
74+
'Telecommunications', 'Energy', 'Real Estate', 'Transportation', 'Media', 'Hospitality',
75+
],
76+
buzzwords: [
77+
'synergize', 'leverage', 'innovate', 'disrupt', 'optimize', 'streamline', 'transform',
78+
'revolutionize', 'empower', 'enable', 'facilitate', 'orchestrate', 'integrate',
79+
],
80+
adjective: [
81+
'revolutionary', 'cutting-edge', 'innovative', 'next-generation', 'advanced', 'leading',
82+
'premier', 'world-class', 'enterprise', 'scalable', 'robust', 'seamless',
83+
],
84+
descriptor: [
85+
'global', 'digital', 'cloud-based', 'AI-powered', 'data-driven', 'user-centric',
86+
'agile', 'secure', 'efficient', 'intelligent', 'automated', 'integrated',
87+
],
88+
noun: [
89+
'solution', 'platform', 'system', 'service', 'technology', 'framework', 'infrastructure',
90+
'application', 'network', 'portal', 'ecosystem', 'architecture', 'engine',
91+
],
92+
},
93+
internet: {
94+
domainSuffix: ['com', 'net', 'org', 'io', 'co', 'app', 'dev', 'tech', 'ai', 'cloud'],
95+
freeEmail: ['gmail.com', 'yahoo.com', 'hotmail.com', 'outlook.com', 'icloud.com', 'proton.me'],
96+
},
97+
phone: {
98+
formats: [
99+
'###-###-####',
100+
'(###) ###-####',
101+
'1-###-###-####',
102+
'+1-###-###-####',
103+
'###.###.####',
104+
],
105+
},
106+
}

src/locales/es.ts

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
import type { LocaleDefinition } from '../types'
2+
3+
export const es: LocaleDefinition = {
4+
title: 'Spanish',
5+
person: {
6+
firstName: [
7+
'María', 'Carmen', 'Josefa', 'Isabel', 'Dolores', 'Pilar', 'Teresa', 'Ana', 'Francisca', 'Laura',
8+
'Antonio', 'José', 'Manuel', 'Francisco', 'Juan', 'David', 'Carlos', 'Miguel', 'Pedro', 'Luis',
9+
'Sofía', 'Isabella', 'Valentina', 'Camila', 'Valeria', 'Lucía', 'Martina', 'Emma', 'Victoria', 'Gabriela',
10+
],
11+
lastName: [
12+
'García', 'Martínez', 'López', 'González', 'Rodríguez', 'Fernández', 'Pérez', 'Sánchez', 'Ramírez', 'Torres',
13+
'Flores', 'Rivera', 'Gómez', 'Díaz', 'Cruz', 'Morales', 'Reyes', 'Gutiérrez', 'Ortiz', 'Jiménez',
14+
],
15+
prefix: ['Sr.', 'Sra.', 'Srta.', 'Dr.', 'Dra.', 'Prof.'],
16+
suffix: ['Jr.', 'Sr.', 'I', 'II', 'III', 'IV', 'V'],
17+
gender: ['Masculino', 'Femenino', 'No binario', 'Agénero', 'Bigénero', 'Género fluido'],
18+
jobTitle: [
19+
'Ingeniero de Software', 'Gerente de Producto', 'Diseñador', 'Científico de Datos', 'Ingeniero DevOps',
20+
'Gerente de Marketing', 'Representante de Ventas', 'Contador', 'Gerente de Recursos Humanos', 'Director',
21+
],
22+
},
23+
address: {
24+
street: [
25+
'Principal', 'Central', 'Mayor', 'Real', 'Nueva', 'San José', 'Las Flores', 'Del Sol',
26+
'La Paz', 'Libertad', 'Independencia', 'Reforma', 'Juárez', 'Hidalgo',
27+
],
28+
city: [
29+
'Madrid', 'Barcelona', 'Valencia', 'Sevilla', 'Zaragoza', 'Málaga', 'Murcia', 'Palma',
30+
'Las Palmas', 'Bilbao', 'Alicante', 'Córdoba', 'Valladolid', 'Vigo', 'Gijón',
31+
],
32+
state: [
33+
'Andalucía', 'Cataluña', 'Madrid', 'Comunidad Valenciana', 'Galicia', 'Castilla y León',
34+
'País Vasco', 'Canarias', 'Castilla-La Mancha', 'Murcia', 'Aragón', 'Extremadura',
35+
],
36+
stateAbbr: [
37+
'AN', 'CT', 'MD', 'VC', 'GA', 'CL', 'PV', 'CN', 'CM', 'MU', 'AR', 'EX',
38+
],
39+
country: [
40+
'España', 'México', 'Argentina', 'Colombia', 'Perú', 'Venezuela', 'Chile', 'Ecuador',
41+
'Guatemala', 'Cuba', 'República Dominicana', 'Honduras', 'Bolivia', 'Paraguay',
42+
],
43+
countryCode: ['ES', 'MX', 'AR', 'CO', 'PE', 'VE', 'CL', 'EC', 'GT', 'CU', 'DO', 'HN', 'BO', 'PY'],
44+
zipCode: ['#####'],
45+
buildingNumber: ['###', '##', '#'],
46+
direction: ['Norte', 'Sur', 'Este', 'Oeste', 'Noreste', 'Noroeste', 'Sureste', 'Suroeste'],
47+
streetSuffix: [
48+
'Calle', 'Avenida', 'Plaza', 'Paseo', 'Camino', 'Ronda', 'Travesía', 'Vía',
49+
'Glorieta', 'Callejón', 'Pasaje', 'Carretera',
50+
],
51+
},
52+
company: {
53+
name: [
54+
'TechnoSoft', 'IberiaTech', 'GlobalSol', 'DataMex', 'InnovaHispana', 'SoluDigital',
55+
'NuevaTech', 'FuturoSoft', 'SistemaSmart', 'CoreTech España',
56+
],
57+
suffix: ['S.A.', 'S.L.', 'S.R.L.', 'Ltda.', 'Corp', 'Tecnologías', 'Soluciones', 'Sistemas'],
58+
industry: [
59+
'Tecnología', 'Finanzas', 'Salud', 'Educación', 'Comercio', 'Manufactura',
60+
'Telecomunicaciones', 'Energía', 'Inmobiliaria', 'Transporte', 'Medios', 'Hostelería',
61+
],
62+
buzzwords: [
63+
'sinergizar', 'aprovechar', 'innovar', 'revolucionar', 'optimizar', 'transformar',
64+
'potenciar', 'habilitar', 'facilitar', 'orquestar', 'integrar',
65+
],
66+
adjective: [
67+
'revolucionario', 'innovador', 'avanzado', 'líder', 'premier', 'empresarial',
68+
'escalable', 'robusto', 'ágil', 'seguro', 'eficiente', 'inteligente',
69+
],
70+
descriptor: [
71+
'global', 'digital', 'en la nube', 'con IA', 'basado en datos', 'centrado en el usuario',
72+
'automatizado', 'integrado', 'moderno', 'innovador',
73+
],
74+
noun: [
75+
'solución', 'plataforma', 'sistema', 'servicio', 'tecnología', 'marco', 'infraestructura',
76+
'aplicación', 'red', 'portal', 'ecosistema', 'arquitectura',
77+
],
78+
},
79+
internet: {
80+
domainSuffix: ['es', 'com', 'net', 'org', 'mx', 'ar', 'co', 'cl'],
81+
freeEmail: ['gmail.com', 'yahoo.es', 'hotmail.es', 'outlook.es', 'correo.es'],
82+
},
83+
phone: {
84+
formats: [
85+
'###-###-###',
86+
'(+34) ###-###-###',
87+
'6##-###-###',
88+
'7##-###-###',
89+
],
90+
},
91+
}

0 commit comments

Comments
 (0)