From baafb6d2f9dc350ee2ea571ff5ec5c0fa6fac8b8 Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Thu, 13 Mar 2025 14:54:45 +1300 Subject: [PATCH] Tweak camelcase function --- shared/naturalcrit/markdown.js | 4 +++- tests/markdown/variables.test.js | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/shared/naturalcrit/markdown.js b/shared/naturalcrit/markdown.js index fda410c36..f8b79e286 100644 --- a/shared/naturalcrit/markdown.js +++ b/shared/naturalcrit/markdown.js @@ -98,7 +98,9 @@ mathParser.functions.toWordsLower = function (a) { mathParser.functions.toWordsCamel = function (a) { const words = mathParser.functions.toWords(a).split(' '); return words.map((word)=>{ - return _.capitalize(word); + return word.replace(/(?:^|\b|\s)(\w)/g, function(w, index) { + return index === 0 ? w.toLowerCase() : w.toUpperCase(); + }); }).join(' '); }; diff --git a/tests/markdown/variables.test.js b/tests/markdown/variables.test.js index 96400d834..8c58f4925 100644 --- a/tests/markdown/variables.test.js +++ b/tests/markdown/variables.test.js @@ -482,6 +482,6 @@ describe('Custom Math Function Tests', ()=>{ it('Number to Words Test - Camelcase', function() { const source = `[a]: 80085\n\nWords: $[toWordsCamel(a)]`; const rendered = Markdown.render(source).trimReturns(); - expect(rendered).toBe('

Words: Eighty Thousand And Eighty-five

'); + expect(rendered).toBe('

Words: Eighty Thousand And Eighty-Five

'); }); }); \ No newline at end of file