Skip to content

Commit

Permalink
feat(config): defaultFakerLocale
Browse files Browse the repository at this point in the history
  • Loading branch information
Akryum committed Jan 9, 2024
1 parent 9ca2ca9 commit ae3d8f6
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
2 changes: 0 additions & 2 deletions packages/core/src/factory/fakerGenerate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import type { Faker } from '@faker-js/faker'
import { runValueCode } from '../util/vm.js'
import { get } from '../util/get.js'

// import { fakerLocales } from './fakerLocales.js'

export interface GenerateValueFromFakerOptions {
factory: string
faker: Faker
Expand Down
6 changes: 5 additions & 1 deletion packages/core/src/factory/fakerGet.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import { getContext } from '../context.js'

export interface GetFakerOptions {
locale?: string
seed?: any
}

export async function getFaker(options: GetFakerOptions) {
const ctx = await getContext()

const allFakers = await import('@faker-js/faker')

// @ts-expect-error no index defined
const locale = allFakers[options.locale ?? 'en']
const locale = allFakers[options.locale ?? ctx.config.defaultFakerLocale ?? 'en']

const faker = new allFakers.Faker({
locale,
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/factory/fakerLocales.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const fakerLocales: Record<string, { name: string, faker: string }> = {
export const fakerLocales = {
af_ZA: {
name: 'Afrikaans (South Africa)',
faker: 'fakerAF_ZA',
Expand Down Expand Up @@ -271,4 +271,4 @@ export const fakerLocales: Record<string, { name: string, faker: string }> = {
name: 'Zulu (South Africa)',
faker: 'fakerZU_ZA',
},
}
} as const
10 changes: 10 additions & 0 deletions packages/core/src/types/config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { fakerLocales } from '../factory/fakerLocales.js'

export interface Config {
/**
* Options for the API server
Expand Down Expand Up @@ -40,5 +42,13 @@ export interface Config {
}
}

/**
* Those resource types will not appear in the resource database explorer in the UI.
*/
ignoredResourcesInExplorer?: string[]

/**
* Locale used by all calls to faker when not specified. Default is English.
*/
defaultFakerLocale?: keyof typeof fakerLocales
}

0 comments on commit ae3d8f6

Please sign in to comment.