nymag/byline-nunjucks

View on GitHub
filters/data/typeof.js

Summary

Maintainability
A
35 mins
Test Coverage
'use strict';
// Nunjucks Filter: Return typeof.
module.exports = function (value) {
  // better typeof checking, by Crockford
  var s = typeof value;

  if (s === 'object') {
    if (value) {
      if (value instanceof Array) {
        s = 'array';
      }
    } else {
      s = 'null';
    }
  }
  return s;
};