feat(Handlebars): formatNumber and group helpers (#31261)

This commit is contained in:
Vitor Avila
2024-12-03 17:55:57 -03:00
committed by GitHub
parent 1e0c04fc15
commit 77f3764fea
4 changed files with 29 additions and 0 deletions

View File

@@ -22,6 +22,7 @@ import moment from 'moment';
import { useMemo, useState } from 'react';
import { isPlainObject } from 'lodash';
import Helpers from 'just-handlebars-helpers';
import HandlebarsGroupBy from 'handlebars-group-by';
export interface HandlebarsViewerProps {
templateSource: string;
@@ -88,4 +89,15 @@ Handlebars.registerHelper('stringify', (obj: any, obj2: any) => {
return isPlainObject(obj) ? JSON.stringify(obj) : String(obj);
});
Handlebars.registerHelper(
'formatNumber',
function (number: any, locale = 'en-US') {
if (typeof number !== 'number') {
return number;
}
return number.toLocaleString(locale);
},
);
Helpers.registerHelpers(Handlebars);
HandlebarsGroupBy.register(Handlebars);