-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
executable file
·30 lines (25 loc) · 1016 Bytes
/
index.js
File metadata and controls
executable file
·30 lines (25 loc) · 1016 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/env node
import { promises as fs } from 'fs';
import path, { join } from 'path';
import { fileURLToPath } from 'url';
import { variables } from './lib/dataRouter.js';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
// Pull an entire list of addresses
export async function list(data) {
const filePath = join(__dirname, variables(data));
const fileContent = await fs.readFile(filePath, 'utf-8');
return JSON.parse(fileContent);
}
// Pull a single random address from a list
export async function random(data) {
const filePath = join(__dirname, variables(data));
const fileContent = await fs.readFile(filePath, 'utf-8');
const addressList = JSON.parse(fileContent);
const address = addressList[Math.floor(Math.random() * addressList.length)];
return address;
}
// Get a list of all ISO country codes
export async function isoCountryCodes() {
const fileContent = await fs.readFile('./dad/src/other/country-codes.min.json', 'utf-8');
return JSON.parse(fileContent);
}