Code coverage report for nodash/lib/type.js

Statements: 100% (28 / 28)      Branches: 100% (20 / 20)      Functions: 100% (16 / 16)      Lines: 100% (28 / 28)      Ignored: none     

All files » nodash/lib/ » type.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93      1   5   5   1 946 946     5         1321 1321   60   946 946 449   497   315         577       16       29       304       639       4       2       2       1       1       248         14       17                
/* vim: set et sw=2 ts=2: */
'use strict';
 
module.exports = function () {
 
  var Nodash = this;
 
  var toString = Object.prototype.toString;
 
  function classOf(thing) {
    var exactType = toString.call(thing);
    return exactType.slice(8, exactType.length - 1).toLowerCase();
  }
 
  return {
 
    classOf: classOf,
 
    typeOf: function (thing) {
      var type = typeof thing;
      switch (type) {
        case 'number':
          return isNaN(thing) ? 'not-a-number' : 'number';
        case 'object':
          var exactType = classOf(thing);
          if (exactType === 'object' && thing.constructor && thing.constructor.__type) {
            return thing.constructor.__type;
          }
          return exactType;
        default:
          return type;
      }
    },
 
    is: function (type, thing) {
      return thing instanceof type;
    },
 
    isBoolean: function (thing) {
      return typeof thing === 'boolean';
    },
 
    isNumber: function (thing) {
      return typeof thing === 'number';
    },
 
    isString: function (thing) {
      return typeof thing === 'string' || toString.call(thing) === '[object String]';
    },
 
    isFunction: function (thing) {
      return typeof thing === 'function';
    },
 
    isUndefined: function (thing) {
      return typeof thing === 'undefined';
    },
 
    isRegExp: function (thing) {
      return toString.call(thing) === '[object RegExp]';
    },
 
    isDate: function (thing) {
      return toString.call(thing) === '[object Date]';
    },
 
    isNull: function (thing) {
      return toString.call(thing) === '[object Null]';
    },
 
    isArguments: function (thing) {
      return toString.call(thing) === '[object Arguments]';
    },
 
    isObject: function (thing) {
      return typeof thing === 'object' &&
          thing !== null && !Array.isArray(thing);
    },
 
    'isNumeric isDigit': function (thing) {
      return /^[0-9]+$/.test(thing);
    },
 
    isInteger: function (thing) {
      return Nodash.isNumber(thing) && !isNaN(thing) &&
        thing - Math.floor(thing) === 0 &&
        thing !== Infinity && thing !== -Infinity;
    },
 
    isArray: Array.isArray
  };
};