node.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. 'use strict';
  2. exports.__esModule = true;
  3. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
  4. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  5. var cloneNode = function cloneNode(obj, parent) {
  6. if ((typeof obj === 'undefined' ? 'undefined' : _typeof(obj)) !== 'object') {
  7. return obj;
  8. }
  9. var cloned = new obj.constructor();
  10. for (var i in obj) {
  11. if (!obj.hasOwnProperty(i)) {
  12. continue;
  13. }
  14. var value = obj[i];
  15. var type = typeof value === 'undefined' ? 'undefined' : _typeof(value);
  16. if (i === 'parent' && type === 'object') {
  17. if (parent) {
  18. cloned[i] = parent;
  19. }
  20. } else if (value instanceof Array) {
  21. cloned[i] = value.map(function (j) {
  22. return cloneNode(j, cloned);
  23. });
  24. } else {
  25. cloned[i] = cloneNode(value, cloned);
  26. }
  27. }
  28. return cloned;
  29. };
  30. var _class = function () {
  31. function _class() {
  32. var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  33. _classCallCheck(this, _class);
  34. for (var key in opts) {
  35. this[key] = opts[key];
  36. }
  37. var _opts$spaces = opts.spaces;
  38. _opts$spaces = _opts$spaces === undefined ? {} : _opts$spaces;
  39. var _opts$spaces$before = _opts$spaces.before,
  40. before = _opts$spaces$before === undefined ? '' : _opts$spaces$before,
  41. _opts$spaces$after = _opts$spaces.after,
  42. after = _opts$spaces$after === undefined ? '' : _opts$spaces$after;
  43. this.spaces = { before: before, after: after };
  44. }
  45. _class.prototype.remove = function remove() {
  46. if (this.parent) {
  47. this.parent.removeChild(this);
  48. }
  49. this.parent = undefined;
  50. return this;
  51. };
  52. _class.prototype.replaceWith = function replaceWith() {
  53. if (this.parent) {
  54. for (var index in arguments) {
  55. this.parent.insertBefore(this, arguments[index]);
  56. }
  57. this.remove();
  58. }
  59. return this;
  60. };
  61. _class.prototype.next = function next() {
  62. return this.parent.at(this.parent.index(this) + 1);
  63. };
  64. _class.prototype.prev = function prev() {
  65. return this.parent.at(this.parent.index(this) - 1);
  66. };
  67. _class.prototype.clone = function clone() {
  68. var overrides = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  69. var cloned = cloneNode(this);
  70. for (var name in overrides) {
  71. cloned[name] = overrides[name];
  72. }
  73. return cloned;
  74. };
  75. _class.prototype.toString = function toString() {
  76. return [this.spaces.before, String(this.value), this.spaces.after].join('');
  77. };
  78. return _class;
  79. }();
  80. exports.default = _class;
  81. module.exports = exports['default'];