Skip to content

Commit 9d24b62

Browse files
achingbrainrvagg
authored andcommitted
chore: fix linting
1 parent a0fdb76 commit 9d24b62

File tree

8 files changed

+51
-28
lines changed

8 files changed

+51
-28
lines changed

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# multiformats
2+
13
[![multiformats.io](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://multiformats.io)
24
[![codecov](https://img.shields.io/codecov/c/github/multiformats/js-multiformats.svg?style=flat-square)](https://codecov.io/gh/multiformats/js-multiformats)
35
[![CI](https://img.shields.io/github/actions/workflow/status/multiformats/js-multiformats/js-test-and-release.yml?branch=master\&style=flat-square)](https://github.com/multiformats/js-multiformats/actions/workflows/js-test-and-release.yml?query=branch%3Amaster)
@@ -212,7 +214,7 @@ $ npm i multiformats
212214

213215
## Browser `<script>` tag
214216

215-
Loading this module through a script tag will make it's exports available as `Multiformats` in the global namespace.
217+
Loading this module through a script tag will make its exports available as `Multiformats` in the global namespace.
216218

217219
```html
218220
<script src="https://unpkg.com/multiformats/dist/index.min.js"></script>
@@ -226,8 +228,8 @@ Loading this module through a script tag will make it's exports available as `Mu
226228

227229
Licensed under either of
228230

229-
- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)
230-
- MIT ([LICENSE-MIT](LICENSE-MIT) / <http://opensource.org/licenses/MIT>)
231+
- Apache 2.0, ([LICENSE-APACHE](https://github.com/multiformats/js-multiformats/LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)
232+
- MIT ([LICENSE-MIT](https://github.com/multiformats/js-multiformats/LICENSE-MIT) / <http://opensource.org/licenses/MIT>)
231233

232234
# Contribution
233235

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
"bugs": {
1313
"url": "https://github.com/multiformats/js-multiformats/issues"
1414
},
15+
"publishConfig": {
16+
"access": "public",
17+
"provenance": true
18+
},
1519
"keywords": [
1620
"ipfs",
1721
"ipld",

src/bases/base.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,12 @@ class Decoder<Base extends string, Prefix extends string> implements MultibaseDe
4444
constructor (name: Base, prefix: Prefix, baseDecode: DecodeFn) {
4545
this.name = name
4646
this.prefix = prefix
47+
const prefixCodePoint = prefix.codePointAt(0)
4748
/* c8 ignore next 3 */
48-
if (prefix.codePointAt(0) === undefined) {
49+
if (prefixCodePoint === undefined) {
4950
throw new Error('Invalid prefix character')
5051
}
51-
this.prefixCodePoint = prefix.codePointAt(0) as number
52+
this.prefixCodePoint = prefixCodePoint
5253
this.baseDecode = baseDecode
5354
}
5455

src/bases/base256emoji.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,14 @@ import { from } from './base.js'
22

33
const alphabet = Array.from('🚀🪐☄🛰🌌🌑🌒🌓🌔🌕🌖🌗🌘🌍🌏🌎🐉☀💻🖥💾💿😂❤😍🤣😊🙏💕😭😘👍😅👏😁🔥🥰💔💖💙😢🤔😆🙄💪😉☺👌🤗💜😔😎😇🌹🤦🎉💞✌✨🤷😱😌🌸🙌😋💗💚😏💛🙂💓🤩😄😀🖤😃💯🙈👇🎶😒🤭❣😜💋👀😪😑💥🙋😞😩😡🤪👊🥳😥🤤👉💃😳✋😚😝😴🌟😬🙃🍀🌷😻😓⭐✅🥺🌈😈🤘💦✔😣🏃💐☹🎊💘😠☝😕🌺🎂🌻😐🖕💝🙊😹🗣💫💀👑🎵🤞😛🔴😤🌼😫⚽🤙☕🏆🤫👈😮🙆🍻🍃🐶💁😲🌿🧡🎁⚡🌞🎈❌✊👋😰🤨😶🤝🚶💰🍓💢🤟🙁🚨💨🤬✈🎀🍺🤓😙💟🌱😖👶🥴▶➡❓💎💸⬇😨🌚🦋😷🕺⚠🙅😟😵👎🤲🤠🤧📌🔵💅🧐🐾🍒😗🤑🌊🤯🐷☎💧😯💆👆🎤🙇🍑❄🌴💣🐸💌📍🥀🤢👅💡💩👐📸👻🤐🤮🎼🥵🚩🍎🍊👼💍📣🥂')
44
const alphabetBytesToChars: string[] = (alphabet.reduce<string[]>((p, c, i) => { p[i] = c; return p }, ([])))
5-
const alphabetCharsToBytes: number[] = (alphabet.reduce<number[]>((p, c, i) => { p[c.codePointAt(0) as number] = i; return p }, ([])))
5+
const alphabetCharsToBytes: number[] = (alphabet.reduce<number[]>((p, c, i) => {
6+
const codePoint = c.codePointAt(0)
7+
if (codePoint == null) {
8+
throw new Error(`Invalid character: ${c}`)
9+
}
10+
p[codePoint] = i
11+
return p
12+
}, ([])))
613

714
function encode (data: Uint8Array): string {
815
return data.reduce((p, c) => {
@@ -14,8 +21,12 @@ function encode (data: Uint8Array): string {
1421
function decode (str: string): Uint8Array {
1522
const byts = []
1623
for (const char of str) {
17-
const byt = alphabetCharsToBytes[char.codePointAt(0) as number]
18-
if (byt === undefined) {
24+
const codePoint = char.codePointAt(0)
25+
if (codePoint == null) {
26+
throw new Error(`Invalid character: ${char}`)
27+
}
28+
const byt = alphabetCharsToBytes[codePoint]
29+
if (byt == null) {
1930
throw new Error(`Non-base256emoji character: ${char}`)
2031
}
2132
byts.push(byt)

src/block.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ type CreateUnsafeInput <T, Code extends number, Alg extends number, V extends AP
195195
* @template V - CID version
196196
*/
197197
export function createUnsafe <T, Code extends number, Alg extends number, V extends API.Version> ({ bytes, cid, value: maybeValue, codec }: CreateUnsafeInput<T, Code, Alg, V>): API.BlockView<T, Code, Alg, V> {
198+
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
198199
const value = maybeValue !== undefined
199200
? maybeValue
200201
: (codec?.decode(bytes))

test/test-cid.spec.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/* globals describe, it */
2+
/* eslint-disable @typescript-eslint/strict-boolean-expressions */
23

34
import { assert } from 'aegir/chai'
45
import OLDCID from 'cids'
@@ -105,8 +106,8 @@ describe('CID', () => {
105106
it('should construct from an old CID', () => {
106107
const cidStr = 'QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n'
107108
const oldCid = CID.parse(cidStr)
108-
const newCid = (CID.asCID(oldCid) as CID)
109-
assert.deepStrictEqual(newCid.toString(), cidStr)
109+
const newCid = CID.asCID(oldCid)
110+
assert.deepStrictEqual(newCid?.toString(), cidStr)
110111
})
111112

112113
it('inspect bytes', () => {
@@ -226,8 +227,8 @@ describe('CID', () => {
226227
const cidStr =
227228
'bafybeidskjjd4zmr7oh6ku6wp72vvbxyibcli2r6if3ocdcy7jjjusvl2u'
228229
const oldCid = CID.parse(cidStr)
229-
const newCid = (CID.asCID(oldCid) as CID)
230-
assert.deepStrictEqual(newCid.toString(), cidStr)
230+
const newCid = CID.asCID(oldCid)
231+
assert.deepStrictEqual(newCid?.toString(), cidStr)
231232
})
232233

233234
it('.link() should return this CID', () => {
@@ -516,7 +517,7 @@ describe('CID', () => {
516517
// @ts-expect-error - no such method
517518
assert.strictEqual(typeof incompatibleCID.toV0, 'undefined')
518519

519-
const cid1 = (CID.asCID(incompatibleCID) as CID)
520+
const cid1 = CID.asCID(incompatibleCID)
520521
assert.ok(cid1 instanceof CID)
521522
assert.strictEqual(cid1.code, code)
522523
assert.strictEqual(cid1.version, version)
@@ -538,7 +539,7 @@ describe('CID', () => {
538539
assert.strictEqual(cid3, cid4)
539540

540541
const cid5 = (
541-
CID.asCID(new OLDCID(1, 'raw', Uint8Array.from(hash.bytes))) as CID
542+
CID.asCID(new OLDCID(1, 'raw', Uint8Array.from(hash.bytes)))
542543
)
543544
assert.ok(cid5 instanceof CID)
544545
assert.strictEqual(cid5.version, 1)
@@ -557,7 +558,9 @@ describe('CID', () => {
557558
assert.deepStrictEqual({ ...x, ...empty }, { ...y, ...empty })
558559
}
559560

560-
const equalDigest = (x: MultihashDigest, y: MultihashDigest): void => {
561+
const equalDigest = (x?: MultihashDigest, y?: MultihashDigest): void => {
562+
assert.ok(x)
563+
assert.ok(y)
561564
assert.deepStrictEqual(x.digest, y.digest)
562565
assert.deepStrictEqual(x.code, y.code)
563566
assert.deepStrictEqual(x.digest, y.digest)
@@ -662,12 +665,12 @@ describe('CID', () => {
662665
it('new CID from old CID', async () => {
663666
const hash = await sha256.digest(textEncoder.encode('abc'))
664667
const cid = (
665-
CID.asCID(new OLDCID(1, 'raw', Uint8Array.from(hash.bytes))) as CID
668+
CID.asCID(new OLDCID(1, 'raw', Uint8Array.from(hash.bytes)))
666669
)
667-
assert.deepStrictEqual(cid.version, 1)
670+
assert.deepStrictEqual(cid?.version, 1)
668671

669-
equalDigest(cid.multihash, hash)
670-
assert.deepStrictEqual(cid.code, 85)
672+
equalDigest(cid?.multihash, hash)
673+
assert.deepStrictEqual(cid?.code, 85)
671674
})
672675

673676
it('util.inspect', async () => {

test/test-link.spec.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/* globals describe, it */
2+
/* eslint-disable @typescript-eslint/strict-boolean-expressions */
23

34
import { assert } from 'aegir/chai'
45
import { sha256 } from '../src/hashes/sha2.js'
@@ -25,10 +26,10 @@ describe('Link', () => {
2526
it('create v1', async () => {
2627
const hash = await sha256.digest(utf8.encode('abc'))
2728
const link = Link.create(0x71, hash)
28-
const code = link.code as 0x71
29+
const code = link.code
2930
assert.deepStrictEqual(code, 0x71)
3031

31-
const version = link.version as 1
32+
const version = link.version
3233
assert.deepEqual(version, 1)
3334

3435
const multihash = link.multihash
@@ -39,10 +40,10 @@ describe('Link', () => {
3940
const hash = await sha256.digest(utf8.encode('abc'))
4041
const link = Link.createLegacy(hash)
4142

42-
const code = link.code as 0x70
43+
const code = link.code
4344
assert.deepStrictEqual(code, 0x70)
4445

45-
const version = link.version as 0
46+
const version = link.version
4647
assert.deepEqual(version, 0)
4748

4849
const multihash = link.multihash
@@ -72,7 +73,7 @@ describe('Link', () => {
7273
const t1 = link
7374
assert.ok(t1)
7475

75-
// ensurate that you can't cast incorrectly
76+
// ensure that you can't cast incorrectly
7677
const t2 =
7778
// @ts-expect-error - version is 1 not 0
7879
(link as Link.Link<unknown, typeof CBOR, typeof SHA256, 0>)
@@ -124,10 +125,10 @@ describe('decode', () => {
124125

125126
const link = Link.decode(bytes)
126127

127-
const code = link.code as 0x71
128+
const code = link.code
128129
assert.deepStrictEqual(code, 0x71)
129130

130-
const version = link.version as 1
131+
const version = link.version
131132
assert.deepEqual(version, 1)
132133

133134
const multihash = link.multihash

test/test-multibase.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,12 @@ describe('multibase', () => {
159159
})
160160

161161
it('infers prefix and name corretly', () => {
162-
const name = base32.name as 'base32'
162+
const name = base32.name
163163

164164
// @ts-expect-error - TS catches mismatch
165165
const name2: 'base16' = base32.name
166166

167-
const prefix = base32.prefix as 'b'
167+
const prefix = base32.prefix
168168
assert.equal(prefix, 'b')
169169
assert.equal(name, 'base32')
170170
assert.equal(name2, name)

0 commit comments

Comments
 (0)