From 9f7ce6557af2f90a8780742dd8275f050b863e4e Mon Sep 17 00:00:00 2001 From: Luke Nagy Date: Tue, 24 Jul 2018 13:47:43 +0800 Subject: [PATCH] Improve screaming snake case regex so as to recognise acronyms e.g. setVIPById as SET_VIP_BY_ID rather than SET_V_I_P_BY_ID. --- lib/createActions.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/createActions.js b/lib/createActions.js index 64bcb2f..15542af 100644 --- a/lib/createActions.js +++ b/lib/createActions.js @@ -5,8 +5,9 @@ const defaultOptions = { prefix: '' } -// matches on capital letters (except at the start & end of the string) -const RX_CAPS = /(?!^)([A-Z])/g +// matches each word in a camelCaseString (except the first) +// consecutive capitals are treated as one word +const RX_CAPS = /(?!^)([A-Z][a-z]+|[A-Z]+(?=[A-Z]|\b))/g // converts a camelCaseWord into a SCREAMING_SNAKE_CASE word const camelToScreamingSnake = pipe(