Skip to content

Commit 84ce091

Browse files
committed
feat: Converts project to module, uses import/export syntax
1 parent 2c1341e commit 84ce091

20 files changed

Lines changed: 321 additions & 2421 deletions

.github/workflows/build.yml

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
- name: Setup Node
1212
uses: actions/setup-node@v4
1313
with:
14-
node-version: '22'
14+
node-version: '24'
1515
- name: Install dependencies
1616
run: npm install
1717
- name: Run Eslint
@@ -22,7 +22,7 @@ jobs:
2222
runs-on: ubuntu-latest
2323
strategy:
2424
matrix:
25-
nodeversion: ['16', '18', '20', '22']
25+
nodeversion: ['16', '18', '20', '22', '24']
2626
steps:
2727
- name: Checkout Repository
2828
uses: actions/checkout@v4
@@ -35,9 +35,4 @@ jobs:
3535
npm install
3636
git submodule init && git submodule update
3737
- name: Run tests
38-
run: npm run coverage
39-
- name: Coveralls
40-
if: github.ref == 'refs/heads/main'
41-
uses: coverallsapp/github-action@master
42-
with:
43-
github-token: ${{ secrets.GITHUB_TOKEN }}
38+
run: npm run test

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
- name: Setup Node
1515
uses: actions/setup-node@v4
1616
with:
17-
node-version: '22'
17+
node-version: '24'
1818
registry-url: 'https://registry.npmjs.org'
1919
- name: Install dependencies
2020
run: |

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# CHANGELOG
22

3+
## v6.0.0 (2025-08-05)
4+
5+
- Converts project to module, uses import/export syntax
6+
37
## v5.0.0 (2024-07-16)
48

59
- Drops support for Node < 16

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
Dummy Address Data (DAD) - Retrieve real addresses from all around the world.
66

77
[![Build Status](https://github.com/Justintime50/dad-node/workflows/build/badge.svg)](https://github.com/Justintime50/dad-node/actions)
8-
[![Coverage Status](https://coveralls.io/repos/github/Justintime50/dad-node/badge.svg?branch=main)](https://coveralls.io/github/Justintime50/dad-node?branch=main)
98
[![NPM](https://img.shields.io/npm/v/dad-tool)](https://www.npmjs.com/package/dad-tool)
109
[![Licence](https://img.shields.io/github/license/justintime50/dad-node)](https://opensource.org/licenses/mit-license.php)
1110

cli.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#!/usr/bin/env node
2-
const dad = require('./index');
2+
import { random } from './index.js';
33

44
// If dad-tool is utilized via CLI, return a random address from a list
55
// Usage: dad-tool US_UT
66
!(async function () {
77
const address_list = process.argv.slice(2);
8-
const address = dad.random(address_list[0]);
8+
const address = random(address_list[0]);
99
console.log(address);
1010
})();

index.js

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,30 @@
11
#!/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));
49

510
// 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);
915
}
1016

1117
// 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)];
1523
return address;
1624
}
1725

1826
// 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);
2230
}
23-
24-
exports.list = list;
25-
exports.random = random;
26-
exports.isoCountryCodes = isoCountryCodes;

lib/dataRouter.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function variables(data) {
1+
export function variables(data) {
22
// DAD variables
33
const addressDirectory = 'dad/src/addresses';
44
const fileExtension = '-addresses.min.json';
@@ -50,5 +50,3 @@ function variables(data) {
5050

5151
return dataFilePath;
5252
}
53-
54-
exports.variables = variables;

0 commit comments

Comments
 (0)