Skip to content

Commit

Permalink
Merge branch 'next' into feat/internet/ipv4
Browse files Browse the repository at this point in the history
  • Loading branch information
ST-DDT authored Sep 26, 2024
2 parents e5ded28 + 4a8499a commit c559507
Show file tree
Hide file tree
Showing 24 changed files with 140 additions and 74 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@

All notable changes to this project will be documented in this file. See [commit-and-tag-version](https://github.com/absolute-version/commit-and-tag-version) for commit guidelines.

## [9.0.3](https://github.com/faker-js/faker/compare/v9.0.2...v9.0.3) (2024-09-26)


### Changed Locales

* **locale:** update french legal entity types ([#3142](https://github.com/faker-js/faker/issues/3142)) ([d6bceb6](https://github.com/faker-js/faker/commit/d6bceb662de6559446fedb11de53a632a525aba0))


### Bug Fixes

* **image:** fix dataUri with type svg-base64 in browsers ([#3144](https://github.com/faker-js/faker/issues/3144)) ([78b2a3a](https://github.com/faker-js/faker/commit/78b2a3a8b85679eeff27beccebcc404b0a5ff3cf))

## [9.0.2](https://github.com/faker-js/faker/compare/v9.0.1...v9.0.2) (2024-09-23)


Expand Down
2 changes: 1 addition & 1 deletion docs/guide/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const randomEmail = faker.internet.email(); // Tomasa_Ferry14@hotmail.com
```

::: info Note
It is highly recommended to use version tags when importing libraries in Deno, e.g: `import { faker } from "https://esm.sh/@faker-js/faker@v9.0.2"`.
It is highly recommended to use version tags when importing libraries in Deno, e.g: `import { faker } from "https://esm.sh/@faker-js/faker@v9.0.3"`.
:::

### Alternative CDN links
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@faker-js/faker",
"version": "9.0.2",
"version": "9.0.3",
"description": "Generate massive amounts of fake contextual data",
"scripts": {
"clean": "rimraf coverage .eslintcache dist docs/.vitepress/cache docs/.vitepress/dist node_modules",
Expand Down
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 @@ -86,3 +82,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';
24 changes: 24 additions & 0 deletions src/internal/base64.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* This works the same as `Buffer.from(input).toString('base64')`
* to work on both Node.js and browser environment.
*
* @internal
*
* @param input The string to encode to Base64.
*
* @returns Base64 encoded string.
*
* @see https://datatracker.ietf.org/doc/html/rfc4648
*
* @example const encodedHeader = toBase64(JSON.stringify(header));
*/
export const toBase64: (input: string) => string =
typeof Buffer === 'undefined'
? (input) => {
const utf8Bytes = new TextEncoder().encode(input);
const binaryString = Array.from(utf8Bytes, (byte) =>
String.fromCodePoint(byte)
).join('');
return btoa(binaryString);
}
: (input) => Buffer.from(input).toString('base64');
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
5 changes: 2 additions & 3 deletions src/modules/image/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { toBase64 } from '../../internal/base64';
import { deprecated } from '../../internal/deprecated';
import { ModuleBase } from '../../internal/module-base';

Expand Down Expand Up @@ -388,8 +389,6 @@ export class ImageModule extends ModuleBase {

return type === 'svg-uri'
? `data:image/svg+xml;charset=UTF-8,${encodeURIComponent(svgString)}`
: `data:image/svg+xml;base64,${Buffer.from(svgString).toString(
'base64'
)}`;
: `data:image/svg+xml;base64,${toBase64(svgString)}`;
}
}
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);
}
},
};
}
18 changes: 18 additions & 0 deletions test/internal/base64.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { describe, expect, it } from 'vitest';
import { faker } from '../../src';
import { toBase64 } from '../../src/internal/base64';

// This test is kind of useless, because during testing the Buffer object is always available.
describe('toBase64', () => {
it.each(
faker.helpers.multiple(
() => faker.string.alphanumeric({ length: { min: 0, max: 100 } }),
{ count: 5 }
)
)(
"should behave the same as `Buffer.from(value).toString('base64')`",
(value) => {
expect(toBase64(value)).toBe(Buffer.from(value).toString('base64'));
}
);
});
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 c559507

Please sign in to comment.