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

Adding JSDoc support #24

Open
jangxyz opened this issue Dec 21, 2023 · 0 comments
Open

Adding JSDoc support #24

jangxyz opened this issue Dec 21, 2023 · 0 comments

Comments

@jangxyz
Copy link

jangxyz commented Dec 21, 2023

This is related to #6.

If there is a way to add this type information in some extra file that doesn't add any typescript to the existing code then that would be fine.

TypeScript supports JSDoc annotations, so you could actually achieve this.

Some thing like this:

JSDoc code sample
  /**
   * Generate CFI string from node and offset.
   * 
   * @param {Node | { node: Node, offset?: number }[]} node 
   * @param {number} [offset]
   * @param {string} [extra]
   * @returns {string}
   */
  static generate(node, offset, extra) {
    /** @type {string} */
    let cfi;
    
    if (node instanceof Array) {
      let strs = [];
      for (let o of node) {
        strs.push(this.generatePart(o.node, o.offset));
      }
      cfi = strs.join('!');
    } else {
      cfi = this.generatePart(node, offset, extra);
    }

    if (extra) cfi += extra;
    
    return `epubcfi(${cfi})`;
  }

You can generate a .d.ts type generation file so users can have type completion and auto-suggestion benefits.

JSDoc is a bit painful to write than in TypeScript, but it's a perfect harmony for both parties; those who do not want to author in TypeScript & for people who want to have type definition support.

Actually, I have done most of the part, on pursuit of trying to understand the code, except for some confusions on this.from and this.to -- can't really understand which type they are supposed to be.

If you are interested, and help me understand the code a little bit, maybe I can submit a PR for it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant