syavorsky / comment-parser

Generic JSDoc-like comment parser.
MIT License
238 stars 23 forks source link

feat: { spacing: 'dedent' } #146

Open bennypowers opened 2 years ago

bennypowers commented 2 years ago

Let's give users a middle ground between 'compact' and 'preserve':

/**
 * @fires {CustomEvent<{ component: PfeClipboard }>} copied
 *        Fires when the current url is successfully copied the user's system clipboard.
 *
 *        ```js
 *        detail: {
 *          url: string
 *        }
 *        ```
 *
 */
console.log(parse(comment, { spacing: 'dedent' }.tags[0].description)
Fires when the current url is successfully copied the user's system clipboard.

```js
detail: {
  url: string
}


this shouldn't be hard to implement, it's basically:
1. get the value if spacing was 'preserve'
2. run `dedent` from 'dedent' npm package on the result

If the maintainers wish, I'm happy to make a PR
syavorsky commented 2 years ago

@bennypowers that is definitely a reasonable suggestion. There is an alternative, more flexible approach though. The spacing option was intentionally kept limited to avoid complexity. But all the variation one may need can be done as in this example. PR for the dedent transform would be very much welcome