From 2078c4e90199ba5ee9c6d4dd49ae78a7b0901635 Mon Sep 17 00:00:00 2001 From: Taku Amano Date: Sat, 4 May 2024 21:12:26 +0900 Subject: [PATCH] refactor: tweaks condition for valid component name --- src/vite/island-components.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/vite/island-components.ts b/src/vite/island-components.ts index 098e0c4..9e599fd 100644 --- a/src/vite/island-components.ts +++ b/src/vite/island-components.ts @@ -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) {