@matthiesenxyz/astrodtsbuilder

0.1.2 • Public • Published

Build a declaration file for Astro Integrations

This utility function is used to build a declaration file for use with Astro's injectTypes function added in the astro:config:done Integration Hook in Astro 4.14.0. This function is useful for generating TypeScript declaration files for Astro Integrations.

Example Usage

// Import and use the function
import buildDeclarationFile from '@matthiesenxyz/astrodtsbuilder';
const dts = buildDeclarationFile();

// Add a note to the file
dts.addSingleLineNote(`This file was generated by '@my-example/module'`);

// Add a Multi-line Note to the file
dts.addMultiLineNote(['It does some cool and helpful stuff', 'It also does some other cool stuff']);

// Add a module with a default export and single line description
dts.addModule("example:module", {
  defaultExport: {
    typeDef: "import('@my-example/module').ExampleModule",
    singleLineDescription: "This is the default Module",
  }
});

// Write the file
const dtsFile = dts.makeFile();

// Output the file
console.log(dtsFile);

Example Output

// This file was generated by '@my-example/module'

// It does some cool and helpful stuff
// It also does some other cool stuff

declare module 'example:module' {
    //** This is the default Module * /
    const defaultExport: import('@my-example/module').ExampleModule;
    export default defaultExport;

}

Licensing

MIT Licensed. Made with ❤️ by Adam Matthiesen.

Package Sidebar

Install

npm i @matthiesenxyz/astrodtsbuilder

Weekly Downloads

26

Version

0.1.2

License

MIT

Unpacked Size

47.5 kB

Total Files

21

Last publish

Collaborators

  • adammatthiesen