From f9339c4bb1459c9a9644f861c2ee7efcdcd3221f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8C=E8=B4=A7=E6=9C=BA=E5=99=A8=E4=BA=BA?= Date: Wed, 26 Jul 2023 11:36:57 +0800 Subject: [PATCH] fix: camel case match --- src/Plugin.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Plugin.js b/src/Plugin.js index 8afe921..6c2fed6 100644 --- a/src/Plugin.js +++ b/src/Plugin.js @@ -2,8 +2,11 @@ import { join } from 'path'; import { addSideEffect, addDefault, addNamed } from '@babel/helper-module-imports'; function transCamel(_str, symbol) { - const str = _str[0].toLowerCase() + _str.substr(1); - return str.replace(/([A-Z])/g, $1 => `${symbol}${$1.toLowerCase()}`); + // e.g. QRCode + // First match: QR + // Second match: Code + const cells = _str.match(/([A-Z]+(?=[A-Z]))|([A-Z][^A-Z]+)/g); + return cells.map(c => c.toLowerCase()).join(symbol); } function winPath(path) {