@@ -12,18 +12,44 @@ import { capitalize } from "@alanscodelog/utils"
1212
1313import * as components from "./components/index.js"
1414
15+
16+ /**
17+ * Register only specific components. Will register components as both snake case and pascal case.
18+ *
19+ * ```ts
20+ * import {SomeComponent} from "@alanscodelog/vue-components"
21+ * const components = { SomeComponent }
22+ * createApp(App)
23+ * .use({
24+ * install(app: typeof App) {
25+ * // will register optional-prefix-some-component and optionalPrefixSomeComponent
26+ * // note it doesn't matter what you call the component in the Object
27+ * // its name is set internally already
28+ * registerComponents(app, components, "optional-prefix-")
29+ * },
30+ * })
31+ * ```
32+ */
33+
34+ // eslint-disable-next-line @typescript-eslint/no-shadow
35+ export const registerComponents = ( app : App , components : Record < string , any > , prefix = "" ) : void => {
36+ for ( const key of Object . keys ( components ) ) {
37+ const component = ( components as any ) [ key ]
38+ const name = prefix + component . name
39+ const capitalizedname = name . split ( "-" ) . map ( ( _ : string ) => capitalize ( _ ) ) . join ( "" )
40+ app . component ( name , component )
41+ app . component ( capitalizedname , component )
42+ }
43+ }
44+
1545// eslint-disable-next-line @typescript-eslint/naming-convention
1646export const VueComponentsPlugin : Plugin = {
1747 install ( app : App ) {
18- for ( const componentName of Object . keys ( components ) ) {
19- const component = ( components as any ) [ componentName ]
20- const capitalizedName = component . name . split ( "-" ) . map ( ( _ : string ) => capitalize ( _ ) ) . join ( "" )
21- app . component ( component . name , component )
22- app . component ( capitalizedName , component )
23- }
48+ registerComponents ( app , components )
2449 } ,
2550}
2651
52+
2753type Components = typeof components
2854
2955/**
0 commit comments