-let rootPath: string
-
-function root () {
- if (rootPath) return rootPath
-
- // We are in /helpers/utils.js
- rootPath = join(__dirname, '..', '..')
-
- if (basename(rootPath) === 'dist') rootPath = resolve(rootPath, '..')
-
- return rootPath
-}
-
-// Thanks: https://stackoverflow.com/a/12034334
-function escapeHTML (stringParam) {
- if (!stringParam) return ''
-
- const entityMap = {
- '&': '&',
- '<': '<',
- '>': '>',
- '"': '"',
- '\'': ''',
- '/': '/',
- '`': '`',
- '=': '='
- }
-
- return String(stringParam).replace(/[&<>"'`=/]/g, s => entityMap[s])
-}
-
-function pageToStartAndCount (page: number, itemsPerPage: number) {
- const start = (page - 1) * itemsPerPage
-
- return { start, count: itemsPerPage }
-}
-
-function mapToJSON (map: Map<any, any>) {
- const obj: any = {}
-
- for (const [ k, v ] of map) {
- obj[k] = v
- }
-
- return obj
-}
-
-function buildPath (path: string) {
- if (isAbsolute(path)) return path
-
- return join(root(), path)
-}