// Helper functions var crypto = require('crypto'); // sha256 hex-hashes password with supplied salt. // Returns hex-hash string exports.hashPassword = function(password, salt) { var hash = crypto.createHash('sha256'); hash.update(password); hash.update(salt); return hash.digest('hex'); } // Convert date() to epoch exports.dateToEpoch = function(date) { return Math.floor(date); }; // Convert epoch (in seconds) to date string exports.epochToDateString = function(epoch) { var date = new Date(epoch); return date.toLocaleString(); }; // Convert epoch to an ISO formatted date. exports.epochToShortDateString = function(epoch) { var date = new Date(epoch); return date.toISOString().slice(0,10); } // Build a slug from a title string // Returns the slug as a string exports.makeSlug = function(str) { str = str.replace(/^\s+|\s+$/g, ''); // trim str = str.toLowerCase(); str = str.trim(); // remove accents, swap ñ for n, etc var from = "àáäâèéëêìíïîòóöôùúüûñç·/_,:;&"; var to = "aaaaeeeeiiiioooouuuunc-------"; for (var i=0, l=from.length ; i