- // We are in /dist/helpers/utils.js
- return join(__dirname, '..', '..', '..')
+ // We are in /helpers/utils.js
+ const paths = [ __dirname, '..', '..' ]
+
+ // We are under /dist directory
+ if (process.mainModule.filename.endsWith('.ts') === false) {
+ paths.push('..')
+ }
+
+ return join.apply(null, paths)
+}
+
+// Thanks: https://stackoverflow.com/a/12034334
+function escapeHTML (stringParam) {
+ 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 }