mirror of
https://github.com/apache/superset.git
synced 2026-04-19 08:04:53 +00:00
feat(Handlebars): formatNumber and group helpers (#31261)
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user