update dependencies and devDependencies
[squeep-html-template-helper] / lib / template-helper.js
index 7e1693c857758c127d1063d30804c6c5fab9b2e6..16a14cc4c3d0bdfd42406a03ef29d31f698eddaa 100644 (file)
@@ -4,7 +4,7 @@
  * A bunch of shorthand to put together common parts of an HTML page. 
  */
 
-const { lazy } = require('@squeep/lazy');
+const { lazy } = require('@squeep/lazy-property');
 
 /**
  * Some fields may have values outside normal dates, handle them here.
@@ -29,7 +29,9 @@ const dateOrNot = (date, otherwise) => {
 
 /**
  * Why is rendering a Date as a string this complicated?
- * @param {Date|Number} date
+ * We handle the infinities because pg-promise might provide those in
+ * lieu of a Date object from timestamp fields.
+ * @param {Date|Number|String} date
  * @param {String=} pInf
  * @param {String=} nInf
  * @param {String=} otherwise
@@ -43,6 +45,7 @@ const dateFormat = (date, pInf = 'Never', nInf = 'Forever', otherwise = '') => {
       return nInf;
     default:
       if (!date
+      ||  Number.isNaN(date.valueOf())
       ||  (!(date instanceof Date) && !isDatableType)) {
         return otherwise;
       }
@@ -90,6 +93,17 @@ const secondsToPeriod = (seconds) => {
 };
 
 
+/**
+ * Return array of strings prefixed with tabs.
+ * @param {Number} indent
+ * @param {String[]} list
+ */
+const indented = (indent, list) => {
+  const spacer = '\t'.repeat(indent);
+  return list.map((l) => `${spacer}${l}`);
+};
+
+
 /**
  * Render the preamble <head> for an HTML page.
  * @param {Number} pagePathLevel number of paths below root this page is
@@ -360,6 +374,7 @@ module.exports = {
   htmlHeader,
   htmlFooter,
   htmlMessages,
+  indented,
   renderNavLink,
   LI,
   UL,