diff --git a/src/faker.ts b/src/faker.ts index 5f5e14ce392..7b7f5e162a3 100644 --- a/src/faker.ts +++ b/src/faker.ts @@ -1,8 +1,8 @@ import type { LocaleDefinition, MetadataDefinition } from './definitions'; import { FakerError } from './errors/faker-error'; import { deprecated } from './internal/deprecated'; -import type { LocaleProxy } from './locale-proxy'; -import { createLocaleProxy } from './locale-proxy'; +import type { LocaleProxy } from './internal/locale-proxy'; +import { createLocaleProxy } from './internal/locale-proxy'; import { AirlineModule } from './modules/airline'; import { AnimalModule } from './modules/animal'; import { ColorModule } from './modules/color'; diff --git a/src/index.ts b/src/index.ts index 0b5903408da..f94b3aa0133 100644 --- a/src/index.ts +++ b/src/index.ts @@ -30,10 +30,6 @@ export type { export { FakerError } from './errors/faker-error'; export { Faker } from './faker'; export type { FakerOptions } from './faker'; -export { - generateMersenne32Randomizer, - generateMersenne53Randomizer, -} from './internal/mersenne'; export * from './locale'; export { fakerEN as faker } from './locale'; export * from './locales'; @@ -85,3 +81,7 @@ export type { WordModule } from './modules/word'; export type { Randomizer } from './randomizer'; export { SimpleFaker, simpleFaker } from './simple-faker'; export { mergeLocales } from './utils/merge-locales'; +export { + generateMersenne32Randomizer, + generateMersenne53Randomizer, +} from './utils/mersenne'; diff --git a/src/locale-proxy.ts b/src/internal/locale-proxy.ts similarity index 96% rename from src/locale-proxy.ts rename to src/internal/locale-proxy.ts index e99ba655156..dbb9f2779f2 100644 --- a/src/locale-proxy.ts +++ b/src/internal/locale-proxy.ts @@ -1,5 +1,5 @@ -import type { LocaleDefinition } from './definitions'; -import { FakerError } from './errors/faker-error'; +import type { LocaleDefinition } from '../definitions'; +import { FakerError } from '../errors/faker-error'; /** * A proxy for LocaleDefinition that marks all properties as required and throws an error when an entry is accessed that is not defined. diff --git a/src/internal/mersenne.ts b/src/internal/mersenne.ts index d01b5ee9b0e..351faa4e4b9 100644 --- a/src/internal/mersenne.ts +++ b/src/internal/mersenne.ts @@ -1,5 +1,3 @@ -import type { Randomizer } from '../randomizer'; - /** * Copyright (c) 2022-2023 Faker * @@ -325,49 +323,3 @@ export class MersenneTwister19937 { } // These real versions are due to Isaku Wada, 2002/01/09 } - -/** - * Generates a MersenneTwister19937 randomizer with 32 bits of precision. - * This is the default randomizer used by faker prior to v9.0. - */ -export function generateMersenne32Randomizer(): Randomizer { - const twister = new MersenneTwister19937(); - - twister.initGenrand(Math.ceil(Math.random() * Number.MAX_SAFE_INTEGER)); - - return { - next(): number { - return twister.genrandReal2(); - }, - seed(seed: number | number[]): void { - if (typeof seed === 'number') { - twister.initGenrand(seed); - } else if (Array.isArray(seed)) { - twister.initByArray(seed, seed.length); - } - }, - }; -} - -/** - * Generates a MersenneTwister19937 randomizer with 53 bits of precision. - * This is the default randomizer used by faker starting with v9.0. - */ -export function generateMersenne53Randomizer(): Randomizer { - const twister = new MersenneTwister19937(); - - twister.initGenrand(Math.ceil(Math.random() * Number.MAX_SAFE_INTEGER)); - - return { - next(): number { - return twister.genrandRes53(); - }, - seed(seed: number | number[]): void { - if (typeof seed === 'number') { - twister.initGenrand(seed); - } else if (Array.isArray(seed)) { - twister.initByArray(seed, seed.length); - } - }, - }; -} diff --git a/src/utils/types.ts b/src/internal/types.ts similarity index 100% rename from src/utils/types.ts rename to src/internal/types.ts diff --git a/src/modules/date/index.ts b/src/modules/date/index.ts index f2eac1cf80e..53204a03817 100644 --- a/src/modules/date/index.ts +++ b/src/modules/date/index.ts @@ -1,8 +1,8 @@ import type { Faker } from '../..'; import type { DateEntryDefinition } from '../../definitions'; import { FakerError } from '../../errors/faker-error'; +import { assertLocaleData } from '../../internal/locale-proxy'; import { SimpleModuleBase } from '../../internal/module-base'; -import { assertLocaleData } from '../../locale-proxy'; /** * Converts a date passed as a `string`, `number` or `Date` to a valid `Date` object. diff --git a/src/modules/string/index.ts b/src/modules/string/index.ts index cfee0dc13fe..7df31fc7f7d 100644 --- a/src/modules/string/index.ts +++ b/src/modules/string/index.ts @@ -1,6 +1,6 @@ import { FakerError } from '../../errors/faker-error'; import { SimpleModuleBase } from '../../internal/module-base'; -import type { LiteralUnion } from '../../utils/types'; +import type { LiteralUnion } from '../../internal/types'; export type Casing = 'upper' | 'lower' | 'mixed'; diff --git a/src/simple-faker.ts b/src/simple-faker.ts index e775cbc7b5d..743df923570 100644 --- a/src/simple-faker.ts +++ b/src/simple-faker.ts @@ -1,10 +1,10 @@ -import { generateMersenne53Randomizer } from './internal/mersenne'; import { DatatypeModule } from './modules/datatype'; import { SimpleDateModule } from './modules/date'; import { SimpleHelpersModule } from './modules/helpers'; import { NumberModule } from './modules/number'; import { StringModule } from './modules/string'; import type { Randomizer } from './randomizer'; +import { generateMersenne53Randomizer } from './utils/mersenne'; /** * This is a simplified Faker class that doesn't need any localized data to generate its output. diff --git a/src/utils/mersenne.ts b/src/utils/mersenne.ts new file mode 100644 index 00000000000..de415f9166e --- /dev/null +++ b/src/utils/mersenne.ts @@ -0,0 +1,48 @@ +import { MersenneTwister19937 } from '../internal/mersenne'; +import type { Randomizer } from '../randomizer'; + +/** + * Generates a MersenneTwister19937 randomizer with 32 bits of precision. + * This is the default randomizer used by faker prior to v9.0. + */ +export function generateMersenne32Randomizer(): Randomizer { + const twister = new MersenneTwister19937(); + + twister.initGenrand(Math.ceil(Math.random() * Number.MAX_SAFE_INTEGER)); + + return { + next(): number { + return twister.genrandReal2(); + }, + seed(seed: number | number[]): void { + if (typeof seed === 'number') { + twister.initGenrand(seed); + } else if (Array.isArray(seed)) { + twister.initByArray(seed, seed.length); + } + }, + }; +} + +/** + * Generates a MersenneTwister19937 randomizer with 53 bits of precision. + * This is the default randomizer used by faker starting with v9.0. + */ +export function generateMersenne53Randomizer(): Randomizer { + const twister = new MersenneTwister19937(); + + twister.initGenrand(Math.ceil(Math.random() * Number.MAX_SAFE_INTEGER)); + + return { + next(): number { + return twister.genrandRes53(); + }, + seed(seed: number | number[]): void { + if (typeof seed === 'number') { + twister.initGenrand(seed); + } else if (Array.isArray(seed)) { + twister.initByArray(seed, seed.length); + } + }, + }; +} diff --git a/test/locale-proxy.spec.ts b/test/internal/locale-proxy.spec.ts similarity index 98% rename from test/locale-proxy.spec.ts rename to test/internal/locale-proxy.spec.ts index c9c8928c76c..1b6e060b9ca 100644 --- a/test/locale-proxy.spec.ts +++ b/test/internal/locale-proxy.spec.ts @@ -1,6 +1,6 @@ import { describe, expect, it } from 'vitest'; -import { FakerError, en } from '../src'; -import { createLocaleProxy } from '../src/locale-proxy'; +import { FakerError, en } from '../../src'; +import { createLocaleProxy } from '../../src/internal/locale-proxy'; describe('LocaleProxy', () => { const locale = createLocaleProxy(en); diff --git a/test/modules/number.spec.ts b/test/modules/number.spec.ts index f318fc5be09..f9adf9ff07d 100644 --- a/test/modules/number.spec.ts +++ b/test/modules/number.spec.ts @@ -1,8 +1,8 @@ import validator from 'validator'; import { describe, expect, it } from 'vitest'; import { FakerError, SimpleFaker, faker } from '../../src'; -import { MERSENNE_MAX_VALUE } from '../internal/mersenne-test-utils'; import { seededTests } from '../support/seeded-runs'; +import { MERSENNE_MAX_VALUE } from '../utils/mersenne-test-utils'; import { times } from './../support/times'; describe('number', () => { diff --git a/test/scripts/apidocs/method.example.ts b/test/scripts/apidocs/method.example.ts index e72f5f3ff9a..4ecdaee1ad7 100644 --- a/test/scripts/apidocs/method.example.ts +++ b/test/scripts/apidocs/method.example.ts @@ -1,7 +1,7 @@ import type { Casing, ColorFormat } from '../../../src'; import { FakerError } from '../../../src/errors/faker-error'; +import type { LiteralUnion } from '../../../src/internal/types'; import type { AlphaNumericChar } from '../../../src/modules/string'; -import type { LiteralUnion } from '../../../src/utils/types'; // explicitly export types so they show up in the docs as decomposed types export type { NumberColorFormat, StringColorFormat } from '../../../src'; export type { AlphaNumericChar, Casing, ColorFormat, LiteralUnion }; diff --git a/test/scripts/apidocs/verify-jsdoc-tags.spec.ts b/test/scripts/apidocs/verify-jsdoc-tags.spec.ts index ea5ed8b9b69..753ef9b3ce9 100644 --- a/test/scripts/apidocs/verify-jsdoc-tags.spec.ts +++ b/test/scripts/apidocs/verify-jsdoc-tags.spec.ts @@ -119,7 +119,7 @@ describe('verify JSDoc tags', () => { ); if (moduleName === 'randomizer') { - examples = `import { generateMersenne32Randomizer } from '${relativeImportPath}/internal/mersenne'; + examples = `import { generateMersenne32Randomizer } from '${relativeImportPath}/utils/mersenne'; const randomizer = generateMersenne32Randomizer(); diff --git a/test/support/seeded-runs.ts b/test/support/seeded-runs.ts index a05f185430d..dee0051c11b 100644 --- a/test/support/seeded-runs.ts +++ b/test/support/seeded-runs.ts @@ -1,6 +1,6 @@ import { describe, expect, describe as vi_describe, it as vi_it } from 'vitest'; import type { Faker } from '../../src/faker'; -import type { Callable, MethodOf } from '../../src/utils/types'; +import type { Callable, MethodOf } from '../../src/internal/types'; export const seededRuns = [42, 1337, 1211]; diff --git a/test/internal/__snapshots__/mersenne.spec.ts.snap b/test/utils/__snapshots__/mersenne.spec.ts.snap similarity index 100% rename from test/internal/__snapshots__/mersenne.spec.ts.snap rename to test/utils/__snapshots__/mersenne.spec.ts.snap diff --git a/test/internal/mersenne-test-utils.ts b/test/utils/mersenne-test-utils.ts similarity index 100% rename from test/internal/mersenne-test-utils.ts rename to test/utils/mersenne-test-utils.ts diff --git a/test/internal/mersenne.spec.ts b/test/utils/mersenne.spec.ts similarity index 97% rename from test/internal/mersenne.spec.ts rename to test/utils/mersenne.spec.ts index f0e48bd0f78..5e9e4c27bc6 100644 --- a/test/internal/mersenne.spec.ts +++ b/test/utils/mersenne.spec.ts @@ -1,10 +1,10 @@ import { beforeAll, beforeEach, describe, expect, it } from 'vitest'; +import { MersenneTwister19937 } from '../../src/internal/mersenne'; +import type { Randomizer } from '../../src/randomizer'; import { - MersenneTwister19937, generateMersenne32Randomizer, generateMersenne53Randomizer, -} from '../../src/internal/mersenne'; -import type { Randomizer } from '../../src/randomizer'; +} from '../../src/utils/mersenne'; import { seededRuns } from '../support/seeded-runs'; import { times } from '../support/times'; import {