Skip to content

Commit

Permalink
refactor: tweaks condition for valid component name
Browse files Browse the repository at this point in the history
  • Loading branch information
usualoma committed May 4, 2024
1 parent 8597e66 commit 2078c4e
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/vite/island-components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,20 @@ import { parse as parseJsonc } from 'jsonc-parser'
// eslint-disable-next-line node/no-extraneous-import
import type { Plugin } from 'vite'

/**
* Check if the name is a valid component name
*
* @param name - The name to check
* @returns true if the name is a valid component name
* @example
* isComponentName('Badge') // true
* isComponentName('BadgeComponent') // true
* isComponentName('badge') // false
* isComponentName('MIN') // false
* isComponentName('Badge_Component') // false
*/
function isComponentName(name: string) {
return /^[A-Z]/.test(name) && /[a-z]/.test(name)
return /^[A-Z][A-Za-z0-9]*[a-z][A-Za-z0-9]*$/.test(name)
}

function addSSRCheck(funcName: string, componentName: string, componentExport?: string) {
Expand Down

0 comments on commit 2078c4e

Please sign in to comment.