Skip to content

Commit

Permalink
Merge branch 'next' into fix/image/dataUri/svg-base64
Browse files Browse the repository at this point in the history
  • Loading branch information
ST-DDT authored Sep 26, 2024
2 parents 7998630 + d6bceb6 commit 88bcda9
Show file tree
Hide file tree
Showing 18 changed files with 82 additions and 69 deletions.
4 changes: 2 additions & 2 deletions src/faker.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
8 changes: 4 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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';
4 changes: 2 additions & 2 deletions src/locale-proxy.ts → src/internal/locale-proxy.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
48 changes: 0 additions & 48 deletions src/internal/mersenne.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import type { Randomizer } from '../randomizer';

/**
* Copyright (c) 2022-2023 Faker
*
Expand Down Expand Up @@ -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);
}
},
};
}
File renamed without changes.
15 changes: 14 additions & 1 deletion src/locales/fr/company/legal_entity_type.ts
Original file line number Diff line number Diff line change
@@ -1 +1,14 @@
export default ['EI', 'EURL', 'GIE', 'SA', 'SARL', 'SAS', 'SCOP', 'SEM'];
export default [
'EI',
'EURL',
'GIE',
'SA',
'SARL',
'SAS',
'SASU',
'SCA',
'SCOP',
'SCS',
'SEM',
'SNC',
];
2 changes: 1 addition & 1 deletion src/modules/date/index.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/modules/string/index.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down
2 changes: 1 addition & 1 deletion src/simple-faker.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
48 changes: 48 additions & 0 deletions src/utils/mersenne.ts
Original file line number Diff line number Diff line change
@@ -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);
}
},
};
}
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
2 changes: 1 addition & 1 deletion test/modules/number.spec.ts
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/scripts/apidocs/method.example.ts
Original file line number Diff line number Diff line change
@@ -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 };
Expand Down
2 changes: 1 addition & 1 deletion test/scripts/apidocs/verify-jsdoc-tags.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion test/support/seeded-runs.ts
Original file line number Diff line number Diff line change
@@ -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];

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down

0 comments on commit 88bcda9

Please sign in to comment.