Utility.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // Generated by CoffeeScript 1.12.7
  2. (function() {
  3. var assign, getValue, isArray, isEmpty, isFunction, isObject, isPlainObject,
  4. slice = [].slice,
  5. hasProp = {}.hasOwnProperty;
  6. assign = function() {
  7. var i, key, len, source, sources, target;
  8. target = arguments[0], sources = 2 <= arguments.length ? slice.call(arguments, 1) : [];
  9. if (isFunction(Object.assign)) {
  10. Object.assign.apply(null, arguments);
  11. } else {
  12. for (i = 0, len = sources.length; i < len; i++) {
  13. source = sources[i];
  14. if (source != null) {
  15. for (key in source) {
  16. if (!hasProp.call(source, key)) continue;
  17. target[key] = source[key];
  18. }
  19. }
  20. }
  21. }
  22. return target;
  23. };
  24. isFunction = function(val) {
  25. return !!val && Object.prototype.toString.call(val) === '[object Function]';
  26. };
  27. isObject = function(val) {
  28. var ref;
  29. return !!val && ((ref = typeof val) === 'function' || ref === 'object');
  30. };
  31. isArray = function(val) {
  32. if (isFunction(Array.isArray)) {
  33. return Array.isArray(val);
  34. } else {
  35. return Object.prototype.toString.call(val) === '[object Array]';
  36. }
  37. };
  38. isEmpty = function(val) {
  39. var key;
  40. if (isArray(val)) {
  41. return !val.length;
  42. } else {
  43. for (key in val) {
  44. if (!hasProp.call(val, key)) continue;
  45. return false;
  46. }
  47. return true;
  48. }
  49. };
  50. isPlainObject = function(val) {
  51. var ctor, proto;
  52. return isObject(val) && (proto = Object.getPrototypeOf(val)) && (ctor = proto.constructor) && (typeof ctor === 'function') && (ctor instanceof ctor) && (Function.prototype.toString.call(ctor) === Function.prototype.toString.call(Object));
  53. };
  54. getValue = function(obj) {
  55. if (isFunction(obj.valueOf)) {
  56. return obj.valueOf();
  57. } else {
  58. return obj;
  59. }
  60. };
  61. module.exports.assign = assign;
  62. module.exports.isFunction = isFunction;
  63. module.exports.isObject = isObject;
  64. module.exports.isArray = isArray;
  65. module.exports.isEmpty = isEmpty;
  66. module.exports.isPlainObject = isPlainObject;
  67. module.exports.getValue = getValue;
  68. }).call(this);