Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: switch to ESM #21

Merged
merged 4 commits into from
Nov 16, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ npm install addr-to-ip-port
### usage

```js
const addrToIPPort = require('addr-to-ip-port')
import addrToIPPort from 'addr-to-ip-port'

addrToIPPort('1.2.3.4:8000') //=> ['1.2.3.4', 8000]
addrToIPPort('1.2.3.4:8000') //=> ['1.2.3.4', 8000] (returns the cached object)
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ let cache = new Map()

// reset cache when it gets to 100,000 elements (~ 600KB of ipv4 addresses)
// so it will not grow to consume all memory in long-running processes
module.exports = function addrToIPPort (addr) {
export default function addrToIPPort (addr) {
if (cache.size === 100000) cache.clear()
if (!cache.has(addr)) {
const m = ADDR_RE.exec(addr)
Expand Down
11 changes: 9 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "addr-to-ip-port",
"description": "Convert an 'address:port' string to an array [address:string, port:number]",
"type": "module",
"version": "1.5.4",
"author": {
"name": "WebTorrent, LLC",
Expand All @@ -14,8 +15,14 @@
"devDependencies": {
"@webtorrent/semantic-release-config": "1.0.7",
"benchmark": "2.1.4",
"semantic-release": "17.4.7",
"tape": "5.5.2"
"semantic-release": "^19.0.5",
DiegoRBaquero marked this conversation as resolved.
Show resolved Hide resolved
"tape": "5.5.3"
},
"engines": {
"node": ">=12.20.0"
},
"exports": {
"import": "./index.js"
},
"homepage": "https://github.com/webtorrent/addr-to-ip-port",
"keywords": [
Expand Down
5 changes: 3 additions & 2 deletions perf/basic.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const addrToIPPort = require('../')
const util = require('./util')
import addrToIPPort from '../index.js'
import util from './util.js'

const suite = util.suite()

// Around 262k addresses to cause 2 resets
Expand Down
2 changes: 1 addition & 1 deletion perf/util.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const benchmark = require('benchmark')
import benchmark from 'benchmark';

exports.suite = () => {
const suite = new benchmark.Suite()
Expand Down
4 changes: 2 additions & 2 deletions test/basic.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const addrToIPPort = require('../')
const test = require('tape')
import test from 'tape'
import addrToIPPort from '../index.js'

test('Basic tests', t => {
t.deepEqual(addrToIPPort('1.2.3.4:1000'), [ '1.2.3.4', 1000 ])
Expand Down