1+ const DOCS_PLUGIN_RE = / \/ d o c s \/ p l u g i n s \/ ( [ a - z 0 - 9 - ] + ) (? = [ " \\ ] ) / g
2+ const CLIENT_EXPORT_RE = / e x p o r t \s + (?: d e c l a r e \s + ) ? (?: c o n s t | f u n c t i o n ) \s + ( \w + ) / g
3+ const CLIENT_SUFFIX_RE = / C l i e n t $ /
4+ const CAMEL_TO_KEBAB_BOUNDARY_RE = / ( [ a - z 0 - 9 ] ) ( [ A - Z ] ) / g
5+ const CAMEL_TO_KEBAB_ACRONYM_RE = / ( [ A - Z ] + ) ( [ A - Z ] [ a - z 0 - 9 ] + ) / g
6+
17export default defineEventHandler ( async ( ) => {
28 const baseDocsUrl = 'https://www.better-auth.com/docs'
39
410 const html = await fetch ( `${ baseDocsUrl } /introduction` ) . then ( r => r . text ( ) )
511
612 const pluginSlugs = new Set < string > ( )
7- const pluginRe = / \/ d o c s \/ p l u g i n s \/ ( [ a - z 0 - 9 - ] + ) (? = [ " \\ ] ) / g
8- for ( const pluginMatch of html . matchAll ( pluginRe ) ) {
13+ for ( const pluginMatch of html . matchAll ( DOCS_PLUGIN_RE ) ) {
914 if ( pluginMatch [ 1 ] )
1015 pluginSlugs . add ( pluginMatch [ 1 ] )
1116 }
@@ -14,25 +19,24 @@ export default defineEventHandler(async () => {
1419 const dts = await fetch ( clientDtsUrl ) . then ( r => r . text ( ) )
1520
1621 const exportNames = new Set < string > ( )
17- const exportRe = / e x p o r t \s + (?: d e c l a r e \s + ) ? (?: c o n s t | f u n c t i o n ) \s + ( \w + ) / g
18- for ( const exportMatch of dts . matchAll ( exportRe ) ) {
22+ for ( const exportMatch of dts . matchAll ( CLIENT_EXPORT_RE ) ) {
1923 const name = exportMatch [ 1 ]
2024 if ( name )
2125 exportNames . add ( name )
2226 }
2327
2428 const clientPluginNames = Array . from ( exportNames )
25- . filter ( name => name . endsWith ( 'Client' ) )
29+ . filter ( name => CLIENT_SUFFIX_RE . test ( name ) )
2630 . sort ( ( a , b ) => a . localeCompare ( b ) )
2731
2832 const camelToKebab = ( input : string ) =>
2933 input
30- . replace ( / ( [ a - z 0 - 9 ] ) ( [ A - Z ] ) / g , '$1-$2' )
31- . replace ( / ( [ A - Z ] + ) ( [ A - Z ] [ a - z 0 - 9 ] + ) / g , '$1-$2' )
34+ . replace ( CAMEL_TO_KEBAB_BOUNDARY_RE , '$1-$2' )
35+ . replace ( CAMEL_TO_KEBAB_ACRONYM_RE , '$1-$2' )
3236 . toLowerCase ( )
3337
3438 const toSlug = ( clientExport : string ) => {
35- const base = clientExport . replace ( / C l i e n t $ / , '' )
39+ const base = clientExport . replace ( CLIENT_SUFFIX_RE , '' )
3640 const candidate = camelToKebab ( base )
3741 const overrides : Record < string , string > = {
3842 'two-factor' : '2fa' ,
0 commit comments