Skip to content

Commit

Permalink
chore: switch to ESM (#17)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: ESM only
* refactor: esm module update

- use export and import with destructuring
- define default exports
- update tests
Signed-off-by: Lakshya Singh <[email protected]>

* chore: update package.json and readme

- use destruct in readme
Signed-off-by: Lakshya Singh <[email protected]>

* chore: update deps security issue

Signed-off-by: Lakshya Singh <[email protected]>

* Update package.json

Signed-off-by: Lakshya Singh <[email protected]>
Co-authored-by: Diego Rodríguez Baquero <[email protected]>
BREAKING CHANGE: ESM only
  • Loading branch information
king-11 authored Nov 16, 2022
1 parent 76f1086 commit 68d1c3c
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 20 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ npm install bep53-range
Parse Magnet URI extension (BEP53) range and return all included values.

```js
const bep53Range = require('bep53-range')
import { parse } from 'bep53-range'

const range = ['1-3', '6', '11-13']

const values = bep53Range.parse(range)
const values = parse(range)
console.log(values) // [1, 2, 3, 6, 11, 12, 13]

```
Expand All @@ -40,11 +40,11 @@ console.log(values) // [1, 2, 3, 6, 11, 12, 13]
Compose Magnet URI extension (BEP53) range from all included values.

```js
const bep53Range = require('bep53-range')
import { compose } from 'bep53-range'

const values = [1, 2, 3, 6, 11, 12, 13]

const range = bep53Range.compose(values)
const range = compose(values)
console.log(range) // ['1-3', '6', '11-13']
```

Expand Down
11 changes: 7 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
module.exports = parseRange
module.exports.parse = parseRange
module.exports.compose = composeRange

function composeRange (range) {
return range
.reduce((acc, cur, idx, arr) => {
Expand All @@ -23,3 +19,10 @@ function parseRange (range) {
return acc.concat(generateRange(...r))
}, [])
}

export default parseRange

export {
parseRange as parse,
composeRange as compose
}
7 changes: 7 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "bep53-range",
"description": "Magnet URI extension (BEP53) range implementation",
"type": "module",
"version": "1.1.1",
"author": {
"name": "Julen Garcia Leunda",
Expand All @@ -15,6 +16,12 @@
"standard": "*",
"tape": "5.6.1"
},
"engines": {
"node": ">=12.20.0"
},
"exports": {
"import": "./index.js"
},
"main": "index.js",
"types": "index.d.ts",
"repository": {
Expand Down
12 changes: 6 additions & 6 deletions test/compose.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
const test = require('tape')
const bep53Range = require('..')
import test from 'tape'
import { compose } from '../index.js'

test('compose: a number', t => {
const range = bep53Range.compose([1])
const range = compose([1])

t.deepEqual(range, ['1'])
t.end()
})

test('compose: one range', t => {
const range = bep53Range.compose([1, 2, 3])
const range = compose([1, 2, 3])

t.deepEqual(range, ['1-3'])
t.end()
})

test('compose: multiple ranges', t => {
const range = bep53Range.compose([1, 2, 3, 11, 12, 13])
const range = compose([1, 2, 3, 11, 12, 13])

t.deepEqual(range, ['1-3', '11-13'])
t.end()
})

test('compose: multiple ranges between a number', t => {
const range = bep53Range.compose([1, 2, 3, 6, 11, 12, 13])
const range = compose([1, 2, 3, 6, 11, 12, 13])

t.deepEqual(range, ['1-3', '6', '11-13'])
t.end()
Expand Down
12 changes: 6 additions & 6 deletions test/parse.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
const test = require('tape')
const bep53Range = require('..')
import test from 'tape'
import { parse } from '../index.js'

test('parse: a number', t => {
const range = bep53Range.parse(['1'])
const range = parse(['1'])

t.deepEqual(range, [1])
t.end()
})

test('parse: one range', t => {
const range = bep53Range.parse(['1-3'])
const range = parse(['1-3'])

t.deepEqual(range, [1, 2, 3])
t.end()
})

test('parse: multiple ranges', t => {
const range = bep53Range.parse(['1-3', '11-13'])
const range = parse(['1-3', '11-13'])

t.deepEqual(range, [1, 2, 3, 11, 12, 13])
t.end()
})

test('parse: multiple ranges between a number', t => {
const range = bep53Range.parse(['1-3', '6', '11-13'])
const range = parse(['1-3', '6', '11-13'])

t.deepEqual(range, [1, 2, 3, 6, 11, 12, 13])
t.end()
Expand Down

0 comments on commit 68d1c3c

Please sign in to comment.