-
-
Notifications
You must be signed in to change notification settings - Fork 943
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'next' into feat/internet/ipv4
- Loading branch information
Showing
24 changed files
with
140 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')); | ||
} | ||
); | ||
}); |
4 changes: 2 additions & 2 deletions
4
test/locale-proxy.spec.ts → test/internal/locale-proxy.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters