Utility.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. // Generated by CoffeeScript 2.4.1
  2. (function() {
  3. // Copies all enumerable own properties from `sources` to `target`
  4. var assign, getValue, isArray, isEmpty, isFunction, isObject, isPlainObject,
  5. hasProp = {}.hasOwnProperty;
  6. assign = function(target, ...sources) {
  7. var i, key, len, source;
  8. if (isFunction(Object.assign)) {
  9. Object.assign.apply(null, arguments);
  10. } else {
  11. for (i = 0, len = sources.length; i < len; i++) {
  12. source = sources[i];
  13. if (source != null) {
  14. for (key in source) {
  15. if (!hasProp.call(source, key)) continue;
  16. target[key] = source[key];
  17. }
  18. }
  19. }
  20. }
  21. return target;
  22. };
  23. // Determines if `val` is a Function object
  24. isFunction = function(val) {
  25. return !!val && Object.prototype.toString.call(val) === '[object Function]';
  26. };
  27. // Determines if `val` is an Object
  28. isObject = function(val) {
  29. var ref;
  30. return !!val && ((ref = typeof val) === 'function' || ref === 'object');
  31. };
  32. // Determines if `val` is an Array
  33. isArray = function(val) {
  34. if (isFunction(Array.isArray)) {
  35. return Array.isArray(val);
  36. } else {
  37. return Object.prototype.toString.call(val) === '[object Array]';
  38. }
  39. };
  40. // Determines if `val` is an empty Array or an Object with no own properties
  41. isEmpty = function(val) {
  42. var key;
  43. if (isArray(val)) {
  44. return !val.length;
  45. } else {
  46. for (key in val) {
  47. if (!hasProp.call(val, key)) continue;
  48. return false;
  49. }
  50. return true;
  51. }
  52. };
  53. // Determines if `val` is a plain Object
  54. isPlainObject = function(val) {
  55. var ctor, proto;
  56. 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));
  57. };
  58. // Gets the primitive value of an object
  59. getValue = function(obj) {
  60. if (isFunction(obj.valueOf)) {
  61. return obj.valueOf();
  62. } else {
  63. return obj;
  64. }
  65. };
  66. module.exports.assign = assign;
  67. module.exports.isFunction = isFunction;
  68. module.exports.isObject = isObject;
  69. module.exports.isArray = isArray;
  70. module.exports.isEmpty = isEmpty;
  71. module.exports.isPlainObject = isPlainObject;
  72. module.exports.getValue = getValue;
  73. }).call(this);