https://github.com/julien-r44/module-methods-extractor
🪛 Utility module to extract public methods for a given default export.
https://github.com/julien-r44/module-methods-extractor
Last synced: 10 months ago
JSON representation
🪛 Utility module to extract public methods for a given default export.
- Host: GitHub
- URL: https://github.com/julien-r44/module-methods-extractor
- Owner: Julien-R44
- License: mit
- Created: 2022-08-29T22:48:27.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-08-29T23:08:09.000Z (over 3 years ago)
- Last Synced: 2024-05-01T15:26:02.681Z (almost 2 years ago)
- Language: TypeScript
- Size: 83 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE.md
Awesome Lists containing this project
README
# @julr/module-methods-extractor
🪛 Utility module to extract public methods for a given default Typescript export. Used by the Adonis.js VSCode extension
## Installation
```bash
pnpm add @julr/module-methods-extractor
```
## Usage
```ts
import { Extractor } from '@julr/module-methods-extractor'
const extractor = new Extractor()
const response = extractor.extract(`
export default class UserController {
public async index () {}
public async store () {}
}
`)
assert.deepEqual(response, {
kind: 'class',
methods: [
{ name: 'index', lineno: 2 },
{ name: 'store', lineno: 5 },
]
})
```
## Features supported
- ESM `export default` is supported.
- Handle inline class declarations like `export default UserController {}`.
- Returns `lineno` for all methods.
- Use `@babel/parser` instead of the Typescript Compiler API to parse the source code. This results in a much lighter dependency ( 274KB instead of 3.32MB)
## Limitations
- Only supports ESM. Commonjs `module.exports` is not supported. ( Maybe later ? )
- The export reference must be located as a top level property. For example:
```ts
const someObject = {
prop: class UserController {}
}
export default someObject.prop
```
The above expression is not something we advocate in the Adonis.js eco-system and also it is not a great pattern to use either.
## Acknowledgements
- [Harminder Virk](https://github.com/thetutlage) for developping the [initial version of this module](https://github.com/poppinss/module-methods-extractor).
## License
[MIT](./LICENSE.md) License © 2022 [Julien Ripouteau](https://github.com/Julien-R44)