common.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /**
  2. * @fileOverview Utility for F2
  3. * @author dxq613 @gmail.com
  4. * @author sima.zhang1990@gmail.com
  5. */
  6. import { upperFirst, lowerFirst, isString, isNumber, isBoolean, isFunction, isDate, isArray, isNil, isObject, isPlainObject, isEqual, deepMix, mix, each, uniq, find, substitute } from '@antv/util';
  7. import * as ArrayUtil from './array';
  8. function isObjectValueEqual(a, b) {
  9. // for vue.js
  10. a = Object.assign({}, a);
  11. b = Object.assign({}, b);
  12. var aProps = Object.getOwnPropertyNames(a);
  13. var bProps = Object.getOwnPropertyNames(b);
  14. if (aProps.length !== bProps.length) {
  15. return false;
  16. }
  17. for (var i = 0, len = aProps.length; i < len; i++) {
  18. var propName = aProps[i];
  19. if (a[propName] !== b[propName]) {
  20. return false;
  21. }
  22. }
  23. return true;
  24. }
  25. function parsePadding(padding) {
  26. var top;
  27. var right;
  28. var bottom;
  29. var left;
  30. if (isNumber(padding) || isString(padding)) {
  31. top = bottom = left = right = padding;
  32. } else if (isArray(padding)) {
  33. top = padding[0];
  34. right = !isNil(padding[1]) ? padding[1] : padding[0];
  35. bottom = !isNil(padding[2]) ? padding[2] : padding[0];
  36. left = !isNil(padding[3]) ? padding[3] : right;
  37. }
  38. return [top, right, bottom, left];
  39. }
  40. function directionEnabled(mode, dir) {
  41. if (mode === undefined) {
  42. return true;
  43. } else if (typeof mode === 'string') {
  44. return mode.indexOf(dir) !== -1;
  45. }
  46. return false;
  47. }
  48. function toTimeStamp(value) {
  49. if (isString(value)) {
  50. if (value.indexOf('T') > 0) {
  51. value = new Date(value).getTime();
  52. } else {
  53. // new Date('2010/01/10') 和 new Date('2010-01-10') 的差别在于:
  54. // 如果仅有年月日时,前者是带有时区的: Fri Jan 10 2020 02:40:13 GMT+0800 (中国标准时间)
  55. // 后者会格式化成 Sun Jan 10 2010 08:00:00 GMT+0800 (中国标准时间)
  56. value = new Date(value.replace(/-/gi, '/')).getTime();
  57. }
  58. }
  59. if (isDate(value)) {
  60. value = value.getTime();
  61. }
  62. return value;
  63. }
  64. export { ArrayUtil as Array };
  65. export * from './dom';
  66. export { upperFirst, lowerFirst, isString, isNumber, isBoolean, isFunction, isDate, isArray, isNil, isObject, isPlainObject, isEqual, deepMix, mix, each, uniq, find, isObjectValueEqual, parsePadding, directionEnabled, toTimeStamp, substitute };