engagementgamelab/CivicSeed

View on GitHub
server/utils/misc.js

Summary

Maintainability
A
0 mins
Test Coverage
'use strict'

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

    server.utils.misc

    - Miscellaneous helper functions

 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

module.exports = (function () {
  return {
    // Given an arbitrary filename, get its extension
    getFilenameExtension: function (filename) {
      var parts = filename.split('.')
      // Catch cases where there is no extension, or if the extension is the
      // entire filename (e.g. '.htaccess')
      if (parts.length === 1 || (parts[0] === '' && parts.length === 2)) {
        return ''
      }
      return parts.pop()
    }
  }
}())