feature: initial commit
This commit is contained in:
commit
ce024ba87a
17 changed files with 1141 additions and 0 deletions
53
tests/helpers.ts
Normal file
53
tests/helpers.ts
Normal file
|
@ -0,0 +1,53 @@
|
|||
import lurid from '@andyburke/lurid';
|
||||
import { convert_to_words } from '@andyburke/lurid/word_bytes';
|
||||
|
||||
const TLDs: string[] = [
|
||||
'com',
|
||||
'org',
|
||||
'net',
|
||||
'edu',
|
||||
'gov',
|
||||
'nexus',
|
||||
'shop',
|
||||
'unreasonablylongtldname'
|
||||
];
|
||||
|
||||
const random_byte_buffer: Uint8Array = new Uint8Array(3);
|
||||
export function random_email_address(): string {
|
||||
crypto.getRandomValues(random_byte_buffer);
|
||||
const name = convert_to_words(random_byte_buffer).join('-');
|
||||
|
||||
crypto.getRandomValues(random_byte_buffer);
|
||||
const domain = convert_to_words(random_byte_buffer).join('-');
|
||||
|
||||
const tld = TLDs[Math.floor(Math.random() * TLDs.length)];
|
||||
return `${name}@${domain}.${tld}`;
|
||||
}
|
||||
|
||||
export function random_username(): string {
|
||||
crypto.getRandomValues(random_byte_buffer);
|
||||
return convert_to_words(random_byte_buffer).join('-');
|
||||
}
|
||||
|
||||
function get_a_random_array_element(values: any[]): any {
|
||||
return values[Math.floor(Math.random() * values.length)];
|
||||
}
|
||||
|
||||
const country_codes: string[] = ['', '+1', '1', '01', '219', '40', '506', '999'];
|
||||
const digits: number[] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
|
||||
const joinings: string[] = [' ', '-', '.'];
|
||||
export function random_phone_number(): string {
|
||||
const country_code = get_a_random_array_element(country_codes);
|
||||
const area_code = [0, 0, 0].map((_) => get_a_random_array_element(digits)).join('');
|
||||
const central_office_code = [0, 0, 0].map((_) => get_a_random_array_element(digits)).join('');
|
||||
const subscriber_code = [0, 0, 0, 0].map((_) => get_a_random_array_element(digits)).join('');
|
||||
|
||||
return `${country_code}${country_code ? get_a_random_array_element(joinings) : ''}${area_code}${
|
||||
get_a_random_array_element(joinings)
|
||||
}${central_office_code}${get_a_random_array_element(joinings)}${subscriber_code}`;
|
||||
}
|
||||
|
||||
const DATA_DIR = lurid();
|
||||
export function get_data_dir(): string {
|
||||
return Deno.env.get('TEST_DATA_STORAGE_ROOT') ?? DATA_DIR;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue