This repository has been archived by the owner on Aug 24, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
feat: add ts types #72
Merged
+171
−111
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
f7bdf4d
feat: add ts types
hugomrdias 74474d5
chore: ci cache
hugomrdias a00ac84
chore: remove ci cache
hugomrdias 5c5ca78
Update README.md
hugomrdias da6788a
fix: feedback
hugomrdias 55a9896
fix: update aegir
hugomrdias 67eb62c
fix: add types
hugomrdias 9d407d2
fix: type versions
hugomrdias 5c7b497
fix: typeversions
hugomrdias 280b133
fix: aegir
hugomrdias File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,8 @@ jobs: | |
- uses: actions/checkout@v2 | ||
- run: yarn | ||
- run: yarn lint | ||
- run: yarn build | ||
- uses: gozala/[email protected] | ||
- run: yarn aegir dep-check -- -i aegir | ||
- uses: ipfs/aegir/actions/bundle-size@master | ||
name: size | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,18 +35,27 @@ | |
}, | ||
"dependencies": { | ||
"@multiformats/base-x": "^4.0.1", | ||
"web-encoding": "^1.0.2" | ||
"web-encoding": "^1.0.4" | ||
}, | ||
"devDependencies": { | ||
"aegir": "^26.0.0", | ||
"aegir": "^29.0.1", | ||
"benchmark": "^2.1.4" | ||
}, | ||
"engines": { | ||
"node": ">=10.0.0", | ||
"npm": ">=6.0.0" | ||
}, | ||
"eslintConfig": { | ||
"extends": "./node_modules/aegir/src/config/eslintrc.js" | ||
"extends": "ipfs" | ||
}, | ||
"types": "dist/src/index.d.ts", | ||
"typesVersions": { | ||
"*": { | ||
"src/*": [ | ||
"dist/src/*", | ||
"dist/src/*/index" | ||
] | ||
} | ||
}, | ||
"contributors": [ | ||
"David Dias <[email protected]>", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,36 @@ | ||
// @ts-check | ||
'use strict' | ||
|
||
const { encodeText } = require('./util') | ||
|
||
/** @typedef {import('./types').CodecFactory} CodecFactory */ | ||
/** @typedef {import("./types").BaseName} BaseName */ | ||
/** @typedef {import("./types").BaseCode} BaseCode */ | ||
|
||
/** | ||
* @typedef {Object} Codec | ||
* @property {function(Uint8Array):string} encode | ||
* @property {function(string):Uint8Array} decode | ||
* Class to encode/decode in the supported Bases | ||
* | ||
* @typedef {function(string):Codec} CodecFactory | ||
*/ | ||
|
||
class Base { | ||
/** | ||
* @param {string} name | ||
* @param {string} code | ||
* @param {CodecFactory} implementation | ||
* @param {BaseName} name | ||
* @param {BaseCode} code | ||
* @param {CodecFactory} factory | ||
* @param {string} alphabet | ||
*/ | ||
constructor (name, code, implementation, alphabet) { | ||
constructor (name, code, factory, alphabet) { | ||
this.name = name | ||
this.code = code | ||
this.codeBuf = encodeText(this.code) | ||
this.alphabet = alphabet | ||
this.engine = implementation(alphabet) | ||
this.codec = factory(alphabet) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💭If this / other properties are not supposed to be touched might be worth adding |
||
} | ||
|
||
/** | ||
* @param {Uint8Array} buf | ||
* @returns {string} | ||
*/ | ||
encode (buf) { | ||
return this.engine.encode(buf) | ||
return this.codec.encode(buf) | ||
} | ||
|
||
/** | ||
|
@@ -44,7 +43,7 @@ class Base { | |
throw new Error(`invalid character '${char}' in '${string}'`) | ||
} | ||
} | ||
return this.engine.decode(string) | ||
return this.codec.decode(string) | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💭 Maybe we do not need the whole section just for the link ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestions ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don’t know maybe API Docs badge at the top ?