Skip to content

Commit efaf79d

Browse files
committed
chore: switch to esm
BREAKING CHANGE: built content includes ESM and CJS
1 parent e406359 commit efaf79d

18 files changed

+105
-104
lines changed
File renamed without changes.

index.js

Lines changed: 0 additions & 16 deletions
This file was deleted.

package.json

Lines changed: 40 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,17 @@
22
"name": "uint8arrays",
33
"version": "2.1.7",
44
"description": "Utility functions to make dealing with Uint8Arrays easier",
5-
"main": "index.js",
5+
"main": "src/index.js",
66
"author": "Alex Potsides <[email protected]>",
77
"homepage": "https://github.com/achingbrain/uint8arrays",
88
"bugs": "https://github.com/achingbrain/uint8arrays/issues",
9-
"types": "dist/index.d.ts",
10-
"typesVersions": {
11-
"*": {
12-
"*": [
13-
"dist/*"
14-
],
15-
"index.js": [
16-
"dist/index.d.ts"
17-
]
18-
}
19-
},
20-
"files": [
21-
"compare.js",
22-
"concat.js",
23-
"equals.js",
24-
"from-string.js",
25-
"index.js",
26-
"to-string.js",
27-
"xor.js",
28-
"dist/*.ts",
29-
"dist/*.map",
30-
"dist/*.js",
31-
"util/*.js"
32-
],
9+
"type": "module",
10+
"types": "dist/types/index.d.ts",
3311
"repository": {
3412
"type": "git",
3513
"url": "https://github.com/achingbrain/uint8arrays.git"
3614
},
3715
"scripts": {
38-
"prepare": "aegir build --no-bundle",
3916
"test": "aegir test",
4017
"lint": "aegir ts -p check && aegir lint",
4118
"release": "aegir release",
@@ -48,15 +25,51 @@
4825
"multiformats": "^9.4.2"
4926
},
5027
"devDependencies": {
51-
"aegir": "^34.0.2",
28+
"aegir": "https://gitpkg.now.sh/ipfs/aegir?feat/build-esm-modules-follow-up",
5229
"util": "^0.12.4"
5330
},
5431
"eslintConfig": {
5532
"extends": "ipfs",
33+
"parserOptions": {
34+
"sourceType": "module"
35+
},
5636
"ignorePatterns": [
5737
"!.aegir.js"
5838
]
5939
},
40+
"typesVersions": {
41+
"*": {
42+
"*": [
43+
"types/*"
44+
],
45+
"types/*": [
46+
"types/*"
47+
]
48+
}
49+
},
50+
"exports": {
51+
".": {
52+
"import": "./src/index.js"
53+
},
54+
"./compare": {
55+
"import": "./src/compare.js"
56+
},
57+
"./concat": {
58+
"import": "./src/concat.js"
59+
},
60+
"./equals": {
61+
"import": "./src/equals.js"
62+
},
63+
"./fromString": {
64+
"import": "./src/from-string.js"
65+
},
66+
"./toString": {
67+
"import": "./src/to-string.js"
68+
},
69+
"./xor": {
70+
"import": "./src/xor.js"
71+
}
72+
},
6073
"contributors": [
6174
"achingbrain <[email protected]>",
6275
"Cayman <[email protected]>",

compare.js renamed to src/compare.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
'use strict'
2-
31
/**
42
* Can be used with Array.sort to sort and array with Uint8Array entries
53
*
@@ -28,4 +26,4 @@ function compare (a, b) {
2826
return 0
2927
}
3028

31-
module.exports = compare
29+
export default compare

concat.js renamed to src/concat.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
'use strict'
2-
31
/**
42
* Returns a new Uint8Array created by concatenating the passed ArrayLikes
53
*
@@ -22,4 +20,4 @@ function concat (arrays, length) {
2220
return output
2321
}
2422

25-
module.exports = concat
23+
export default concat

equals.js renamed to src/equals.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
'use strict'
2-
31
/**
42
* Returns true if the two passed Uint8Arrays have the same content
53
*
@@ -24,4 +22,4 @@ function equals (a, b) {
2422
return true
2523
}
2624

27-
module.exports = equals
25+
export default equals

from-string.js renamed to src/from-string.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
'use strict'
2-
3-
const bases = require('./util/bases')
1+
import bases from './util/bases.js'
42

53
/**
64
* @typedef {import('./util/bases').SupportedEncodings} SupportedEncodings
@@ -28,4 +26,4 @@ function fromString (string, encoding = 'utf8') {
2826
return base.decoder.decode(`${base.prefix}${string}`)
2927
}
3028

31-
module.exports = fromString
29+
export default fromString

src/index.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import compare from './compare.js'
2+
import concat from './concat.js'
3+
import equals from './equals.js'
4+
import fromString from './from-string.js'
5+
import toString from './to-string.js'
6+
import xor from './xor.js'
7+
8+
export {
9+
compare,
10+
concat,
11+
equals,
12+
fromString,
13+
toString,
14+
xor
15+
}

to-string.js renamed to src/to-string.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
'use strict'
2-
3-
const bases = require('./util/bases')
1+
import bases from './util/bases.js'
42

53
/**
64
* @typedef {import('./util/bases').SupportedEncodings} SupportedEncodings
@@ -28,4 +26,4 @@ function toString (array, encoding = 'utf8') {
2826
return base.encoder.encode(array).substring(1)
2927
}
3028

31-
module.exports = toString
29+
export default toString

util/bases.js renamed to src/util/bases.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
'use strict'
2-
3-
const { bases } = require('multiformats/basics')
1+
import { bases } from 'multiformats/basics'
42

53
/**
64
* @typedef {import('multiformats/bases/interface').MultibaseCodec<any>} MultibaseCodec
@@ -62,14 +60,14 @@ const ascii = createCodec('ascii', 'a', (buf) => {
6260
* @type {Record<SupportedEncodings, MultibaseCodec>}
6361
*/
6462
const BASES = {
65-
'utf8': string,
63+
utf8: string,
6664
'utf-8': string,
67-
'hex': bases.base16,
68-
'latin1': ascii,
69-
'ascii': ascii,
70-
'binary': ascii,
65+
hex: bases.base16,
66+
latin1: ascii,
67+
ascii: ascii,
68+
binary: ascii,
7169

7270
...bases
7371
}
7472

75-
module.exports = BASES
73+
export default BASES

0 commit comments

Comments
 (0)