2024-02-21 19:40:50 +01:00
|
|
|
import { date, duration } from "./date"
|
2022-07-28 21:20:53 +02:00
|
|
|
|
2024-03-21 18:41:23 +01:00
|
|
|
/*
|
|
|
|
@budibase/handlebars-helpers is not treeshakeable, so we can't use the barrel files.
|
|
|
|
Otherwise, we have issues when generating the isolated-vm bundle because of the treeshaking
|
|
|
|
*/
|
2024-03-21 17:09:20 +01:00
|
|
|
/* eslint-disable local-rules/no-budibase-imports */
|
2024-03-21 16:10:27 +01:00
|
|
|
// @ts-expect-error
|
|
|
|
import math from "@budibase/handlebars-helpers/lib/math"
|
|
|
|
// @ts-expect-error
|
|
|
|
import array from "@budibase/handlebars-helpers/lib/array"
|
|
|
|
// @ts-expect-error
|
|
|
|
import number from "@budibase/handlebars-helpers/lib/number"
|
|
|
|
// @ts-expect-error
|
|
|
|
import url from "@budibase/handlebars-helpers/lib/url"
|
|
|
|
// @ts-expect-error
|
|
|
|
import string from "@budibase/handlebars-helpers/lib/string"
|
|
|
|
// @ts-expect-error
|
|
|
|
import comparison from "@budibase/handlebars-helpers/lib/comparison"
|
|
|
|
// @ts-expect-error
|
|
|
|
import object from "@budibase/handlebars-helpers/lib/object"
|
|
|
|
// @ts-expect-error
|
|
|
|
import regex from "@budibase/handlebars-helpers/lib/regex"
|
|
|
|
// @ts-expect-error
|
|
|
|
import uuid from "@budibase/handlebars-helpers/lib/uuid"
|
2024-03-21 17:09:20 +01:00
|
|
|
/* eslint-enable local-rules/no-budibase-imports */
|
2024-03-21 11:28:06 +01:00
|
|
|
|
2024-02-02 12:02:09 +01:00
|
|
|
// https://github.com/evanw/esbuild/issues/56
|
2024-03-21 11:28:06 +01:00
|
|
|
const externalCollections = {
|
|
|
|
math,
|
|
|
|
array,
|
|
|
|
number,
|
|
|
|
url,
|
|
|
|
string,
|
|
|
|
comparison,
|
|
|
|
object,
|
|
|
|
regex,
|
|
|
|
uuid,
|
|
|
|
}
|
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-03-21 11:28:06 +01:00
|
|
|
for (let collection of Object.values(externalCollections)) {
|
2024-03-21 16:10:27 +01:00
|
|
|
for (let [key, func] of Object.entries<any>(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,
|
2024-03-21 17:59:07 +01:00
|
|
|
...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
|
|
|
}
|