|
1 | 1 | #!/usr/bin/env node |
2 | | -const path = require('path'); |
3 | | -const dataRouter = require('./lib/dataRouter'); |
| 2 | +import { promises as fs } from 'fs'; |
| 3 | +import path, { join } from 'path'; |
| 4 | +import { fileURLToPath } from 'url'; |
| 5 | + |
| 6 | +import { variables } from './lib/dataRouter.js'; |
| 7 | + |
| 8 | +const __dirname = path.dirname(fileURLToPath(import.meta.url)); |
4 | 9 |
|
5 | 10 | // Pull an entire list of addresses |
6 | | -function list(data) { |
7 | | - const list = require(path.join(__dirname, dataRouter.variables(data))); |
8 | | - return list; |
| 11 | +export async function list(data) { |
| 12 | + const filePath = join(__dirname, variables(data)); |
| 13 | + const fileContent = await fs.readFile(filePath, 'utf-8'); |
| 14 | + return JSON.parse(fileContent); |
9 | 15 | } |
10 | 16 |
|
11 | 17 | // Pull a single random address from a list |
12 | | -function random(data) { |
13 | | - const randomAddress = require(path.join(__dirname, dataRouter.variables(data))); |
14 | | - const address = randomAddress[Math.floor(Math.random() * randomAddress.length)]; |
| 18 | +export async function random(data) { |
| 19 | + const filePath = join(__dirname, variables(data)); |
| 20 | + const fileContent = await fs.readFile(filePath, 'utf-8'); |
| 21 | + const addressList = JSON.parse(fileContent); |
| 22 | + const address = addressList[Math.floor(Math.random() * addressList.length)]; |
15 | 23 | return address; |
16 | 24 | } |
17 | 25 |
|
18 | 26 | // Get a list of all ISO country codes |
19 | | -function isoCountryCodes() { |
20 | | - const isoData = require('./dad/src/other/country-codes.min.json'); |
21 | | - return isoData; |
| 27 | +export async function isoCountryCodes() { |
| 28 | + const fileContent = await fs.readFile('./dad/src/other/country-codes.min.json', 'utf-8'); |
| 29 | + return JSON.parse(fileContent); |
22 | 30 | } |
23 | | - |
24 | | -exports.list = list; |
25 | | -exports.random = random; |
26 | | -exports.isoCountryCodes = isoCountryCodes; |
|
0 commit comments