Skip to content

Commit

Permalink
Use ESM syntax, and update deps to support it
Browse files Browse the repository at this point in the history
  • Loading branch information
fershad authored Nov 8, 2024
2 parents a483393 + c92efbe commit b69cf46
Show file tree
Hide file tree
Showing 11 changed files with 3,968 additions and 8,768 deletions.
21 changes: 0 additions & 21 deletions .eslintrc.json

This file was deleted.

30 changes: 16 additions & 14 deletions .github/workflows/unittests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,27 @@ name: Unit tests
on:
push:
branches:
- main
- main
- master
pull_request:
branches:
- main
- main
- master
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.x, 18.x, 20.x]
node-version: [18.x, 20.x, 22.x]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Install
run: npm ci
- name: Verify lint
run: npm run lint
- name: Run unit tests
run: npm test
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: Install
run: npm ci
- name: Verify lint
run: npm run lint
- name: Run unit tests
run: npm test
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ Normally you can check domain against the The Green Web Foundation url2green dat

```js

const greencheck = require('@tgwf/hosting')
import greencheck from "@tgwf/hosting"

// returns true if green, otherwise false
greencheck.check("google.com")
await greencheck.check("google.com")

// returns an array of the green domains, in this case ["google"].
greencheck.check(["google.com", "kochindustries.com"])"]
await greencheck.check(["google.com", "kochindustries.com"])"]
```
## Usage
Expand All @@ -27,13 +27,13 @@ To do so, install this module with `npm install @tgwf/url2green`. You can then u
```js
const hostingDB = require('@tgwf/hosting-database');
import hostingDB from "@tgwf/hosting-database"
// returns true if green, otherwise false
hostingDB.check("google.com", "path/to/database.db");
await hostingDB.check("google.com", "path/to/database.db");
// returns an array of the green domains, in this case ["google.
hostingDB.check(["google.com", "kochindustries.com"], "path/to/database.db");
await hostingDB.check(["google.com", "kochindustries.com"], "path/to/database.db");
```

## Fetching the latest copy of the url2green dataset
Expand All @@ -44,9 +44,9 @@ You can generate a simple JSON list of the domains to check against, with `dumpD


```js
const hostingDB = require('@tgwf/hosting-database');
import hostingDB from "@tgwf/hosting-database"

hostingDB.dumpDomains("path/to/database.db", "path/to/output.json");
await hostingDB.dumpDomains("path/to/database.db", "path/to/output.json");
```

In cases where you don't want to rely on SQLite, this will generate a JSON file that allows you to perform the same lookups, using the `@tgwf/co2` module.
Expand Down
40 changes: 40 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import prettier from "eslint-plugin-prettier";
import jest from "eslint-plugin-jest";
import globals from "globals";
import path from "node:path";
import { fileURLToPath } from "node:url";
import js from "@eslint/js";
import { FlatCompat } from "@eslint/eslintrc";

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
allConfig: js.configs.all,
});

export default [
...compat.extends("eslint:recommended"),
{
plugins: {
prettier,
jest,
},

languageOptions: {
globals: {
...globals.node,
...jest.environments.globals.globals,
},

ecmaVersion: 2020,
},

rules: {
"prettier/prettier": ["error", { trailingComma: "all" }],
"no-unused-vars": "off",
},
},
];
Loading

0 comments on commit b69cf46

Please sign in to comment.