2024-02-21 19:40:50 +01:00
|
|
|
import { date, duration } from "./date"
|
2022-07-28 21:20:53 +02:00
|
|
|
|
2024-02-02 12:02:09 +01:00
|
|
|
// https://github.com/evanw/esbuild/issues/56
|
2024-02-21 22:35:30 +01:00
|
|
|
const getExternalCollections = (): Record<string, () => any> => ({
|
2024-02-02 12:02:09 +01:00
|
|
|
math: require("@budibase/handlebars-helpers/lib/math"),
|
|
|
|
array: require("@budibase/handlebars-helpers/lib/array"),
|
|
|
|
number: require("@budibase/handlebars-helpers/lib/number"),
|
|
|
|
url: require("@budibase/handlebars-helpers/lib/url"),
|
|
|
|
string: require("@budibase/handlebars-helpers/lib/string"),
|
|
|
|
comparison: require("@budibase/handlebars-helpers/lib/comparison"),
|
|
|
|
object: require("@budibase/handlebars-helpers/lib/object"),
|
|
|
|
regex: require("@budibase/handlebars-helpers/lib/regex"),
|
|
|
|
uuid: require("@budibase/handlebars-helpers/lib/uuid"),
|
2024-02-21 22:35:30 +01:00
|
|
|
})
|
2023-12-19 18:46:15 +01:00
|
|
|
|
2024-02-21 19:40:50 +01:00
|
|
|
export const helpersToRemoveForJs = ["sortBy"]
|
2024-01-30 16:52:25 +01:00
|
|
|
|
2024-02-02 12:02:09 +01:00
|
|
|
const addedHelpers = {
|
|
|
|
date: date,
|
|
|
|
duration: duration,
|
|
|
|
}
|
|
|
|
|
2024-03-15 10:18:47 +01:00
|
|
|
let helpers: Record<string, any>
|
2024-02-02 12:02:09 +01:00
|
|
|
|
2024-02-21 19:40:50 +01:00
|
|
|
export function getJsHelperList() {
|
2023-12-19 18:46:15 +01:00
|
|
|
if (helpers) {
|
|
|
|
return helpers
|
|
|
|
}
|
|
|
|
|
|
|
|
helpers = {}
|
2024-02-21 22:35:30 +01:00
|
|
|
for (let collection of Object.values(getExternalCollections())) {
|
2022-07-28 21:20:53 +02:00
|
|
|
for (let [key, func] of Object.entries(collection)) {
|
2024-01-25 19:48:34 +01:00
|
|
|
// Handlebars injects the hbs options to the helpers by default. We are adding an empty {} as a last parameter to simulate it
|
2024-03-15 09:35:38 +01:00
|
|
|
helpers[key] = (...props: any) => func(...props, {})
|
2022-07-28 21:20:53 +02:00
|
|
|
}
|
|
|
|
}
|
2024-03-15 09:35:38 +01:00
|
|
|
helpers = {
|
|
|
|
...helpers,
|
|
|
|
addedHelpers,
|
2022-07-28 21:20:53 +02:00
|
|
|
}
|
2024-01-25 17:24:47 +01:00
|
|
|
|
2024-01-31 10:34:49 +01:00
|
|
|
for (const toRemove of helpersToRemoveForJs) {
|
2024-01-30 16:52:25 +01:00
|
|
|
delete helpers[toRemove]
|
|
|
|
}
|
2023-12-19 18:46:15 +01:00
|
|
|
Object.freeze(helpers)
|
|
|
|
return helpers
|
2022-07-28 21:20:53 +02:00
|
|
|
}
|