utils.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. export const int = (number) => {
  2. if (number === '' || number === null) {
  3. return 0;
  4. }
  5. return parseInt(number, 10);
  6. };
  7. export const innerWidth = (node) => {
  8. let width = node.clientWidth;
  9. const computedStyle = node.style;
  10. width -= int(computedStyle.paddingLeft);
  11. width -= int(computedStyle.paddingRight);
  12. return width;
  13. };
  14. export const outerWidth = (node) => {
  15. let width = node.clientWidth;
  16. const computedStyle = node.style;
  17. width += int(computedStyle.borderLeftWidth);
  18. width += int(computedStyle.borderRightWidth);
  19. return width;
  20. };
  21. export const innerHeight = (node) => {
  22. let height = node.clientHeight;
  23. const computedStyle = node.style;
  24. height -= int(computedStyle.paddingTop);
  25. height -= int(computedStyle.paddingBottom);
  26. return height;
  27. };
  28. export const outerHeight = (node) => {
  29. let height = node.clientHeight;
  30. const computedStyle = node.style;
  31. height += int(computedStyle.borderTopWidth);
  32. height += int(computedStyle.borderBottomWidth);
  33. return height;
  34. };
  35. export const parseBounds = (bounds) => {
  36. return {
  37. left: bounds.left,
  38. top: bounds.top,
  39. right: bounds.right,
  40. bottom: bounds.bottom
  41. };
  42. };
  43. export const isNumber = (things) => {
  44. return typeof things === 'number' ? true : false;
  45. };
  46. export const getDataSet = (children) => {
  47. return children.map((child) => {
  48. return Object.assign({}, child.props['data-set'], { isUserMove: true, key: child.key });
  49. });
  50. };
  51. export const stringJoin = (source, join) => {
  52. return source + (join ? ` ${join}` : '');
  53. };