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
This switches from the commonjs require() syntax to the newer ESM
import syntax.

Jest did not work with the ESM syntax, so I updated the Jest config to
use esbuild to transpile the ESM syntax to commonjs, so Jest can still
run the tests.

We do this in the main CO2.js package, to it seemed an ok precedent to
follow.

This also updates better-sqlite, to use a new version which seems to
offer pre-builds, as of #1002 on the better sqlite repo.
WiseLibs/better-sqlite3#1002
  • Loading branch information
mrchrisadams committed Oct 26, 2024
1 parent 3a62c4a commit 9bb1ae4
Show file tree
Hide file tree
Showing 8 changed files with 6,865 additions and 14,337 deletions.
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
Loading

0 comments on commit 9bb1ae4

Please sign in to comment.