SwVitaliy

Untitled

May 15th, 2012
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. is = {
  3.   fun:function(obj){ return typeof obj === "function" },
  4.   obj:function(obj){ return typeof obj === "object" },
  5.   arr:function(obj){ return obj.constructor.toString().slice(9,12) === "Arr" }
  6. };
  7. types = {};
  8.  
  9. function capitaliseFirstLetter(string)
  10. {
  11.     return string.charAt(0).toUpperCase() + string.slice(1);
  12. }
  13.  
  14. function clos(k)
  15. {
  16.     var _is = is;
  17.     return function(value)
  18.     {
  19.         if ( !_is[k](value) )
  20.         {
  21.             throw "value \"{value}\" has not type \"{type}\" ".replace('{value}', value.toString()).replace('{type}', k);
  22.         }
  23.         return true;
  24.     };
  25. }
  26.  
  27. var i;
  28. for (i in is)
  29. {
  30. if ( !is.hasOwnProperty(i) )continue;
  31. types[ "is"    + capitaliseFirstLetter(i) ] = is[i];
  32. types[ "check" + capitaliseFirstLetter(i) ] = clos(i);
  33. }
Advertisement
Add Comment
Please, Sign In to add comment