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
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 29 additions and 0 deletions

View File

@ -28030,6 +28030,14 @@
"uglify-js": "^3.1.4"
}
},
"node_modules/handlebars-group-by": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/handlebars-group-by/-/handlebars-group-by-1.0.1.tgz",
"integrity": "sha512-qwVVDVAJMBKdmnQU8jcEXGOu+4/2YJX1RP3pUw6Ee9t6gdkxt+dJEWDudSFTgqb35KXrktw/Nn/Dp3Rx5muHpg==",
"engines": {
"node": ">= 0.10"
}
},
"node_modules/handlebars/node_modules/source-map": {
"version": "0.6.1",
"license": "BSD-3-Clause",
@ -58569,6 +58577,7 @@
"license": "Apache-2.0",
"dependencies": {
"handlebars": "^4.7.8",
"handlebars-group-by": "^1.0.1",
"just-handlebars-helpers": "^1.0.19"
},
"devDependencies": {
@ -69180,6 +69189,7 @@
"@types/jest": "^29.5.12",
"@types/lodash": "^4.17.7",
"handlebars": "^4.7.8",
"handlebars-group-by": "*",
"jest": "^29.7.0",
"just-handlebars-helpers": "^1.0.19"
},
@ -79832,6 +79842,11 @@
}
}
},
"handlebars-group-by": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/handlebars-group-by/-/handlebars-group-by-1.0.1.tgz",
"integrity": "sha512-qwVVDVAJMBKdmnQU8jcEXGOu+4/2YJX1RP3pUw6Ee9t6gdkxt+dJEWDudSFTgqb35KXrktw/Nn/Dp3Rx5muHpg=="
},
"har-schema": {
"version": "2.0.0",
"dev": true

View File

@ -28,6 +28,7 @@
},
"dependencies": {
"handlebars": "^4.7.8",
"handlebars-group-by": "^1.0.1",
"just-handlebars-helpers": "^1.0.19"
},
"peerDependencies": {

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);

View File

@ -22,3 +22,4 @@ declare module '*.png' {
}
declare module '*.jpg';
declare module 'just-handlebars-helpers';
declare module 'handlebars-group-by';