text: const moment = require('moment')
  
  module.exports = {
    formatDate: function (date, format) {
      return moment(date).utc().format(format)
    },
    truncate: function (str, len) {
      if (str.length > len && str.length > 0) {
        let new_str = str + ' '
        new_str = str.substr(0, len)
        new_str = str.substr(0, new_str.lastIndexOf(' '))
        new_str = new_str.length > 0 ? new_str : str.substr(0, len)
        return new_str + '...'
      }
      return str
    },
    stripTags: function (input) {
      return input.replace(/<(?:.|\n)*?>/gm, '')
    },
    editIcon: function (courseworkUser, loggedUser, courseworkID, floating = true) {
      if (courseworkUser._id.toString() == loggedUser._id.toString()) {
        if (floating) {
          return `<a href="/courseworks/edit/${courseworkID}" class="btn-flat"><i class="small material-icons">edit</i></a>`
        } else {
          return `<a href="/courseworks/edit/${courseworkID}"><i class="small material-icons">edit</i></a>`
        }
      } else {
        return ''
      }
    },
    select: function (selected, options) {
      return options
        .fn(this)
        .replace(
          new RegExp(' value="' + selected + '"'),
          '$& selected="selected"'
        )
        .replace(
          new RegExp('>' + selected + '</option>'),
          ' selected="selected"$&'
        )
    },
  }