Skip to content

Commit 9bb1ae4

Browse files
committed
Use ESM syntax, and update deps to support it
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
1 parent 3a62c4a commit 9bb1ae4

File tree

8 files changed

+6865
-14337
lines changed

8 files changed

+6865
-14337
lines changed

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ Normally you can check domain against the The Green Web Foundation url2green dat
77

88
```js
99

10-
const greencheck = require('@tgwf/hosting')
10+
import greencheck from "@tgwf/hosting"
1111

1212
// returns true if green, otherwise false
13-
greencheck.check("google.com")
13+
await greencheck.check("google.com")
1414

1515
// returns an array of the green domains, in this case ["google"].
16-
greencheck.check(["google.com", "kochindustries.com"])"]
16+
await greencheck.check(["google.com", "kochindustries.com"])"]
1717
```
1818
1919
## Usage
@@ -27,13 +27,13 @@ To do so, install this module with `npm install @tgwf/url2green`. You can then u
2727
2828
```js
2929
30-
const hostingDB = require('@tgwf/hosting-database');
30+
import hostingDB from "@tgwf/hosting-database"
3131
3232
// returns true if green, otherwise false
33-
hostingDB.check("google.com", "path/to/database.db");
33+
await hostingDB.check("google.com", "path/to/database.db");
3434
3535
// returns an array of the green domains, in this case ["google.
36-
hostingDB.check(["google.com", "kochindustries.com"], "path/to/database.db");
36+
await hostingDB.check(["google.com", "kochindustries.com"], "path/to/database.db");
3737
```
3838

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

4545

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

49-
hostingDB.dumpDomains("path/to/database.db", "path/to/output.json");
49+
await hostingDB.dumpDomains("path/to/database.db", "path/to/output.json");
5050
```
5151

5252
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.

0 commit comments

Comments
 (0)