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

✨feature: add doc #1986

Merged
merged 16 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ npm-debug.log
test/*.js
test/integration/*.js
!test/ts-node-register.js
docs
100 changes: 96 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"bech32": "^2.0.0",
"bip174": "^2.1.1",
"bs58check": "^3.0.1",
"typedoc-plugin-bitcoinjs-runcase": "^1.0.1",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be a devDependency?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it should me. I remember this but maybe something is wrong!!

I want to tell you about another thing.
I added an executable environment to the document to help us more flexibly display related cases and provide user testing.
The background is as follows

  1. We have a lot of test cases. Moving too many cases will affect the organizational structure of our code, and the workload will be huge.
  2. For related cases, single testing can be combined with the context to understand more, more comprehensively and more efficiently.

To achieve this goal, I did the following things, which also cost me a lot of time:

  1. Build bitcoinjs-lib browser version
  2. Develop typedoc-plugin-bitcoinjs-runcase plug-in to support sneaking into the executable environment
  3. Modify relevant comment tags

You can view the relevant effects here: https://jasonandjay.github.io/bitcoinjs-lib/functions/address.fromBase58Check.html

1
2

I think this is a great feature, but I need your help evaluating whether it's suitable

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That way we can tell the user to test here and find more cases in the single test

Then we only need to give a correct usage method in example (I customized a @case tag), so that the construction efficiency of our document will be much higher

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@junderw please take a look

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jasonandjay typedoc-plugin-bitcoinjs-runcase is a production dependency and has react and react-dom as dependencies. That doesn't belong in bitcoinjs at all.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pajasevi yes, i will change it later, i want to know is this the right direction to add an executable environment to the document to simplify the case in the single test? so as to proceed with the next step.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will take a while to review.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps this should be in a follow up pr

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review typedoc plugin or comments in our repository?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding typedoc-plugin-bitcoinjs-runcase should be in a separate PR is what I'm saying.

"typeforce": "^1.11.3",
"varuint-bitcoin": "^1.1.2"
},
Expand Down
17 changes: 5 additions & 12 deletions ts_src/address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,12 @@ function _toFutureSegwitAddress(output: Buffer, network: Network): string {

/**
* decode address with base58 specification, return address version and address hash if valid
* @example
* @case
* ```ts
* // valid case
* fromBase58Check('1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH')
* // => {version: 0, hash: <Buffer 75 1e 76 e8 19 91 96 d4 54 94 1c 45 d1 b3 a3 23 f1 43 3b d6>}
*
* // invalid case: address is too short
* fromBase58Check('7SeEnXWPaCCALbVrTnszCVGfRU8cGfx')
* // => throw new TypeError('7SeEnXWPaCCALbVrTnszCVGfRU8cGfx is too short')
*
* // invalid case: address is too long
* fromBase58Check('j9ywUkWg2fTQrouxxh5rSZhRvrjMkEUfuiKe')
* // => throw new TypeError('j9ywUkWg2fTQrouxxh5rSZhRvrjMkEUfuiKe is too long')
* // You can test it here and find more case in test/address.spec.ts
* const result = address.fromBase58Check('1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH')
* console.log(JSON.stringify(result))
* // => {"version":0,"hash":{"type":"Buffer","data":[117,30,118,232,25,145,150,212,84,148,28,69,209,179,163,35,241,67,59,214]}}
* ```
*/
export function fromBase58Check(address: string): Base58CheckResult {
Expand Down
1 change: 1 addition & 0 deletions typedoc.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"searchGroupBoosts": {
"Classes": 1.5
},
"plugin": ["typedoc-plugin-bitcoinjs-runcase"],
"visibilityFilters": {},
"hideGenerator": true,
"excludePrivate": true,
Expand Down
Loading