mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2025-12-30 21:52:43 +00:00
Tweak camelcase function
This commit is contained in:
@@ -98,7 +98,9 @@ mathParser.functions.toWordsLower = function (a) {
|
|||||||
mathParser.functions.toWordsCamel = function (a) {
|
mathParser.functions.toWordsCamel = function (a) {
|
||||||
const words = mathParser.functions.toWords(a).split(' ');
|
const words = mathParser.functions.toWords(a).split(' ');
|
||||||
return words.map((word)=>{
|
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(' ');
|
}).join(' ');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -482,6 +482,6 @@ describe('Custom Math Function Tests', ()=>{
|
|||||||
it('Number to Words Test - Camelcase', function() {
|
it('Number to Words Test - Camelcase', function() {
|
||||||
const source = `[a]: 80085\n\nWords: $[toWordsCamel(a)]`;
|
const source = `[a]: 80085\n\nWords: $[toWordsCamel(a)]`;
|
||||||
const rendered = Markdown.render(source).trimReturns();
|
const rendered = Markdown.render(source).trimReturns();
|
||||||
expect(rendered).toBe('<p>Words: Eighty Thousand And Eighty-five</p>');
|
expect(rendered).toBe('<p>Words: Eighty Thousand And Eighty-Five</p>');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
Reference in New Issue
Block a user