Skip to content

Commit 861dddb

Browse files
authored
Merge pull request #37 from ThaUnknown/esm
BREAKING CHANGE: ESM only feat: esm
2 parents 91c7cd0 + 44260b8 commit 861dddb

File tree

4 files changed

+26
-16
lines changed

4 files changed

+26
-16
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Given one of the following:
3030
this module loads the ip set (downloading from the network, if necessary) and returns an [ip-set](https://www.npmjs.org/package/ip-set) object. An `ip-set` is just a mutable set data structure optimized for use with IPv4 and IPv6 addresses.
3131

3232
```js
33-
const loadIPSet = require('load-ip-set')
33+
import loadIPSet from 'load-ip-set'
3434
loadIPSet('http://example.com/list.txt', (err, ipSet) => {
3535
if (err) throw err
3636
ipSet.contains('1.2.3.4') //=> true

index.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/*! load-ip-set. MIT License. WebTorrent LLC <https://webtorrent.io/opensource> */
2-
const fs = require('fs')
3-
const get = require('simple-get')
4-
const IPSet = require('ip-set')
5-
const Netmask = require('netmask').Netmask
6-
const once = require('once')
7-
const split = require('split')
8-
const zlib = require('zlib')
2+
import fs from 'fs'
3+
import get from 'simple-get'
4+
import IPSet from 'ip-set'
5+
import { Netmask } from 'netmask'
6+
import once from 'once'
7+
import split from 'split'
8+
import zlib from 'zlib'
99

1010
// Match single IPs and IP ranges (IPv4 and IPv6), with or without a description
1111
const ipSetRegex = /^\s*(?:[^#].*?\s*:\s*)?([a-f0-9.:]+)(?:\s*-\s*([a-f0-9.:]+))?\s*$/
@@ -56,4 +56,4 @@ function loadIPSet (input, opts, cb) {
5656
}
5757
}
5858

59-
module.exports = loadIPSet
59+
export default loadIPSet

package.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"bugs": {
1414
"url": "https://github.com/webtorrent/load-ip-set/issues"
1515
},
16+
"type": "module",
1617
"dependencies": {
1718
"ip-set": "^2.1.0",
1819
"netmask": "^2.0.1",
@@ -37,7 +38,12 @@
3738
"webtorrent"
3839
],
3940
"license": "MIT",
40-
"main": "index.js",
41+
"engines": {
42+
"node": ">=12.20.0"
43+
},
44+
"exports": {
45+
"import": "./index.js"
46+
},
4147
"repository": {
4248
"type": "git",
4349
"url": "git://github.com/webtorrent/load-ip-set.git"

test/basic.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
const fs = require('fs')
2-
const http = require('http')
3-
const loadIPSet = require('../')
4-
const path = require('path')
5-
const test = require('tape')
6-
const zlib = require('zlib')
1+
import fs from 'fs'
2+
import http from 'http'
3+
import loadIPSet from '../index.js'
4+
import path, { dirname } from 'path'
5+
import test from 'tape'
6+
import zlib from 'zlib'
7+
import { fileURLToPath } from 'url'
8+
9+
const __filename = fileURLToPath(import.meta.url)
10+
const __dirname = dirname(__filename)
711

812
test('array of IPs', t => {
913
t.plan(5)

0 commit comments

Comments
 (0)